Combines this object's current estimate of a finder pattern position and module size
with a new estimate. It returns a new {@code FinderPattern} containing a weighted average
based on count.
344218
FinderPattern combineEstimate(float i, float j, float newModuleSize) {
    int combinedCount = count + 1;
    float combinedX = (count * getX() + j) / combinedCount;
    float combinedY = (count * getY() + i) / combinedCount;
    float combinedModuleSize = (count * estimatedModuleSize + newModuleSize) / combinedCount;
    return new FinderPattern(combinedX, combinedY, combinedModuleSize, combinedCount);
  }
1171161
private void replacePattern(
      NodeTraversal t, Node pattern, Node rhs, Node parent, Node nodeToDetach) {
    checkArgument(NodeUtil.isStatement(nodeToDetach), nodeToDetach);
    switch (pattern.getToken()) {
      case ARRAY_PATTERN:
        replaceArrayPattern(t, pattern, rhs, parent, nodeToDetach);
        break;
      case OBJECT_PATTERN:
        replaceObjectPattern(t, pattern, rhs, parent, nodeToDetach);
        break;
      default:
        throw new IllegalStateException("unexpected");
    }
  }
150665
private void addPattern(MethodSpec.Builder method, String pattern) {
    // Parse the pattern and populate the method body with instructions to format the date.
    for (Node node : DATETIME_PARSER.parse(pattern)) {
      if (node instanceof Text) {
        method.addStatement("b.append($S)", ((Text)node).text());
      } else if (node instanceof Field) {
        Field field = (Field)node;
        method.addStatement("formatField(d, '$L', $L, b)", field.ch(), field.width());
      }
    }
  }
871066
public void accumulate(Object workingMemoryContext,
                           Object context,
                           Tuple leftTuple,
                           InternalFactHandle handle,
                           Declaration[] declarations,
                           Declaration[] innerDeclarations,
                           WorkingMemory workingMemory) throws Exception {
        final Object value = this.expression.evaluate( handle,
                                                       leftTuple,
                                                       declarations,
                                                       innerDeclarations,
                                                       workingMemory,
                                                       workingMemoryContext ).getValue();
        if ( this.function.supportsReverse() ) {
            ((JavaAccumulatorFunctionContext) context).reverseSupport.put( handle.getId(),
                                                                           value );
        }
        this.function.accumulate( ((JavaAccumulatorFunctionContext) context).context,
                                  value );
    }
26332
private float calculateModuleSizeOneWay(ResultPoint pattern, ResultPoint otherPattern) {
    float moduleSizeEst1 = sizeOfBlackWhiteBlackRunBothWays((int) pattern.getX(),
        (int) pattern.getY(),
        (int) otherPattern.getX(),
        (int) otherPattern.getY());
    float moduleSizeEst2 = sizeOfBlackWhiteBlackRunBothWays((int) otherPattern.getX(),
        (int) otherPattern.getY(),
        (int) pattern.getX(),
        (int) pattern.getY());
    if (Float.isNaN(moduleSizeEst1)) {
      return moduleSizeEst2 / 7.0f;
    }
    if (Float.isNaN(moduleSizeEst2)) {
      return moduleSizeEst1 / 7.0f;
    }
    // Average them, and divide by 7 since we've counted the width of 3 black modules,
    // and 1 white and 1 black module on either side. Ergo, divide sum by 14.
    return (moduleSizeEst1 + moduleSizeEst2) / 14.0f;
  }
148182
function(pattern) {
        const mapBounds = this._map.getBounds().pad(0.1);
        return this._paths.map(path => {
            const directionPoints = this._getDirectionPoints(path, pattern)
                // filter out invisible points
                .filter(point => mapBounds.contains(point.latLng));
            return L.featureGroup(this._buildSymbols(path, pattern.symbolFactory, directionPoints));
        });
    }
470062
Node tryOptimizeArrayPattern(Node pattern) {
    checkArgument(pattern.isArrayPattern(), pattern);

    for (Node lastChild = pattern.getLastChild(); lastChild != null; ) {
      if (lastChild.isEmpty() || isRemovableDestructuringTarget(lastChild)) {
        Node prev = lastChild.getPrevious();
        pattern.removeChild(lastChild);
        lastChild = prev;
        reportChangeToEnclosingScope(pattern);
      } else {
        // don't remove any non-trailing empty nodes because that will change the ordering of the
        // other assignments
        // note that this case also covers array pattern rest, which must be the final element
        break;
      }
    }
    return pattern;
  }
