Ejemplo n.º 1
0
  @Test
  public void testParse() throws Exception {

    // generate a sample JSON array
    StringBuilder sample = new StringBuilder();
    sample.append("[");
    int i = 0;
    final int N = 5000;
    for (; i < N; i++) {
      sample.append(i);
      sample.append(",");
    }
    sample.append(i);
    sample.append("]");

    String json = sample.toString();

    StopWatch timer = new StopWatch();

    for (int n = 0; n < 500; n++) {
      JSONPullParser parser = new JSONPullParser(json);

      JSONEvent e;
      while ((e = parser.next()) != JSONEvent.EndJSON) {}
    }
    _logger.info("time: " + timer.getElapsedTime());
  }
  @Test
  public void test_that_third_level_nodes_without_parents_are_generated_correct_json()
      throws JSONException {
    List<Statistics> nodeList = new ArrayList<Statistics>();
    nodeList.add(new ManagerStatistics("A:B:C", "ACCOUNT", "Y"));

    StringBuilder expected = new StringBuilder();
    expected.append("[");
    expected.append(
        "{\"id\":\"A\",\"name\":\"A\",\"children_ids\":[\"A:B\"],\"node_type\":\"chart\",\"chart_id\":\"A\",\"parent_id\":null}");
    expected.append(",");
    expected.append(
        "{\"id\":\"A:B\",\"name\":\"B\",\"children_ids\":[],\"node_type\":\"chart\",\"chart_id\":\"A:B\",\"parent_id\":\"A\"}");
    // expected.append(",");
    // expected.append("{\"guid\":3,\"isSelected\":false,\"name\":\"C\",\"treeItemIsExpanded\":false,\"guiPath\":\"A:B:C\",\"parentPath\":\"A:B\"}");
    expected.append("]");

    JSONArray jsonObject =
        BuildJsonObjectsUtil.buildTreeTypeMenuJsonObject(
            "treeMenuID",
            nodeList,
            new ArrayList<Alert>(),
            new ArrayList<GroupedStatistics>(),
            0,
            20,
            false,
            "chart");
    assertEquals(expected.toString(), jsonObject.toString());
  }
Ejemplo n.º 3
0
  @Test
  public void testLexerPerformance() throws Exception {

    // generate a sample JSON array
    StringBuilder sample = new StringBuilder();
    sample.append("[");
    int i = 0;
    final int N = 5000;
    for (; i < N; i++) {
      sample.append(i);
      sample.append(",");
    }
    sample.append(i);
    sample.append("]");

    String json = sample.toString();

    StopWatch timer = new StopWatch();

    for (int n = 0; n < 500; n++) {
      JSONLexer lexer = new JSONLexer(json);

      Token t;
      while ((t = lexer.nextToken()) != null) {}
    }
    _logger.info("time: " + timer.getElapsedTime());
  }
Ejemplo n.º 4
0
  /**
   * Checks if the specified function correctly handles its argument types, and returns the function
   * name.
   *
   * @param def function definition types are supported.
   */
  protected void check(final Function def) {
    final String desc = def.toString();
    final String name = desc.replaceAll("\\(.*", "");

    // test too few, too many, and wrong argument types
    for (int al = Math.max(def.min - 1, 0); al <= def.max + 1; al++) {
      final boolean in = al >= def.min && al <= def.max;
      final StringBuilder qu = new StringBuilder(name + "(");
      int any = 0;
      for (int a = 0; a < al; a++) {
        if (a != 0) qu.append(", ");
        if (in) {
          // test arguments
          if (def.args[a].type == AtomType.STR) {
            qu.append("1");
          } else { // any type (skip test)
            qu.append("'X'");
            if (SeqType.STR.instance(def.args[a])) any++;
          }
        } else {
          // test wrong number of arguments
          qu.append("'x'");
        }
      }
      // skip test if all types are arbitrary
      if ((def.min > 0 || al != 0) && (any == 0 || any != al)) {
        final String query = qu.append(")").toString();
        if (in) error(query, Err.XPTYPE, Err.NODBCTX, Err.NODB);
        else error(query, Err.XPARGS);
      }
    }
  }
