Java StringBuilder.substring Examples

Java StringBuilder.substring - 30 examples found. These are the top rated real world Java examples of StringBuilder.substring extracted from open source projects. You can rate examples to help us improve the quality of examples.
  private String createUnion(
      int index, Collection<Object> params, String fieldName, String operator) {
    StringBuilder queryUnion = new StringBuilder();
    StringBuilder queryFilter = new StringBuilder();

    for (Object param : params) {
      String letName = "$q" + index++;
      queryFilter
          .append(", ")
          .append(letName)
          .append(" = (SELECT FROM MeIdentification WHERE ")
          .append(fieldName)
          .append(' ')
          .append(operator)
          .append(" '")
          .append(param)
          .append("')");
      queryUnion.append(",").append(letName);
    }

    if (params.size() == 1) return queryFilter.toString();
    else
      return ", $q"
          + index
          + " = (SELECT FROM MeIdentification WHERE @rid IN ( SELECT UNIONALL("
          + queryUnion.substring(1)
          + ") LET "
          + queryFilter.substring(2)
          + " ))";
  }
  public Map<String, String> getDiscoveryMap() {
    NetBenchClient nbc = new NetBenchClient();
    Map<String, String> dhm = null;
    try {
      Map<String, ArrayList<String>> tmphm = new HashMap<String, ArrayList<String>>();
      dhm = new HashMap<String, String>();
      List<MsgEvent> dlist = discover();
      for (MsgEvent me : dlist) {
        String agentpath = me.getMsgRegion() + "_" + me.getMsgAgent();
        String ippath = me.getParam("clientip") + "_" + me.getParam("serverip");
        // Benchmark connection here.. will have to do self-terminating code at some point
        String netBenchResult =
            nbc.benchmarkThroughput(me.getParam("serverip"), "benchmark-throughput", 3, 1);
        if (netBenchResult != null) {
          ippath = ippath + "_" + netBenchResult;
        }

        //
        if (!tmphm.containsKey(agentpath)) {
          ArrayList<String> newList = new ArrayList<String>();
          newList.add(ippath);
          tmphm.put(agentpath, newList);
        } else {
          ArrayList<String> newList = tmphm.get(agentpath);
          if (!newList.contains(ippath)) {
            newList.add(ippath);
            tmphm.put(agentpath, newList);
          }
        }
      }

      if (!tmphm.isEmpty()) {
        StringBuilder keylist = new StringBuilder();
        for (Entry<String, ArrayList<String>> entry : tmphm.entrySet()) {
          String agentpath = entry.getKey();
          keylist.append(agentpath + ",");
          ArrayList<String> ipList = entry.getValue();
          // System.out.println(agentpath);
          StringBuilder sb = new StringBuilder();

          for (String ip : ipList) {
            // System.out.println(ip);
            sb.append(ip + ",");
          }
          String ips = sb.substring(0, sb.length() - 1);
          dhm.put(agentpath, ips);
          // do what you have to do here
          // In your case, an other loop.
        }

        String keyfound = keylist.substring(0, keylist.length() - 1);
        dhm.put("discoveredagents", keyfound);
      }

    } catch (Exception ex) {
      System.out.println("DiscoveryClient : getDiscovery : " + ex.toString());
    }

    return dhm;
  }
Example #3
0
  private String getSegment() {

    String segment = null;

    int pos = m_sb.indexOf(SEPARATOR);
    int sl = SEPARATOR.length();

    if (pos > 0 && pos + sl < m_sb.length() && m_sb.charAt(pos + sl) == '\r') {
      sl++;
    }

    if (pos > 0 && pos + sl < m_sb.length() && m_sb.charAt(pos + sl) == '\n') {
      sl++;
    }

    if (pos >= 0) {
      segment = m_sb.substring(0, pos);

      m_sb.delete(0, pos + sl);
    } else {
      pos = m_sb.indexOf(TERMINATOR);

      if (pos >= 0) {
        m_last = true;
        segment = m_sb.substring(0, pos);
      }
    }

    return segment;
  }
Example #4
0
  /*
   * Assumes valid xml
   */
  private String getElement(Reader reader) throws IOException {
    StringBuilder result = new StringBuilder();
    result.append('<');

    boolean done = false;

    while (!done) {
      int current = reader.read();
      while (current != '>') {
        if (current < 0) {
          throw new EOFException();
        }
        result.append((char) current);
        current = reader.read();
      }
      result.append((char) current);

      int len = result.length();
      if (len > 4 && result.substring(0, 4).equals("<!--")) {
        // This is a comment - make sure we are at the end
        if (len >= 7 && result.substring(len - 3, len).equals("-->")) {
          done = true;
        }
      } else {
        done = true;
      }
    }

    return result.toString();
  }
  @Override
  public String toSourceString() {

    StringBuilder sb = new StringBuilder();

    appendSourceStringForChildren(sb);

    if (userSuppliedPlaceholderName != null) {
      int indexBeforeClose;
      if (isSelfEnding) {
        indexBeforeClose = sb.length() - 2;
        if (!sb.substring(indexBeforeClose).equals("/>")) {
          throw new AssertionError();
        }
      } else {
        indexBeforeClose = sb.length() - 1;
        if (!sb.substring(indexBeforeClose).equals(">")) {
          throw new AssertionError();
        }
      }
      sb.insert(indexBeforeClose, " phname=\"" + userSuppliedPlaceholderName + "\"");
    }

    return sb.toString();
  }
Example #6
0
  public static UUID generateUuidForName(String name) {
    TFM_Log.info("Generating spoof UUID for " + name);
    name = name.toLowerCase();
    try {
      final MessageDigest mDigest = MessageDigest.getInstance("SHA1");
      byte[] result = mDigest.digest(name.getBytes());
      final StringBuilder sb = new StringBuilder();
      for (int i = 0; i < result.length; i++) {
        sb.append(Integer.toString((result[i] & 0xff) + 0x100, 16).substring(1));
      }

      return UUID.fromString(
          sb.substring(0, 8)
              + "-"
              + sb.substring(8, 12)
              + "-"
              + sb.substring(12, 16)
              + "-"
              + sb.substring(16, 20)
              + "-"
              + sb.substring(20, 32));
    } catch (NoSuchAlgorithmException ex) {
      TFM_Log.severe(ex);
    }

    return UUID.randomUUID();
  }