Package jimm.util

Examples of jimm.util.Replacer


    assertEquals("a,xyzzy", StringUtils.join(list, ","));
    assertEquals("a-*-xyzzy", StringUtils.join(list, "-*-"));
}

public void testReplace() {
    Replacer r = new Replacer() {
  public Object replace(String s) { return "x"; }
  };

    assertNull(StringUtils.replaceDelimited("", "", null, null));
    assertNull(StringUtils.replaceDelimited(null, null, null, null));
View Full Code Here


     StringUtils.replaceDelimited("{", "}", r,
          "{jobs.hourly rate}.nil? ? nil : {jobs.hourly rate} / 100.0"));
}

public void testReplaceNotAfter() {
    Replacer r = new Replacer() {
  public Object replace(String s) { return "x"; }
  };

    assertNull(StringUtils.replaceDelimited("#", "", "", null, null));
    assertNull(StringUtils.replaceDelimited("#", "#", "#", null, null));
View Full Code Here

}

public void testAvoidInfiniteLoop() {
    final int[] count = new int[1];
    count[0] = 0;
    Replacer r = new Replacer() {
  public Object replace(String s) {
      if (++count[0] == 2)
    fail("caught in an infinite loop");
      return "{" + s + "}";
  }
View Full Code Here

    // Here, we are using replacers so we can start observing things.
    // Usually, they are used to replace strings.

    // Formulas
    StringUtils.replaceDelimited(exceptAfter, "{@", "}", new Replacer() {
  public Object replace(String str) {
      Formula f = report.findFormula(str);
      observedContents.add(f);
      f.addObserver(Expression.this);
      return "";    // Avoid early bail-out
  }},
         expr);

    // Parameters
    StringUtils.replaceDelimited(exceptAfter, "{?", "}", new Replacer() {
  public Object replace(String str) {
      Parameter p = report.findParameter(str);
      observedContents.add(p);
      p.addObserver(Expression.this);
      return "";    // Avoid early bail-out
  }},
         expr);

    // User columns
    StringUtils.replaceDelimited(exceptAfter, "{!", "}", new Replacer() {
  public Object replace(String str) {
      UserColumn uc = report.findUserColumn(str);
      observedContents.add(uc);
      uc.addObserver(Expression.this);
      return "";    // Avoid early bail-out
View Full Code Here

public Collection columnsUsed() {
    final ArrayList list = new ArrayList();

    // We are using a replacer passively, to look for curly-delimited
    // expressions. Nothing in the expression text gets modified.
    StringUtils.replaceDelimited(exceptAfter, "{", "}", new Replacer() {
  public Object replace(String str) {
      switch (str.charAt(0)) {
      case '!':    // User column
    UserColumn uc = report.findUserColumn(str.substring(1));
    if (uc != null// Should never be null
View Full Code Here

public Collection userColumnsUsed() {
    final ArrayList list = new ArrayList();

    // We are using a replacer passively, to look for curly-delimited
    // expressions. Nothing in the expression text gets modified.
    StringUtils.replaceDelimited(exceptAfter, "{!", "}", new Replacer() {
  public Object replace(String str) {
      UserColumn uc = report.findUserColumn(str);
      if (uc != null// Should never be null
    list.add(uc);
      return "";    // So we don't bail out
View Full Code Here

    String str = getExpression();
    if (str == null || str.trim().length() == 0)
  return null;

    // Special values
    str = StringUtils.replaceDelimited("#", "{%", "}", new Replacer() {
  public Object replace(String str) {
      Object obj = SpecialField.value(formulaField, str, report);
      return obj == null ? "nil" : obj;
  }},
         str);
    if (str == null) return null;

    // Formula values
    str = StringUtils.replaceDelimited("#", "{@", "}", new Replacer() {
  public Object replace(String str) {
      Formula f = report.findFormula(str);
      return f == null ? "nil" : f.eval(formulaField);
  }},
         str);
    if (str == null) return null;

    // Parameter values
    str = StringUtils.replaceDelimited("#", "{?", "}", new Replacer() {
  public Object replace(String str) {
      Parameter p = report.findParameter(str);
      return p == null ? "nil" : p.getValue();
  }},
         str);
    if (str == null) return null;

    // User column values
    str = StringUtils.replaceDelimited("#", "{!", "}", new Replacer() {
  public Object replace(String str) {
      UserColumn uc = report.findUserColumn(str);
      return uc == null ? "nil" : report.columnValue(uc);
  }},
         str);
    if (str == null) return null;

    // Column values
    str = StringUtils.replaceDelimited("#", "{", "}", new Replacer() {
  public Object replace(String str) {
      Column col = report.findColumn(str);
      if (col == null)
    return "{" + str + "}";
View Full Code Here

TOP

Related Classes of jimm.util.Replacer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.