Ejemplo n.º 5
0
  private String generateOperation() {
    StringBuilder operation = new StringBuilder();
    Random generator = new Random(new Date().getTime());

    int operationName = (generator.nextInt(20)) % 2;
    int firstParam = generator.nextInt(10);
    int secondParam = generator.nextInt(10);
    int result = 0;

    switch (operationName) {
      case 0:
        operation.append("add(");
        result = firstParam + secondParam;
        break;
      case 1:
        operation.append("sub(");
        result = firstParam - secondParam;
        break;
      default:;
    }

    operation.append(firstParam + "," + secondParam + ")=" + result);

    return operation.toString();
  }
 /**
  * A convenience method for performing KeyValue existence/nonexistence tests.
  *
  * @param expectedKeys The expected KeyValue keys.
  * @param actualKeys The actual KeyValue keys.
  * @throws Exception
  */
 private void assertRuleTemplateHasExpectedKeyValues(
     Set<String> expectedKeys, Set<String> actualKeys) throws Exception {
   // Check to see if all required keys are in the set.
   for (Iterator<String> iterator = expectedKeys.iterator(); iterator.hasNext(); ) {
     final String expKey = iterator.next();
     assertTrue(
         "The key label pair with a key of '" + expKey + "' should have been true.",
         actualKeys.contains(expKey));
     actualKeys.remove(expKey);
   }
   // If any keys are still in the list, then fail the test because we expected their equivalent
   // rule template options to
   // have a non-true value.
   if (!actualKeys.isEmpty()) {
     // Construct the error message.
     final String pluralStr = (actualKeys.size() != 1) ? "s" : "";
     final StringBuilder errMsg = new StringBuilder();
     errMsg
         .append("The key label pair")
         .append(pluralStr)
         .append(" with the key")
         .append(pluralStr)
         .append(" of ");
     for (Iterator<String> iterator = actualKeys.iterator(); iterator.hasNext(); ) {
       errMsg.append("'").append(iterator.next()).append(iterator.hasNext() ? "', " : "' ");
     }
     errMsg.append("should have been false.");
     // Fail the test.
     fail(errMsg.toString());
   }
 }
