Exemple #1
1
  private void initIfNeed() {
    if (myInitialized) return;
    myInitialized = true;
    for (Map.Entry<String, Pair<String, List<String>>> entry : myTree.entrySet()) {
      final String group = entry.getKey();
      if (CORE.equals(group)) continue;

      List<IdSet> idSets = new ArrayList<IdSet>();
      StringBuilder description = new StringBuilder();
      for (String idDescription : entry.getValue().getSecond()) {
        IdSet idSet = new IdSet(idDescription);
        String idSetTitle = idSet.getTitle();
        if (idSetTitle == null) continue;
        idSets.add(idSet);
        if (description.length() > 0) {
          description.append(", ");
        }
        description.append(idSetTitle);
      }
      myGroups.put(group, idSets);

      if (description.length() > MAX_DESCR_LENGTH) {
        int lastWord = description.lastIndexOf(",", MAX_DESCR_LENGTH);
        description.delete(lastWord, description.length()).append("...");
      }
      description.insert(0, "<html><body><center><i>");
      myDescriptions.put(group, description.toString());
    }
  }
 public StringBuilder findLocations(Document doc, StringBuilder sb) {
   for (Tag tag : doc.tags) {
     StringBuilder nb = new StringBuilder();
     for (int i = tag.begin; i < tag.end; i++) {
       nb.append(doc.terms.get(i) + " ");
     }
     if (!(nb.lastIndexOf(" ") == -1)) {
       nb.deleteCharAt(nb.lastIndexOf(" "));
     }
     String name = nb.toString();
     sb.append(name);
     sb.append(",");
     sb.append(doc.name);
     sb.append("\n");
   }
   return sb;
 }
Exemple #3
1
 /**
  * pretty print the warning message supplied
  *
  * @param logger logger for the message
  * @param message the message
  */
 private static void prettyPrintWarningMessage(Logger logger, String message) {
   StringBuilder builder = new StringBuilder(message);
   while (builder.length() > 70) {
     int space = builder.lastIndexOf(" ", 70);
     if (space <= 0) space = 70;
     logger.warn(String.format("* %s", builder.substring(0, space)));
     builder.delete(0, space + 1);
   }
   logger.warn(String.format("* %s", builder));
 }
 @NotNull
 private static String stripPath(@NotNull String path) {
   String[] endingsToStrip = {"/", "!", ".jar"};
   StringBuilder buffer = new StringBuilder(path);
   for (String ending : endingsToStrip) {
     if (buffer.lastIndexOf(ending) == buffer.length() - ending.length()) {
       buffer.setLength(buffer.length() - ending.length());
     }
   }
   return buffer.toString();
 }