547498
@Nonnull
	public DataBuilder appendOperatingSystemPattern(@Nonnull final OperatingSystemPattern pattern) {
		Check.notNull(pattern, "pattern");

		if (!operatingSystemPatterns.containsKey(pattern.getId())) {
			operatingSystemPatterns.put(pattern.getId(), new TreeSet<OperatingSystemPattern>(OS_PATTERN_COMPARATOR));
		}

		operatingSystemPatterns.get(pattern.getId()).add(pattern);
		return this;
	}
493948
private void fromAccumulate(PatternDescrBuilder<?> pattern) throws RecognitionException {
        AccumulateDescrBuilder<?> accumulate = helper.start(pattern,
                AccumulateDescrBuilder.class,
                null);
        try {
            if (helper.validateIdentifierKey(DroolsSoftKeywords.ACCUMULATE)) {
                match(input,
                        DRL6Lexer.ID,
                        DroolsSoftKeywords.ACCUMULATE,
                        null,
                        DroolsEditorType.KEYWORD);
            } else {
                // might be using the short mnemonic
                match(input,
                        DRL6Lexer.ID,
                        DroolsSoftKeywords.ACC,
                        null,
                        DroolsEditorType.KEYWORD);
            }
            if (state.failed)
                return;

            if (state.backtracking == 0 && input.LA(1) != DRL6Lexer.EOF) {
                helper.emit(Location.LOCATION_LHS_FROM_ACCUMULATE);
            }
            match(input,
                    DRL6Lexer.LEFT_PAREN,
                    null,
                    null,
                    DroolsEditorType.SYMBOL);
            if (state.failed)
                return;

            CEDescrBuilder<?, AndDescr> source = accumulate.source();
            try {
                helper.start(source,
                        CEDescrBuilder.class,
                        null);
                lhsAnd(source,
                        false);
                if (state.failed)
                    return;

                if (source.getDescr() != null && source.getDescr() instanceof ConditionalElementDescr) {
                    ConditionalElementDescr root = (ConditionalElementDescr) source.getDescr();
                    BaseDescr[] descrs = root.getDescrs().toArray(new BaseDescr[root.getDescrs().size()]);
                    root.getDescrs().clear();
                    for (int i = 0; i < descrs.length; i++) {
                        root.addOrMerge(descrs[i]);
                    }
                }
            } finally {
                helper.end(CEDescrBuilder.class,
                        source);
            }

            if (input.LA(1) == DRL6Lexer.COMMA) {
                match(input,
                        DRL6Lexer.COMMA,
                        null,
                        null,
                        DroolsEditorType.SYMBOL);
                if (state.failed)
                    return;
            } else if (input.LA(-1) != DRL6Lexer.SEMICOLON) {
                match(input,
                      DRL6Lexer.SEMICOLON,
                      null,
                      null,
                      DroolsEditorType.SYMBOL);
                if (state.failed)
                    return;
            }

            if (helper.validateIdentifierKey(DroolsSoftKeywords.INIT)) {
                // custom code, inline accumulate

                // initBlock
                match(input,
                        DRL6Lexer.ID,
                        DroolsSoftKeywords.INIT,
                        null,
                        DroolsEditorType.KEYWORD);
                if (state.failed)
                    return;
                if (state.backtracking == 0 && input.LA(1) != DRL6Lexer.EOF) {
                    helper.emit(Location.LOCATION_LHS_FROM_ACCUMULATE_INIT);
                }

                String init = chunk(DRL6Lexer.LEFT_PAREN,
                        DRL6Lexer.RIGHT_PAREN,
                        Location.LOCATION_LHS_FROM_ACCUMULATE_INIT_INSIDE);
                if (state.failed)
                    return;
                if (state.backtracking == 0)
                    accumulate.init(init);

                if (input.LA(1) == DRL6Lexer.COMMA) {
                    match(input,
                            DRL6Lexer.COMMA,
                            null,
                            null,
                            DroolsEditorType.SYMBOL);
                    if (state.failed)
                        return;
                }

                // actionBlock
                match(input,
                        DRL6Lexer.ID,
                        DroolsSoftKeywords.ACTION,
                        null,
                        DroolsEditorType.KEYWORD);
                if (state.failed)
                    return;
                if (state.backtracking == 0 && input.LA(1) != DRL6Lexer.EOF) {
                    helper.emit(Location.LOCATION_LHS_FROM_ACCUMULATE_ACTION);
                }

                String action = chunk(DRL6Lexer.LEFT_PAREN,
                        DRL6Lexer.RIGHT_PAREN,
                        Location.LOCATION_LHS_FROM_ACCUMULATE_ACTION_INSIDE);
                if (state.failed)
                    return;
                if (state.backtracking == 0)
                    accumulate.action(action);

                if (input.LA(1) == DRL6Lexer.COMMA) {
                    match(input,
                            DRL6Lexer.COMMA,
                            null,
                            null,
                            DroolsEditorType.SYMBOL);
                    if (state.failed)
                        return;
                }

                // reverseBlock
                if (helper.validateIdentifierKey(DroolsSoftKeywords.REVERSE)) {
                    match(input,
                            DRL6Lexer.ID,
                            DroolsSoftKeywords.REVERSE,
                            null,
                            DroolsEditorType.KEYWORD);
                    if (state.failed)
                        return;
                    if (state.backtracking == 0 && input.LA(1) != DRL6Lexer.EOF) {
                        helper.emit(Location.LOCATION_LHS_FROM_ACCUMULATE_REVERSE);
                    }

                    String reverse = chunk(DRL6Lexer.LEFT_PAREN,
                            DRL6Lexer.RIGHT_PAREN,
                            Location.LOCATION_LHS_FROM_ACCUMULATE_REVERSE_INSIDE);
                    if (state.failed)
                        return;
                    if (state.backtracking == 0)
                        accumulate.reverse(reverse);

                    if (input.LA(1) == DRL6Lexer.COMMA) {
                        match(input,
                                DRL6Lexer.COMMA,
                                null,
                                null,
                                DroolsEditorType.SYMBOL);
                        if (state.failed)
                            return;
                    }
                }

                // resultBlock
                match(input,
                        DRL6Lexer.ID,
                        DroolsSoftKeywords.RESULT,
                        null,
                        DroolsEditorType.KEYWORD);
                if (state.failed)
                    return;

                if (state.backtracking == 0 && input.LA(1) != DRL6Lexer.EOF) {
                    helper.emit(Location.LOCATION_LHS_FROM_ACCUMULATE_RESULT);
                }

                String result = chunk(DRL6Lexer.LEFT_PAREN,
                        DRL6Lexer.RIGHT_PAREN,
                        Location.LOCATION_LHS_FROM_ACCUMULATE_RESULT_INSIDE);
                if (state.failed)
                    return;
                if (state.backtracking == 0)
                    accumulate.result(result);
            } else {
                // accumulate functions
                accumulateFunction(accumulate,
                                   false,
                                   null);
                if (state.failed)
                    return;
            }

            match(input,
                    DRL6Lexer.RIGHT_PAREN,
                    null,
                    null,
                    DroolsEditorType.SYMBOL);
            if (state.failed)
                return;
        } finally {
            helper.end(AccumulateDescrBuilder.class,
                    accumulate);
            if (state.backtracking == 0 && input.LA(1) != DRL6Lexer.EOF) {
                helper.emit(Location.LOCATION_LHS_BEGIN_OF_CONDITION);
            }
        }
    }