Ejemplo n.º 7
0
  /* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
  @Test
  public void testUnpredicatedPathsInAlt() throws Exception {
    mkdir(tmpdir);

    StringBuilder grammarBuilder = new StringBuilder(169);
    grammarBuilder.append("grammar T;\n");
    grammarBuilder.append("s : a {print(\"alt 1\")}\n");
    grammarBuilder.append("  | b {print(\"alt 2\")}\n");
    grammarBuilder.append("  ;\n");
    grammarBuilder.append("a : {False}? ID INT\n");
    grammarBuilder.append("  | ID INT\n");
    grammarBuilder.append("  ;\n");
    grammarBuilder.append("b : ID ID\n");
    grammarBuilder.append("  ;\n");
    grammarBuilder.append("ID : 'a'..'z'+ ;\n");
    grammarBuilder.append("INT : '0'..'9'+;\n");
    grammarBuilder.append("WS : (' '|'\\n') -> skip ;");
    String grammar = grammarBuilder.toString();

    String input = "x 4";
    String found =
        execParser(
            "T.g4", grammar, "TParser", "TLexer", "TListener", "TVisitor", "s", input, false);

    assertEquals("alt 1\n", found);
    assertNull(this.stderrDuringParse);
  }
Ejemplo n.º 8
0
  private KieBase createKnowledgeBase() {
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(
        ResourceFactory.newClassPathResource(
            "memory/BPMN2-RuleTaskWithInsertProcessInstance.bpmn2"),
        ResourceType.BPMN2);
    kbuilder.add(
        ResourceFactory.newClassPathResource("memory/ProcessInstanceRule.drl"), ResourceType.DRL);

    if (!kbuilder.getErrors().isEmpty()) {
      Iterator<KnowledgeBuilderError> errIter = kbuilder.getErrors().iterator();
      while (errIter.hasNext()) {
        KnowledgeBuilderError err = errIter.next();
        StringBuilder lines = new StringBuilder("");
        if (err.getLines().length > 0) {
          lines.append(err.getLines()[0]);
          for (int i = 1; i < err.getLines().length; ++i) {
            lines.append(", " + err.getLines()[i]);
          }
        }
        logger.warn(err.getMessage() + " (" + lines.toString() + ")");
      }
      throw new IllegalArgumentException("Errors while parsing knowledge base");
    }
    KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());

    return kbase;
  }
  @Test
  public void testUpdateLookupParameter() throws Exception {
    protocolFundingSourceService = new ProtocolFundingSourceServiceImpl();
    Entry<String, String> entry =
        protocolFundingSourceService.getLookupParameters(FundingSourceType.SPONSOR);
    Assert.assertNotNull(entry);
    String fieldConversions = entry.getValue();
    StringBuilder builder = new StringBuilder();
    builder.append("sponsorCode:" + PROTOCOL_FUNDING_SOURCE_NUMBER + Constants.COMMA);
    builder.append("sponsorName:" + PROTOCOL_FUNDING_SOURCE_NAME);

    Assert.assertThat(entry.getValue(), JUnitMatchers.containsString(builder.toString()));
    String parameter =
        KRADConstants.METHOD_TO_CALL_BOPARM_LEFT_DEL
            + KRADConstants.METHOD_TO_CALL_BOPARM_RIGHT_DEL
            + KRADConstants.METHOD_TO_CALL_PARM1_LEFT_DEL
            + KRADConstants.METHOD_TO_CALL_PARM1_RIGHT_DEL;
    String updatedParam =
        protocolFundingSourceService.updateLookupParameter(
            parameter, Sponsor.class.getName(), fieldConversions);
    Assert.assertThat(
        updatedParam,
        JUnitMatchers.containsString(
            "(!!" + Sponsor.class.getName() + "!!)(((" + builder.toString() + ")))"));
  }
Ejemplo n.º 10
0
  /* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
  @Test
  public void testDisabledAlternative() throws Exception {
    mkdir(tmpdir);

    StringBuilder grammarBuilder = new StringBuilder(121);
    grammarBuilder.append("grammar T;\n");
    grammarBuilder.append("cppCompilationUnit : content+ EOF;\n");
    grammarBuilder.append("content: anything | {False}? .;\n");
    grammarBuilder.append("anything: ANY_CHAR;\n");
    grammarBuilder.append("ANY_CHAR: [_a-zA-Z0-9];");
    String grammar = grammarBuilder.toString();

    String input = "hello";
    String found =
        execParser(
            "T.g4",
            grammar,
            "TParser",
            "TLexer",
            "TListener",
            "TVisitor",
            "cppCompilationUnit",
            input,
            false);

    assertEquals("", found);
    assertNull(this.stderrDuringParse);
  }
  @Before
  public void beforeRunRest() {
    jdbcTemplate = new JdbcTemplate(this.dataSource);

    String sql_drop_table = "DROP TABLE IF EXISTS USER_PROFILE;";
    jdbcTemplate.execute(sql_drop_table);

    StringBuilder sql_create_table = new StringBuilder();
    sql_create_table.append(" CREATE TABLE USER_PROFILE( ");
    sql_create_table.append(" USER_PROFILE_ID  VARCHAR(10) NOT NULL PRIMARY KEY, ");
    sql_create_table.append(" NAME VARCHAR(100), ");
    sql_create_table.append(" EMAIL VARCHAR(100) ");
    sql_create_table.append(" ); ");
    jdbcTemplate.execute(sql_create_table.toString());

    String sql_insert_nut_user =
        "******";
    jdbcTemplate.update(sql_insert_nut_user, new Object[] {"01", "nut", "*****@*****.**"});

    String sql_insert_oo_user =
        "******";
    jdbcTemplate.update(sql_insert_oo_user, new Object[] {"02", "oo", "*****@*****.**"});

    userProfileDao.setDataSource(dataSource);
  }
Ejemplo n.º 12
0
 @Override
 public String toString() {
   final StringBuilder sb = new StringBuilder("TestMessage{");
   sb.append("publisher=").append(publisher);
   sb.append(", data='").append(data).append('\'');
   sb.append('}');
   return sb.toString();
 }
 private String protoToString(List<Protos.Key> keys) {
   StringBuilder sb = new StringBuilder();
   for (Protos.Key key : keys) {
     sb.append(key.toString());
     sb.append("\n");
   }
   return sb.toString().trim();
 }
  /** Generates a string like this one: [1, 2, 3, 4, 5] */
  private <T> String generateListString(List<T> list) {
    StringBuilder stringBuilder = new StringBuilder("[");
    for (int i = 0; i < list.size() - 2; i++) {
      stringBuilder.append(list.get(i)).append(", ");
    }
    stringBuilder.append(list.get(list.size() - 1)).append("]");

    return stringBuilder.toString();
  }