Exemple #5
1
  /** Return the next element of the json document */
  private String getNextNode() {
    final int popState;

    switch (states.peek()) {
      case ARRAY:
        switch (rand.nextInt(9)) {
          case 0: // String case
            final String val = "stepha" + this.getWhitespace() + "n" + this.getWhitespace() + "e";
            this.addToLastNode(1);
            nodes.add(IntsRef.deepCopyOf(curNodePath));
            images.add(val);
            types.add(ExtendedJsonTokenizer.getTokenTypes()[LITERAL]);
            incr.add(1);
            datatypes.add(XSDDatatype.XSD_STRING);
            return "\"" + val + "\"" + this.getWhitespace() + ",";
          case 1: // DOUBLE case
            this.addToLastNode(1);
            nodes.add(IntsRef.deepCopyOf(curNodePath));
            images.add("34.560e-9");
            types.add(ExtendedJsonTokenizer.getTokenTypes()[NUMBER]);
            incr.add(1);
            datatypes.add(XSDDatatype.XSD_DOUBLE);
            return "34.560e-9" + this.getWhitespace() + ",";
          case 2: // LONG case
            this.addToLastNode(1);
            nodes.add(IntsRef.deepCopyOf(curNodePath));
            images.add("34560e-9");
            types.add(ExtendedJsonTokenizer.getTokenTypes()[NUMBER]);
            incr.add(1);
            datatypes.add(XSDDatatype.XSD_LONG);
            return "34560e-9" + this.getWhitespace() + ",";
          case 3: // true case
            this.addToLastNode(1);
            nodes.add(IntsRef.deepCopyOf(curNodePath));
            images.add("true");
            types.add(ExtendedJsonTokenizer.getTokenTypes()[TRUE]);
            incr.add(1);
            datatypes.add(XSDDatatype.XSD_BOOLEAN);
            return "true" + this.getWhitespace() + ",";
          case 4: // false case
            this.addToLastNode(1);
            nodes.add(IntsRef.deepCopyOf(curNodePath));
            images.add("false");
            types.add(ExtendedJsonTokenizer.getTokenTypes()[FALSE]);
            incr.add(1);
            datatypes.add(XSDDatatype.XSD_BOOLEAN);
            return "false" + this.getWhitespace() + ",";
          case 5: // null case
            this.addToLastNode(1);
            nodes.add(IntsRef.deepCopyOf(curNodePath));
            images.add("null");
            types.add(ExtendedJsonTokenizer.getTokenTypes()[NULL]);
            incr.add(1);
            datatypes.add(XSDDatatype.XSD_STRING);
            return "null" + this.getWhitespace() + ",";
          case 6: // nested array case
            if (states.size() <= MAX_DEPTH) {
              this.addToLastNode(1);
              this.incrNodeObjectPath();
              states.add(ARRAY);
              return "[";
            }
            return "";
          case 7: // nested object case
            if (states.size() <= MAX_DEPTH) {
              this.addToLastNode(1);
              this.incrNodeObjectPath();
              states.add(ARRAY_OBJECT);
              return "{";
            }
            return "";
          case 8: // closing array case
            this.decrNodeObjectPath();
            popState = states.pop();
            if (popState != ARRAY) {
              shouldFail = true;
            }
            // Remove previous comma, this is not allowed
            final int comma = sb.lastIndexOf(",");
            if (comma != -1 && sb.substring(comma + 1).matches("\\s*")) {
              sb.deleteCharAt(comma);
            }
            return "],";
        }
      case ARRAY_OBJECT:
      case OBJECT_ATT:
        switch (rand.nextInt(3)) {
          case 0: // new object field
            types.add(ExtendedJsonTokenizer.getTokenTypes()[LITERAL]);
            images.add("ste ph ane");
            incr.add(1);
            this.addToLastNode(1);
            nodes.add(IntsRef.deepCopyOf(curNodePath));
            datatypes.add(JSONDatatype.JSON_FIELD);

            states.push(OBJECT_VAL);
            return "\"ste ph ane\"" + this.getWhitespace() + ":";
          case 1: // close object
            if (states.peek() == OBJECT_ATT && nestedObjs > 0) {
              this.decrNodeObjectPath();
              nestedObjs--;
            }
            this.decrNodeObjectPath();
            popState = states.pop();
            if (popState != OBJECT_ATT && popState != ARRAY_OBJECT) {
              shouldFail = true;
            }
            // Remove previous comma, this is not allowed
            final int comma = sb.lastIndexOf(",");
            if (comma != -1 && sb.substring(comma + 1).matches("\\s*")) {
              sb.deleteCharAt(comma);
            }
            return states.empty() ? "}" : "},";
          case 2: // Datatype
            if (getLastNode() >= 0) {
              // this nested object cannot be a datatype object because other things have been added
              // to it
              return "";
            }
            final String field;
            if (states.isEmpty()) {
              // datatype object at the root are not possible
              shouldFail = true;
              field = "{";
            } else if (states.peek() == OBJECT_ATT) {
              // field name
              this.addToLastNode(1);
              field = "\"field\":{";
              types.add(ExtendedJsonTokenizer.getTokenTypes()[LITERAL]);
              images.add("field");
              incr.add(1);
              nodes.add(IntsRef.deepCopyOf(curNodePath));
              datatypes.add(JSONDatatype.JSON_FIELD);
              // value
              this.incrNodeObjectPath();
              this.setLastNode(0);
            } else if (states.peek() == ARRAY) {
              this.addToLastNode(1);
              field = "{";
            } else if (states.peek() == ARRAY_OBJECT) {
              this.decrNodeObjectPath();
              field = "";
            } else {
              // should not happen
              throw new IllegalStateException("Received unknown state=" + states.peek());
            }

            types.add(ExtendedJsonTokenizer.getTokenTypes()[LITERAL]);
            images.add("Luke Skywalker");
            incr.add(1);
            nodes.add(IntsRef.deepCopyOf(curNodePath));
            datatypes.add("jedi");
            // close datatype object
            if (states.peek() == ARRAY_OBJECT) {
              popState = states.pop();
            } else {
              this.decrNodeObjectPath();
            }
            return field
                + this.getWhitespace()
                + "\""
                + ExtendedJsonTokenizer.DATATYPE_LABEL
                + "\":"
                + this.getWhitespace()
                + "\"jedi\","
                + "\""
                + ExtendedJsonTokenizer.DATATYPE_VALUES
                + "\":"
                + this.getWhitespace()
                + "\"Luke Skywalker\""
                + this.getWhitespace()
                + "},";
        }
      case OBJECT_VAL:
        switch (rand.nextInt(8)) {
          case 0: // String
            return this.doValString(
                "stepha" + this.getWhitespace() + "n" + this.getWhitespace() + "e");
          case 1: // DOUBLE case
            images.add("34.560e-9");
            types.add(ExtendedJsonTokenizer.getTokenTypes()[NUMBER]);
            incr.add(1);
            this.incrNodeObjectPath();
            this.setLastNode(0);
            nodes.add(IntsRef.deepCopyOf(curNodePath));
            this.decrNodeObjectPath();
            datatypes.add(XSDDatatype.XSD_DOUBLE);

            states.pop(); // remove OBJECT_VAL state
            return "34.560e-9" + this.getWhitespace() + ",";
          case 2: // LONG case
            images.add("34560e-9");
            types.add(ExtendedJsonTokenizer.getTokenTypes()[NUMBER]);
            incr.add(1);
            this.incrNodeObjectPath();
            this.setLastNode(0);
            nodes.add(IntsRef.deepCopyOf(curNodePath));
            this.decrNodeObjectPath();
            datatypes.add(XSDDatatype.XSD_LONG);

            states.pop(); // remove OBJECT_VAL state
            return "34560e-9" + this.getWhitespace() + ",";
          case 3: // True
            images.add("true");
            types.add(ExtendedJsonTokenizer.getTokenTypes()[TRUE]);
            incr.add(1);
            this.incrNodeObjectPath();
            this.setLastNode(0);
            nodes.add(IntsRef.deepCopyOf(curNodePath));
            this.decrNodeObjectPath();
            datatypes.add(XSDDatatype.XSD_BOOLEAN);

            states.pop(); // remove OBJECT_VAL state
            return "true" + this.getWhitespace() + ",";
          case 4: // False
            images.add("false");
            types.add(ExtendedJsonTokenizer.getTokenTypes()[FALSE]);
            incr.add(1);
            this.incrNodeObjectPath();
            this.setLastNode(0);
            nodes.add(IntsRef.deepCopyOf(curNodePath));
            this.decrNodeObjectPath();
            datatypes.add(XSDDatatype.XSD_BOOLEAN);

            states.pop(); // remove OBJECT_VAL state
            return "false" + this.getWhitespace() + ",";
          case 5: // NULL
            images.add("null");
            types.add(ExtendedJsonTokenizer.getTokenTypes()[NULL]);
            incr.add(1);
            this.incrNodeObjectPath();
            this.setLastNode(0);
            nodes.add(IntsRef.deepCopyOf(curNodePath));
            this.decrNodeObjectPath();
            datatypes.add(XSDDatatype.XSD_STRING);

            states.pop(); // remove OBJECT_VAL state
            return "null" + this.getWhitespace() + ",";
          case 6: // New array
            if (states.size() <= MAX_DEPTH) {
              states.pop(); // remove OBJECT_VAL state
              this.incrNodeObjectPath();
              states.add(ARRAY);
              return "[";
            }
            return this.doValString("");
          case 7: // new Object
            if (states.size() <= MAX_DEPTH) {
              states.pop(); // remove OBJECT_VAL state
              // Two incrementations, because the object introduce a "blank" node
              nestedObjs++;
              this.incrNodeObjectPath();
              this.setLastNode(0);
              this.incrNodeObjectPath();
              states.add(OBJECT_ATT);
              return "{";
            }
            return this.doValString("");
        }
      default:
        throw new IllegalStateException("Got unknown lexical state: " + states.peek());
    }
  }
 @Override
 protected void appendNullText(StringBuilder buffer) {
   buffer.setLength(buffer.lastIndexOf("\n") + 1);
 }