962842
public static Pattern repeat(Pattern pattern, int min, int max)
   {
      if (pattern == null)
      {
         throw new IllegalArgumentException("Pattern can not be null");
      }
      return new RepeatPattern(pattern, min, max);
   }
444655
protected PExp patternToExp(PPattern pattern) throws AnalysisException
	{
		PatternToExpVisitor visitor = new PatternToExpVisitor(getUniqueGenerator(), af);
		return pattern.apply(visitor);
	}
995011
public String getPatternForNumItems(int count) {
        if (count <= 0) {
            throw new IllegalArgumentException("count must be > 0");
        }
        ArrayList<String> list = new ArrayList<String>();
        for (int i = 0; i < count; i++) {
            list.add(String.format("{%d}", i));
        }
        return format(list);
    }
1281423
public void setPattern(String patternType) {

        final PatternType type = PatternType.valueOf(patternType);
        if (type != m_model.getPatternType()) {
            removeExceptionsOnChange(new Command() {

                public void execute() {

                    EndType oldEndType = m_model.getEndType();
                    m_model.setPatternType(type);
                    m_model.setIndividualDates(null);
                    m_model.setInterval(getPatternDefaultValues().getInterval());
                    m_model.setEveryWorkingDay(Boolean.FALSE);
                    m_model.clearWeekDays();
                    m_model.clearIndividualDates();
                    m_model.clearWeeksOfMonth();
                    m_model.clearExceptions();
                    if (type.equals(PatternType.NONE) || type.equals(PatternType.INDIVIDUAL)) {
                        m_model.setEndType(EndType.SINGLE);
                    } else if (oldEndType.equals(EndType.SINGLE)) {
                        m_model.setEndType(EndType.TIMES);
                        m_model.setOccurrences(10);
                        m_model.setSeriesEndDate(null);
                    }
                    m_model.setDayOfMonth(getPatternDefaultValues().getDayOfMonth());
                    m_model.setMonth(getPatternDefaultValues().getMonth());
                    if (type.equals(PatternType.WEEKLY)) {
                        m_model.setWeekDay(getPatternDefaultValues().getWeekDay());
                    }
                    valueChanged();
                }
            });
        }

    }
