コンスタによるインスタンスを生成する際の前提条件となる引数のチェックを行う。

@param pattern コンパイル済みの正規表現
@param replacement 置換する文字。
@throws NullPointerException if pattern or replacement is null.
172860
private static void checkPreconditions(final Pattern pattern, final String replacement) {
        if(pattern == null ) {
            throw new NullPointerException("regex should not be null");
        }
        
        if(replacement == null) {
            throw new NullPointerException("replacement should not be null");
        }
    }
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);
        }

    }
171584
public FulltextMatch addPattern(
                    final String pattern
                    )
    {
        if (pattern == null  ||  pattern.length() == 0) {
            throw new IllegalArgumentException( "no pattern specified" );
        }

        _patterns.add( pattern );

        return this;
    }
325567
protected function replace(array &$str, $pattern, $replacement)
    {
        foreach ($str as &$s) {
            $s = preg_replace($pattern, $replacement, $s);
        }
    }
46469
public static String format(Object o, String pattern) {
        if (null == o) return "";
        return format(null, o, pattern, null, null);
    }
891906
protected org.apache.log4j.helpers.PatternParser createPatternParser(final String pattern) {
		return new FoundationLoggingPatternParser(pattern);
	}
1200928
public static void main(String[] args) throws Exception {
    if (args.length < 2) {
      logger.info("using BatchReplaceMain dir patternfile encoding");
      return;
    }
    String dir = args[0];
    if (!new File(dir).exists()) {
      logger.error("{} not a valid file or directory", dir);
      return;
    }
    String properties = args[1];
    if (!new File(properties).exists()) {
      logger.info("{} not valid file or directory", properties);
    }
    Charset charset = null;
    if (args.length >= 3) {
      charset = Charset.forName(args[2]);
    }
    List<String> lines = Files.readLines(new File(properties));
    Map<String, List<Replacer>> profiles = CollectUtils.newHashMap();
    List<Replacer> replacers = null;
    for (String line : lines) {
      if (Strings.isEmpty(line)) {
        continue;
      }
      if (-1 == line.indexOf('=')) {
        replacers = CollectUtils.newArrayList();
        profiles.put(line, replacers);
      } else {
        line = Strings.replace(line, "\\=", "~~~~");
        String older = Strings.replace(Strings.substringBefore(line, "="), "~~~~", "=");
        String newer = Strings.replace(Strings.substringAfter(line, "="), "~~~~", "=");
        older = Strings.replace(older, "\\n", "\n");
        older = Strings.replace(older, "\\t", "\t");
        newer = Strings.replace(newer, "\\n", "\n");
        newer = Strings.replace(newer, "\\t", "\t");
        Replacer pair = new Replacer(older, newer);
        replacers.add(pair);
      }
    }
    replaceFile(dir, profiles, charset);
  }
1032530
public void print(String pattern, Object... arguments) {
    print(String.format(pattern, arguments));
  }
129640
public @NonNull SelectorComponent pattern(final @NonNull String pattern) {
    return new SelectorComponent(this.children, this.color, this.obfuscated, this.bold, this.strikethrough, this.underlined, this.italic, this.clickEvent, this.hoverEvent, this.insertion, requireNonNull(pattern, "pattern"));
  }
1147833
public <T> AsyncMutateInBuilder replace(String path, T fragment) {
        if (StringUtil.isNullOrEmpty(path)) {
            throw new IllegalArgumentException("Path must not be empty for replace");
        }
        this.mutationSpecs.add(new MutationSpec(Mutation.REPLACE, path, fragment));
        return this;
    }
995272
public static final String convertPattern(String pattern) {
        if (pattern == null) {
            return null;
        }
        else {
            String convertedPattern = pattern;
            for (PatternConverter converter : PATTERN_CONVERTERS) {
                convertedPattern = converter.convert(convertedPattern);
            }

            return convertedPattern;
        }
    }
1240799
private static boolean doesNameMatchPattern(final Principal principal, final Pattern pattern) {
        if (pattern != null) {
            val name = principal.getName();
            val result = pattern.matcher(name).matches();
            LOGGER.debug("[{}] matches [{}] == [{}]", pattern.pattern(), name, result);
            return result;
        }
        return true;
    }
1172877
public static SimonPattern create(String pattern) {
		if (pattern == null) {
			return null;
		}

		return createForType(pattern, Simon.class);
	}
514524
protected PExp patternToExp(PPattern pattern, IPogAssistantFactory af,
			UniqueNameGenerator unq)
	{
		PatternToExpVisitor visitor = new PatternToExpVisitor(unq, af);
		try
		{
			return pattern.apply(visitor);
		} catch (AnalysisException e)
		{
			return null;
		}
	}
1198391
@Nonnull
  public DescribeCommand match(@Nullable String pattern) {
    if (!"*".equals(pattern)) {
      matchOption = Optional.ofNullable(pattern);
      log.info("--match = {}", matchOption.orElse(""));
    }
    return this;
  }
601488
public void applyPattern(String pat)
    {
        this.pattern = pat;
        parsePattern();

        setLocale(null, null);
        // reset parsed pattern items
        patternItems = null;
    }
578047
public synchronized static String formatDate(final java.util.Date object, String pattern) {
		if (pattern == null || pattern.equals("")) {
			pattern = JKFormatUtil.DEFAULT_DATE_PATTERN;
		}
		return JKFormatUtil.getDateFormatter(pattern).format(object);
	}