Ejemplo n.º 15
0
 private String testCase() {
   StringBuilder sb = new StringBuilder();
   sb.append("# comment\n");
   sb.append("class=service2,index=contract1,index=annotation1\n");
   sb.append("class=service1,index=contract1:name1,index=annotation1\n");
   sb.append("class=service4,a=1\n");
   sb.append(
       "class=service3,index=contract2:name2,index=contract1:name2,index=annotation2,index=annotation1,b=2,a=1\n");
   return sb.toString();
 }
Ejemplo n.º 16
0
  /* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
  @Test
  public void testPredFromAltTestedInLoopBack_2() throws Exception {
    mkdir(tmpdir);

    StringBuilder grammarBuilder = new StringBuilder(203);
    grammarBuilder.append("grammar T;\n");
    grammarBuilder.append("file_\n");
    grammarBuilder.append("@after {print($ctx.toStringTree(recog=self))}\n");
    grammarBuilder.append("  : para para EOF ;\n");
    grammarBuilder.append("para: paraContent NL NL ;\n");
    grammarBuilder.append("paraContent : ('s'|'x'|{self._input.LA(2)!=TParser.NL}? NL)+ ;\n");
    grammarBuilder.append("NL : '\\n' ;\n");
    grammarBuilder.append("s : 's' ;\n");
    grammarBuilder.append("X : 'x' ;");
    String grammar = grammarBuilder.toString();

    String input = "s\n" + "\n" + "\n" + "x\n" + "\n";
    String found =
        execParser(
            "T.g4", grammar, "TParser", "TLexer", "TListener", "TVisitor", "file_", input, true);

    assertEquals(
        "(file_ (para (paraContent s) \\n \\n) (para (paraContent \\n x) \\n \\n) <EOF>)\n", found);
    assertNull(this.stderrDuringParse);
  }
Ejemplo n.º 17
0
  /* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
  @Test
  public void testDependentPredNotInOuterCtxShouldBeIgnored() throws Exception {
    mkdir(tmpdir);

    StringBuilder grammarBuilder = new StringBuilder(256);
    grammarBuilder.append("grammar T;\n");
    grammarBuilder.append(
        "s : b[2] ';' |  b[2] '.' ; // decision in s drills down to ctx-dependent pred in a;\n");
    grammarBuilder.append("b[int i] : a[i] ;\n");
    grammarBuilder.append("a[int i]\n");
    grammarBuilder.append("  : {$i==1}? ID {print(\"alt 1\")}\n");
    grammarBuilder.append("    | {$i==2}? ID {print(\"alt 2\")}\n");
    grammarBuilder.append("    ;\n");
    grammarBuilder.append("ID : 'a'..'z'+ ;\n");
    grammarBuilder.append("INT : '0'..'9'+;\n");
    grammarBuilder.append("WS : (' '|'\\n') -> skip ;\n");
    String grammar = grammarBuilder.toString();

    String input = "a;";
    String found =
        execParser(
            "T.g4", grammar, "TParser", "TLexer", "TListener", "TVisitor", "s", input, false);

    assertEquals("alt 2\n", found);
    assertNull(this.stderrDuringParse);
  }
Ejemplo n.º 18
0
  /* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
  @Test
  public void testIndependentPredNotPassedOuterCtxToAvoidCastException() throws Exception {
    mkdir(tmpdir);

    StringBuilder grammarBuilder = new StringBuilder(169);
    grammarBuilder.append("grammar T;\n");
    grammarBuilder.append("s : b ';' |  b '.' ;\n");
    grammarBuilder.append("b : a ;\n");
    grammarBuilder.append("a\n");
    grammarBuilder.append("  : {False}? ID {print(\"alt 1\")}\n");
    grammarBuilder.append("  | {True}? ID {print(\"alt 2\")}\n");
    grammarBuilder.append(" ;\n");
    grammarBuilder.append("ID : 'a'..'z'+ ;\n");
    grammarBuilder.append("INT : '0'..'9'+;\n");
    grammarBuilder.append("WS : (' '|'\\n') -> skip ;");
    String grammar = grammarBuilder.toString();

    String input = "a;";
    String found =
        execParser(
            "T.g4", grammar, "TParser", "TLexer", "TListener", "TVisitor", "s", input, false);

    assertEquals("alt 2\n", found);
    assertNull(this.stderrDuringParse);
  }
Ejemplo n.º 19
0
  /* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
  @Test
  public void testOrder() throws Exception {
    mkdir(tmpdir);

    StringBuilder grammarBuilder = new StringBuilder(283);
    grammarBuilder.append("grammar T;\n");
    grammarBuilder.append("s : a {} a; // do 2x: once in ATN, next in DFA;\n");
    grammarBuilder.append("// action blocks lookahead from falling off of 'a'\n");
    grammarBuilder.append("// and looking into 2nd 'a' ref. !ctx dependent pred\n");
    grammarBuilder.append("a : ID {print(\"alt 1\")}\n");
    grammarBuilder.append("  | {True}?  ID {print(\"alt 2\")}\n");
    grammarBuilder.append("  ;\n");
    grammarBuilder.append("ID : 'a'..'z'+ ;\n");
    grammarBuilder.append("INT : '0'..'9'+;\n");
    grammarBuilder.append("WS : (' '|'\\n') -> skip ;");
    String grammar = grammarBuilder.toString();

    String input = "x y";
    String found =
        execParser(
            "T.g4", grammar, "TParser", "TLexer", "TListener", "TVisitor", "s", input, false);

    assertEquals("alt 1\n" + "alt 1\n", found);
    assertNull(this.stderrDuringParse);
  }
Ejemplo n.º 20
0
  /* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
  @Test
  public void test2UnpredicatedAltsAndOneOrthogonalAlt() throws Exception {
    mkdir(tmpdir);

    StringBuilder grammarBuilder = new StringBuilder(321);
    grammarBuilder.append("grammar T;\n");
    grammarBuilder.append(
        "s : {self._interp.predictionMode =  PredictionMode.LL_EXACT_AMBIG_DETECTION} a ';' a ';' a;\n");
    grammarBuilder.append("a : INT {print(\"alt 1\")}\n");
    grammarBuilder.append(
        "  | ID {print(\"alt 2\")} // must pick this one for ID since pred is false\n");
    grammarBuilder.append("  | ID {print(\"alt 3\")}\n");
    grammarBuilder.append("  | {False}? ID {print(\"alt 4\")}\n");
    grammarBuilder.append("  ;\n");
    grammarBuilder.append("ID : 'a'..'z'+ ;\n");
    grammarBuilder.append("INT : '0'..'9'+;\n");
    grammarBuilder.append("WS : (' '|'\\n') -> skip ;");
    String grammar = grammarBuilder.toString();

    String input = "34; x; y";
    String found =
        execParser("T.g4", grammar, "TParser", "TLexer", "TListener", "TVisitor", "s", input, true);

    assertEquals("alt 1\n" + "alt 2\n" + "alt 2\n", found);

    assertEquals(
        "line 1:4 reportAttemptingFullContext d=0 (a), input='x'\n"
            + "line 1:4 reportAmbiguity d=0 (a): ambigAlts={2, 3}, input='x'\n"
            + "line 1:7 reportAttemptingFullContext d=0 (a), input='y'\n"
            + "line 1:7 reportAmbiguity d=0 (a): ambigAlts={2, 3}, input='y'\n",
        this.stderrDuringParse);
  }
  private String tokenizerToString(Tokenizer tokenizer) throws Exception {
    OffsetAttribute extOffset = tokenizer.addAttribute(OffsetAttribute.class);
    PositionIncrementAttribute posIncrAtt =
        tokenizer.addAttribute(PositionIncrementAttribute.class);
    PositionLengthAttribute posLengthAtt = tokenizer.addAttribute(PositionLengthAttribute.class);
    CharTermAttribute term = tokenizer.addAttribute(CharTermAttribute.class);
    TypeAttribute type = tokenizer.addAttribute(TypeAttribute.class);
    SemanticClassAttribute semanticClass = tokenizer.addAttribute(SemanticClassAttribute.class);
    PartOfSpeechAttribute pos = tokenizer.addAttribute(PartOfSpeechAttribute.class);

    StringBuilder result = new StringBuilder();
    tokenizer.reset();
    while (tokenizer.incrementToken() == true) {
      result.append(new String(term.buffer(), 0, term.length())).append(":");
      result.append(type.type()).append(":");
      result.append(pos.partOfSpeech()).append(":");
      result.append(semanticClass.semanticClass()).append(":");
      result.append(String.valueOf(posIncrAtt.getPositionIncrement())).append(":");
      result.append(String.valueOf(posLengthAtt.getPositionLength())).append(":");
      result.append(String.valueOf(extOffset.startOffset())).append(":");
      result.append(String.valueOf(extOffset.endOffset()));
      result.append(",");
    }
    tokenizer.end();
    return result.toString();
  }
Ejemplo n.º 22
0
  /* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
  @Test
  public void testValidateInDFA() throws Exception {
    mkdir(tmpdir);

    StringBuilder grammarBuilder = new StringBuilder(318);
    grammarBuilder.append("grammar T;\n");
    grammarBuilder.append("s : a ';' a;\n");
    grammarBuilder.append("// ';' helps us to resynchronize without consuming\n");
    grammarBuilder.append("// 2nd 'a' reference. We our testing that the DFA also\n");
    grammarBuilder.append("// throws an exception if the validating predicate fails\n");
    grammarBuilder.append("a : {False}? ID  {print(\"alt 1\")}\n");
    grammarBuilder.append("  | {True}?  INT {print(\"alt 2\")}\n");
    grammarBuilder.append("  ;\n");
    grammarBuilder.append("ID : 'a'..'z'+ ;\n");
    grammarBuilder.append("INT : '0'..'9'+;\n");
    grammarBuilder.append("WS : (' '|'\\n') -> skip ;");
    String grammar = grammarBuilder.toString();

    String input = "x ; y";
    String found =
        execParser(
            "T.g4", grammar, "TParser", "TLexer", "TListener", "TVisitor", "s", input, false);

    assertEquals("", found);

    assertEquals(
        "line 1:0 no viable alternative at input 'x'\n"
            + "line 1:4 no viable alternative at input 'y'\n",
        this.stderrDuringParse);
  }
Ejemplo n.º 23
0
 @Test
 public void testSortInhabitantsAndContents() {
   StringBuilder sb = new StringBuilder();
   sb.append("class=service1,index=annotation1,index=contract1:name1\n");
   sb.append("class=service2,index=annotation1,index=contract1\n");
   sb.append(
       "class=service3,index=annotation1,index=annotation2,index=contract1:name2,index=contract2:name2,a=1,b=2\n");
   sb.append("class=service4,a=1\n");
   String expected = sb.toString();
   String output = Utilities.sortInhabitantsDescriptor(testCase(), true);
   assertEquals(expected, output);
 }
Ejemplo n.º 24
0
  public void buildList(int maxLength) {
    Item itemToAdd;

    for (int i = 0; i < maxLength; i++) {
      StringBuilder sb = new StringBuilder();
      sb.append("item");
      sb.append(i);
      float price = i;
      itemToAdd = new Item(sb.toString(), price);
      testList.add(itemToAdd);
    }
  }
Ejemplo n.º 25
0
 protected static String pwdOutputFor(Object... entities) {
   StringBuilder builder = new StringBuilder();
   for (Object entity : entities) {
     builder.append((builder.length() == 0 ? "" : "-->"));
     if (entity instanceof Node) {
       builder.append("(").append(((Node) entity).getId()).append(")");
     } else {
       builder.append("<").append(((Relationship) entity).getId()).append(">");
     }
   }
   return Pattern.quote(builder.toString());
 }
Ejemplo n.º 26
0
  private String toHexString(byte[] response) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < response.length; i++) {
      sb.append(Integer.toHexString(response[i] & 0xFF));

      if (i != response.length - 1) {
        sb.append(' ');
      }
    }

    return sb.toString();
  }
Ejemplo n.º 27
0
 public static String parseFromMap(String address) {
   StringBuilder stringBuilder = new StringBuilder();
   stringBuilder.append(
       "http://map.baidu.com/?newmap=1&reqflag=pcmap&biz=1&from=webmap&da_par=baidu&pcevaname=pc3&qt=s&da_src=searchBox.button&wd=");
   stringBuilder.append(address);
   stringBuilder.append(
       "&c=131&src=0&wd2=&sug=0&l=12&b=%2812926672.97,4820723.72;12989648.97,4831091.72%29&from=webmap&force=newsample&sug_forward=&tn=B_NORMAL_MAP&nn=0&ie=utf-8&t=1430923785326");
   String url = stringBuilder.toString();
   String addressFromDitu = getAddressFromDitu(url);
   Map<String, Map<String, String>> map = FastJsonUtil.getMap(addressFromDitu);
   return map.get("current_city").get("name");
 }
Ejemplo n.º 28
0
 private void doTestCommaDelimitedListToStringArrayLegalMatch(String[] components) {
   StringBuilder sb = new StringBuilder();
   for (int i = 0; i < components.length; i++) {
     if (i != 0) {
       sb.append(",");
     }
     sb.append(components[i]);
   }
   String[] sa = StringUtils.commaDelimitedListToStringArray(sb.toString());
   assertTrue("String array isn't null with legal match", sa != null);
   assertEquals("String array length is correct with legal match", components.length, sa.length);
   assertTrue("Output equals input", Arrays.equals(sa, components));
 }
Ejemplo n.º 29
0
  public static String randomString(String fldName, int length) {

    if (fldName.length() >= length) {
      return fldName.substring(0, length);
    }

    sb.setLength(0);
    sb.append(fldName);
    for (int i = fldName.length(); i < length; i++) {
      sb.append(chars.charAt(random.nextInt(chars.length())));
    }
    return sb.toString();
  }
Ejemplo n.º 30
0
 private static final Pattern asPattern(String fp) {
   if (fp.length() != 40) {
     throw new IllegalArgumentException("bad fp");
   }
   StringBuilder sb = new StringBuilder();
   for (int i = 0; i < 40; i += 4) {
     if (i > 0) {
       sb.append("[\\s\u00a0]*");
     }
     sb.append(fp.substring(i, i + 4));
   }
   return Pattern.compile(sb.toString(), Pattern.CASE_INSENSITIVE);
 }