1066372
protected static NumberPattern parse(String pattern) {
    return NUMBER_PATTERN_CACHE.computeIfAbsent(pattern, s -> new NumberPatternParser().parse(s));
  }
883350
@Nonnull
	public DataBuilder appendBrowserPattern(@Nonnull final BrowserPattern pattern) {
		Check.notNull(pattern, "pattern");
		if (!browserPatterns.containsKey(pattern.getId())) {
			browserPatterns.put(pattern.getId(), new TreeSet<BrowserPattern>(BROWSER_PATTERN_COMPARATOR));
		}

		browserPatterns.get(pattern.getId()).add(pattern);
		return this;
	}
501849
public TupleCombinerBuilder include( String... varNamePatterns)
    {
    for( String varNamePattern : varNamePatterns)
      {
      tupleCombiner_.addIncludedVar( varNamePattern);
      }
    return this;
    }
598421
@Override
    public final void applyPattern(String pattern)
    {

        if (hasRegistry())
        {
            super.applyPattern(pattern);
            toPattern = super.toPattern();
            return;
        }

        ArrayList<Format> foundFormats = new ArrayList<Format>();
        ArrayList<String> foundDescriptions = new ArrayList<String>();
        StringBuilder stripCustom = new StringBuilder(pattern.length());

        ParsePosition pos = new ParsePosition(0);
        char[] c = pattern.toCharArray();
        int fmtCount = 0;

        while (pos.getIndex() < pattern.length())
        {

            char charType = c[pos.getIndex()];

            if (QUOTE == charType)
            {

                appendQuotedString(pattern, pos, stripCustom, true);
                continue;

            }

            if (START_FE == charType)
            {

                fmtCount++;
                seekNonWs(pattern, pos);
                int start = pos.getIndex();
                int index = readArgumentIndex(pattern, next(pos));
                stripCustom.append(START_FE).append(index);
                seekNonWs(pattern, pos);
                Format format = null;
                String formatDescription = null;
                if (c[pos.getIndex()] == START_FMT)
                {
                    formatDescription = parseFormatDescription(pattern, next(pos));
                    format = getFormat(formatDescription);
                    if (format == null)
                    {
                        stripCustom.append(START_FMT).append(formatDescription);
                    }
                }
                foundFormats.add(format);
                foundDescriptions.add(format == null ? null : formatDescription);

                Preconditions.checkState(foundFormats.size() == fmtCount);
                Preconditions.checkState(foundDescriptions.size() == fmtCount);

                if (c[pos.getIndex()] != END_FE)
                {
                    throw new IllegalArgumentException("Unreadable format element at position " + start);
                }

            }

            //$FALL-THROUGH$
            stripCustom.append(c[pos.getIndex()]);
            next(pos);

        }

        super.applyPattern(stripCustom.toString());

        toPattern = insertFormats(super.toPattern(), foundDescriptions);

        if (containsElements(foundFormats))
        {
            Format[] origFormats = getFormats();
            // only loop over what we know we have, as MessageFormat on Java 1.3
            // seems to provide an extra format element:
            Iterator<Format> it = foundFormats.iterator();
            for (int i = 0; it.hasNext(); i++)
            {
                Format f = it.next();
                if (f != null)
                {
                    origFormats[i] = f;
                }
            }
            super.setFormats(origFormats);
        }

    }