Example #1
1
 private void wire(final String header, final byte[] b, final int pos, final int off) {
   final StringBuilder buffer = new StringBuilder();
   for (int i = 0; i < off; i++) {
     final int ch = b[pos + i];
     if (ch == 13) {
       buffer.append("[\\r]");
     } else if (ch == 10) {
       buffer.append("[\\n]\"");
       buffer.insert(0, "\"");
       buffer.insert(0, header);
       this.log.debug(this.id + " " + buffer.toString());
       buffer.setLength(0);
     } else if ((ch < 32) || (ch > 127)) {
       buffer.append("[0x");
       buffer.append(Integer.toHexString(ch));
       buffer.append("]");
     } else {
       buffer.append((char) ch);
     }
   }
   if (buffer.length() > 0) {
     buffer.append('\"');
     buffer.insert(0, '\"');
     buffer.insert(0, header);
     this.log.debug(this.id + " " + buffer.toString());
   }
 }
Example #2
1
 private void timesClause(StringBuilder sb, int offset, Map<String, Timestamp> eachTime)
     throws ParseException {
   Timestamp ts = null;
   List<String> times = bulkFilter.get(BulkResponseImpl.BULK_FILTER_START_CREATED_EPOCH);
   if (times != null) {
     ts = new Timestamp(DateUtils.parseDateUTC(times.get(0)).getTime());
     sb.insert(offset - 1, " AND a.createdTimestamp >= :startCreated");
     eachTime.put("startCreated", ts);
   }
   times = bulkFilter.get(BulkResponseImpl.BULK_FILTER_END_CREATED_EPOCH);
   if (times != null) {
     ts = new Timestamp(DateUtils.parseDateUTC(times.get(0)).getTime());
     sb.insert(offset - 1, " AND a.createdTimestamp <= :endCreated");
     eachTime.put("endCreated", ts);
   }
   times = bulkFilter.get(BulkResponseImpl.BULK_FILTER_START_NOMINAL_EPOCH);
   if (times != null) {
     ts = new Timestamp(DateUtils.parseDateUTC(times.get(0)).getTime());
     sb.insert(offset - 1, " AND a.nominalTimestamp >= :startNominal");
     eachTime.put("startNominal", ts);
   }
   times = bulkFilter.get(BulkResponseImpl.BULK_FILTER_END_NOMINAL_EPOCH);
   if (times != null) {
     ts = new Timestamp(DateUtils.parseDateUTC(times.get(0)).getTime());
     sb.insert(offset - 1, " AND a.nominalTimestamp <= :endNominal");
     eachTime.put("endNominal", ts);
   }
 }
  private void generateParens(
      ArrayList<String> list, int leftRem, int rightRem, StringBuilder sb, int index) {

    // number of left parentheses remaining cannot be less than 0
    // cannot possibly have a valid string having inserted more
    // right parentheses than left parentheses
    if (leftRem < 0 || rightRem < leftRem) return;

    if (leftRem == 0 && rightRem == 0) list.add(sb.toString());
    else {
      // add left parenthesis if any left
      if (leftRem > 0) {
        try {
          sb.setCharAt(index, '(');
        } catch (Exception e) {
          sb.insert(index, "(");
        }
        generateParens(list, leftRem - 1, rightRem, sb, index + 1);
      }

      // add right parenthesis if valid
      if (rightRem > leftRem) {
        try {
          sb.setCharAt(index, ')');
        } catch (Exception e) {
          sb.insert(index, ")");
        }
        generateParens(list, leftRem, rightRem - 1, sb, index + 1);
      }
    }
  }
  @SuppressWarnings("unchecked")
  @Override
  public <R extends HttpRequest> R bindToRequest(R request, Object payload) {
    // If we have a payload/bucket/container that is not all lowercase, vhost-style URLs are not an
    // option and must be
    // automatically converted to their path-based equivalent.  This should only be possible for
    // AWS-S3 since it is
    // the only S3 implementation configured to allow uppercase payload/bucket/container names.
    //
    // http://code.google.com/p/jclouds/issues/detail?id=992
    String payloadAsString = payload.toString();

    if (isVhostStyle && payloadAsString.equals(payloadAsString.toLowerCase())) {
      request = bindAsHostPrefix.bindToRequest(request, payload);
      String host = request.getEndpoint().getHost();
      if (request.getEndpoint().getPort() != -1) {
        host += ":" + request.getEndpoint().getPort();
      }
      return (R) request.toBuilder().replaceHeader(HttpHeaders.HOST, host).build();
    } else {
      StringBuilder path = new StringBuilder(request.getEndpoint().getPath());
      if (servicePath.equals("/")) {
        if (path.toString().equals("/")) path.append(payloadAsString);
        else path.insert(0, "/" + payloadAsString);
      } else {
        int indexToInsert = 0;
        indexToInsert = path.indexOf(servicePath);
        indexToInsert = indexToInsert == -1 ? 0 : indexToInsert;
        indexToInsert += servicePath.length();
        path.insert(indexToInsert, "/" + payloadAsString);
      }
      return (R) request.toBuilder().replacePath(path.toString()).build();
    }
  }
Example #5
1
  /**
   * Creates a relative path to the given {@link ConfigurationSection} from the given relative
   * section.
   *
   * <p>You may use this method for any given {@link ConfigurationSection}, not only {@link
   * MemorySection}.
   *
   * @param section Section to create a path for.
   * @param key Name of the specified section.
   * @param relativeTo Section to create the path relative to.
   * @return Full path of the section from its root.
   */
  public static String createPath(
      ConfigurationSection section, String key, ConfigurationSection relativeTo) {
    StringBuilder builder = new StringBuilder();

    if (section != null) {
      for (ConfigurationSection parent = section;
          (parent != null) && (parent != relativeTo);
          parent = parent.getParent()) {
        if (builder.length() > 0) {
          builder.insert(0, section.getRoot().options().pathSeparator());
        }

        builder.insert(0, parent.getName());
      }
    }

    if ((key != null) && (key.length() > 0)) {
      if (builder.length() > 0) {
        builder.append(section.getRoot().options().pathSeparator());
      }

      builder.append(key);
    }

    return builder.toString();
  }
Example #6
1
  @Override
  public void saveConfig() {
    String str = this.getConfig().saveToString();
    StringBuilder sb = new StringBuilder(str);

    sb.insert(
        sb.indexOf("\nversion:") + 1,
        "\n# Configuration version used during upgrade. Do not change.\n");

    sb.insert(
        sb.indexOf("\nmute_minutes") + 1,
        "\n# The default number of minutes a player will remain muted.\n");

    sb.insert(
        sb.indexOf("\nprotect_boats") + 1,
        "\n# When true, protects boats from breakage unless deliberately broken.\n");

    final File cfg_file = new File(this.getDataFolder(), "config.yml");
    final String cfg_str = sb.toString();
    final Logger logger = this.getLogger();

    new BukkitRunnable() {
      @Override
      public void run() {
        cfg_file.delete();
        try (PrintWriter writer = new PrintWriter(cfg_file, "UTF-8")) {
          cfg_file.createNewFile();
          writer.write(cfg_str);
          writer.close();
        } catch (IOException ex) {
          logger.severe("Error saving configuration!");
        }
      }
    }.runTaskAsynchronously(this);
  }
 static DecoderResult decode(byte[] bytes, int mode) {
   StringBuilder result = new StringBuilder(144);
   switch (mode) {
     case 2:
     case 3:
       String postcode;
       if (mode == 2) {
         int pc = getPostCode2(bytes);
         NumberFormat df = new DecimalFormat("0000000000".substring(0, getPostCode2Length(bytes)));
         postcode = df.format(pc);
       } else {
         postcode = getPostCode3(bytes);
       }
       String country = THREE_DIGITS.format(getCountry(bytes));
       String service = THREE_DIGITS.format(getServiceClass(bytes));
       result.append(getMessage(bytes, 10, 84));
       if (result.toString().startsWith("[)>" + RS + "01" + GS)) {
         result.insert(9, postcode + GS + country + GS + service + GS);
       } else {
         result.insert(0, postcode + GS + country + GS + service + GS);
       }
       break;
     case 4:
       result.append(getMessage(bytes, 1, 93));
       break;
     case 5:
       result.append(getMessage(bytes, 1, 77));
       break;
   }
   return new DecoderResult(bytes, result.toString(), null, String.valueOf(mode));
 }
 @NotNull
 public static String getProjectRepresentationName(
     @NotNull String targetProjectPath, @Nullable String rootProjectPath) {
   if (rootProjectPath == null) {
     File rootProjectDir = new File(targetProjectPath);
     if (rootProjectDir.isFile()) {
       rootProjectDir = rootProjectDir.getParentFile();
     }
     return rootProjectDir.getName();
   }
   File rootProjectDir = new File(rootProjectPath);
   if (rootProjectDir.isFile()) {
     rootProjectDir = rootProjectDir.getParentFile();
   }
   File targetProjectDir = new File(targetProjectPath);
   if (targetProjectDir.isFile()) {
     targetProjectDir = targetProjectDir.getParentFile();
   }
   StringBuilder buffer = new StringBuilder();
   for (File f = targetProjectDir;
       f != null && !FileUtil.filesEqual(f, rootProjectDir);
       f = f.getParentFile()) {
     buffer.insert(0, f.getName()).insert(0, ":");
   }
   buffer.insert(0, rootProjectDir.getName());
   return buffer.toString();
 }
  public static String createPath(
      ConfigurationSection section, String key, ConfigurationSection relativeTo) {
    Configuration root = section.getRoot();
    if (root == null) {
      throw new IllegalStateException("Cannot create path without a root");
    }
    char separator = root.options().pathSeparator();

    StringBuilder builder = new StringBuilder();
    if (section != null) {
      for (ConfigurationSection parent = section;
          (parent != null) && (parent != relativeTo);
          parent = parent.getParent()) {
        if (builder.length() > 0) {
          builder.insert(0, separator);
        }

        builder.insert(0, parent.getName());
      }
    }

    if ((key != null) && (key.length() > 0)) {
      if (builder.length() > 0) {
        builder.append(separator);
      }

      builder.append(key);
    }

    return builder.toString();
  }
  @NotNull
  private static String getPresentableElementPosition(
      @NotNull final CodeInsightTestFixture fixture, final @Nullable PsiElement element) {
    if (element == null) return "";

    final StringBuilder buf = new StringBuilder(element.getText());
    DartComponent component = PsiTreeUtil.getParentOfType(element, DartComponent.class);
    while (component != null) {
      final DartComponentName componentName = component.getComponentName();
      if (componentName != null && componentName != element) {
        buf.insert(0, component.getName() + " -> ");
      }
      component = PsiTreeUtil.getParentOfType(component, DartComponent.class);
    }
    String path =
        element instanceof PsiDirectoryImpl
            ? ((PsiDirectoryImpl) element).getVirtualFile().getPath()
            : element.getContainingFile().getVirtualFile().getPath();

    final String contentRoot =
        ModuleRootManager.getInstance(fixture.getModule()).getContentRoots()[0].getPath();
    if (path.equals(contentRoot)) path = "[content root]";

    final String contentRootWithSlash = contentRoot + "/";
    if (path.startsWith(contentRootWithSlash)) path = path.substring(contentRootWithSlash.length());

    final DartSdk sdk = DartSdk.getDartSdk(element.getProject());
    if (sdk != null && path.startsWith(sdk.getHomePath()))
      path = "[Dart SDK]" + path.substring(sdk.getHomePath().length());

    if (buf.length() > 0) buf.insert(0, " -> ");
    buf.insert(0, path);

    return buf.toString();
  }
Example #11
0
  public void addOrderBy(Class<?> clazz, String field, boolean ascending) {
    if (field == null) {
      return;
    }
    Field f;
    Pair<Class<?>, Field> pair = ReflectUtil.getAnyField(clazz, field);
    assert (pair != null) : "Can't find field " + field + " in " + clazz.getName();
    clazz = pair.first();
    f = pair.second();

    Column column = f.getAnnotation(Column.class);
    String name = column != null ? column.name() : field;

    StringBuilder order = new StringBuilder();
    if (column.table() == null || column.table().length() == 0) {
      order.append(DbUtil.getTableName(clazz));
    } else {
      order.append(column.table());
    }
    order.append(".").append(name).append(ascending ? " ASC " : " DESC ");

    if (_orderBy == null) {
      _orderBy = order.insert(0, " ORDER BY ").toString();
    } else {
      _orderBy = order.insert(0, _orderBy).toString();
    }
  }
  private static Couple<Integer> composeText(
      StringBuilder sb,
      List<Pair<String, HighlightInfo>> list,
      int index,
      String text,
      int endPos,
      int startPos) {
    int i = index;
    while (i < list.size()) {
      Pair<String, HighlightInfo> pair = list.get(i);
      HighlightInfo info = pair.second;
      if (info.endOffset <= startPos) {
        break;
      }

      String severity = pair.first;
      HighlightInfo prev = i < list.size() - 1 ? list.get(i + 1).second : null;

      sb.insert(0, text.substring(info.endOffset, endPos));
      sb.insert(0, "</" + severity + ">");
      endPos = info.endOffset;
      if (prev != null && prev.endOffset > info.startOffset) {
        Couple<Integer> result = composeText(sb, list, i + 1, text, endPos, info.startOffset);
        i = result.first - 1;
        endPos = result.second;
      }
      sb.insert(0, text.substring(info.startOffset, endPos));
      sb.insert(0, "<" + severity + " descr=\"" + info.getDescription() + "\">");

      endPos = info.startOffset;
      i++;
    }

    return Couple.newOne(i, endPos);
  }
  @Override
  public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {

    String CPF = getText(0, getLength());
    for (int i = 0; i < str.length(); i++) {
      char c = str.charAt(i);
      if (!Character.isDigit(c)) {
        return;
      }
    }

    if (CPF.length() < tamanho) {
      super.remove(0, getLength());
      StringBuilder s = new StringBuilder(CPF + str);

      if (s.length() == 3) {
        s.insert(3, ".");
      } else if (s.length() == 7) {
        s.insert(7, ".");
      } else if (s.length() == 11) {
        s.insert(11, "-");
      }

      super.insertString(0, s.toString(), a);
    }
  }
  public void testPsi2DocSurround() throws Exception {
    StringBuilder buffer = new StringBuilder("0123456789");
    RangeMarker marker = createMarker(buffer.toString(), 2, 5);
    synchronizer.startTransaction(getProject(), document, psiFile);

    synchronizer.replaceString(document, 3, 5, "3a4");
    buffer.replace(3, 5, "3a4");

    synchronizer.insertString(document, 3, "b");
    buffer.insert(3, "b");

    synchronizer.insertString(document, 7, "d");
    buffer.insert(7, "d");

    final PsiToDocumentSynchronizer.DocumentChangeTransaction transaction =
        synchronizer.getTransaction(document);
    final Set<Pair<PsiToDocumentSynchronizer.MutableTextRange, StringBuffer>> affectedFragments =
        transaction.getAffectedFragments();
    assertEquals(3, affectedFragments.size());

    synchronizer.commitTransaction(document);

    assertEquals(buffer.toString(), document.getText());

    assertValidMarker(marker, 2, 7);
  }
  public static String linkify(List<Link> links, String text) {

    // if(!hasLinks(links)) { return text; }

    int addedChars = 0; // offset for inserting

    for (Link link : links) {
      StringBuilder stringBuilder = new StringBuilder(text);

      int start = link.getStart();
      int end = link.getEnd();
      String href = link.getHref();
      String openTag = String.format(aherf, href);

      stringBuilder.insert(addedChars + start, openTag);
      addedChars += openTag.length();

      stringBuilder.insert(addedChars + end, closeTag);
      addedChars += closeTag.length();

      text = stringBuilder.toString();
    }

    return text;
  }
Example #16
0
 @Override
 public void formatTo(Formatter formatter, int flags, int width, int precision) {
   StringBuilder sb = new StringBuilder();
   boolean alternate = (flags & ALTERNATE) == ALTERNATE;
   if (alternate) {
     sb.append(value);
   } else {
     sb.append(
         String.format(
             "%s %s %s %s",
             value.substring(0, 3),
             value.substring(3, 7),
             value.substring(7, 11),
             value.substring(11)));
   }
   int length = sb.length();
   if (length < width) {
     for (int i = 0; i < width - length; i++) {
       if (alternate) {
         sb.insert(0, '0');
       } else {
         boolean leftJustified = (flags & LEFT_JUSTIFY) == LEFT_JUSTIFY;
         if (leftJustified) {
           sb.append(' ');
         } else {
           sb.insert(0, ' ');
         }
       }
     }
   }
   formatter.format(sb.toString());
 }
Example #17
0
  public String toMenuLocationDebug(final String profileID, final Locale locale) {
    final String SEPARATOR =
        LocaleHelper.getLocalizedMessage(locale, Config.Display_SettingNavigationSeparator, null);
    final StringBuilder sb = new StringBuilder();

    PwmSettingCategory nextCategory = this;
    while (nextCategory != null) {
      if (nextCategory != this) {
        sb.insert(0, nextCategory.getLabel(locale) + SEPARATOR);
      } else {
        sb.insert(0, nextCategory.getLabel(locale));
      }
      nextCategory = nextCategory.getParent();
    }

    if (this.hasProfiles()) {
      if (profileID != null) {
        sb.append(SEPARATOR);
        sb.append(profileID);
      } else {
        final String NULL_PROFILE =
            LocaleHelper.getLocalizedMessage(
                locale, Config.Display_SettingNavigationNullProfile, null);
        sb.append(SEPARATOR);
        sb.append(NULL_PROFILE);
      }
    }

    return sb.toString();
  }
Example #18
0
  /**
   * First if clause tests if there are enough player initialized The rest tests if all players are
   * valid means every player has one or more names and a weapon ErrorMessage is a string builder to
   * create a string which is sent to the error handling with the exception Error is a variable
   * which shows if an error was found or not
   */
  private void errorCheck() throws FileNotFoundException, InvalidParameterException {
    if (DistrictAmount * PlayersPerDistrict > Players.length) {
      throw new FileNotFoundException(
          String.valueOf(DistrictAmount * PlayersPerDistrict - Players.length));
    }

    StringBuilder ErrorMessage = new StringBuilder();
    boolean error = false;

    for (int i = 0; i < Players.length; i++) {
      if (Players[i].replaceAll("\\s+", " ").split(" ").length < 2) {
        ErrorMessage.append(String.valueOf(i + 1) + " ");
        error = true;
      }
    }

    if (error) {
      int i;
      for (i = 1;
          i < ErrorMessage.toString().replaceAll("\\s+", " ").split(" ").length * 3 - 7;
          i = i + 3) {
        ErrorMessage.insert(i, ",");
      }

      if (ErrorMessage.toString().replaceAll("\\s+", " ").split(" ").length != 1) {
        ErrorMessage.insert(i + 1, "and ");
      }

      ErrorMessage.deleteCharAt(
          ErrorMessage.toString().replaceAll("\\s+", " ").split(" ").length * 3 - 2);
      throw new InvalidParameterException(ErrorMessage.toString());
    }
  }
Example #19
0
 public static String addBinary(String a, String b) {
   if (a.length() < b.length()) {
     String tmp = a;
     a = b;
     b = tmp;
   }
   int lengthA = a.length();
   int lengthB = b.length();
   int indexA = lengthA - 1;
   int indexB = lengthB - 1;
   int carry = 0;
   StringBuilder sb = new StringBuilder();
   while (indexA >= 0 && indexB >= 0) {
     int sum = a.charAt(indexA) - '0' + b.charAt(indexB) - '0' + carry;
     carry = sum / 2;
     sb.insert(0, sum % 2);
     indexA--;
     indexB--;
   }
   while (indexA >= 0) {
     int sum = a.charAt(indexA) - '0' + carry;
     carry = sum / 2;
     sb.insert(0, sum % 2);
     indexA--;
   }
   if (carry == 1) {
     sb.insert(0, 1);
   }
   return sb.toString();
 }
Example #20
0
  public String addBinary(String a, String b) {
    if (a == null && b == null) {
      return null;
    } else if (a == null || b == null) {
      return (a == null) ? b : a;
    } else if (a.length() == 0 && b.length() == 0) {
      return "";
    } else if (a.length() == 0 || b.length() == 0) {
      return (a.length() == 0) ? b : a;
    }

    int aIndex = a.length() - 1;
    int bIndex = b.length() - 1;
    boolean carry = false;

    StringBuilder resultBuilder = new StringBuilder();

    while (aIndex >= 0 || bIndex >= 0) {
      char aDigit = '\0';
      char bDigit = '\0';

      if (aIndex >= 0) {
        aDigit = a.charAt(aIndex);
        aIndex--;
      }
      if (bIndex >= 0) {
        bDigit = b.charAt(bIndex);
        bIndex--;
      }

      char newDigit = '\0';

      if (aDigit == '1' && bDigit == '1') {
        if (carry) {
          newDigit = '1';
        } else {
          newDigit = '0';
          carry = true;
        }
      } else if (aDigit == '1' || bDigit == '1') {
        newDigit = (carry) ? '0' : '1';
      } else {
        if (carry) {
          newDigit = '1';
          carry = false;
        } else {
          newDigit = '0';
        }
      }

      resultBuilder.insert(0, newDigit);
    }

    if (carry) {
      resultBuilder.insert(0, '1');
    }

    return resultBuilder.toString();
  }
Example #21
0
  /**
   * Escape the value before saving
   *
   * @param x the value to escape
   * @return the escaped value
   */
  private static String escapeValue(final String x) {
    boolean inquote = false;
    int lineStart = 0;
    final StringBuilder r = new StringBuilder(x.length());
    for (int k = 0; k < x.length(); k++) {
      final char c = x.charAt(k);
      switch (c) {
        case '\n':
          if (inquote) {
            r.append('"');
            inquote = false;
          }
          r.append("\\n\\\n");
          lineStart = r.length();
          break;

        case '\t':
          r.append("\\t");
          break;

        case '\b':
          r.append("\\b");
          break;

        case '\\':
          r.append("\\\\");
          break;

        case '"':
          r.append("\\\"");
          break;

        case ';':
        case '#':
          if (!inquote) {
            r.insert(lineStart, '"');
            inquote = true;
          }
          r.append(c);
          break;

        case ' ':
          if (!inquote && r.length() > 0 && r.charAt(r.length() - 1) == ' ') {
            r.insert(lineStart, '"');
            inquote = true;
          }
          r.append(' ');
          break;

        default:
          r.append(c);
          break;
      }
    }
    if (inquote) {
      r.append('"');
    }
    return r.toString();
  }
Example #22
0
  private void updateBackgroundText() {
    // Setup the semitransparent background text
    backgroundText.setCache(false);
    backgroundText.setTextOrigin(VPos.BASELINE);
    backgroundText.setTextAlignment(TextAlignment.RIGHT);

    // Setup the semitransparent background text
    // Width of one segment
    oneSegment.setFont(valueFont);
    dotSegment.setText(".");
    if (LcdFont.LCD == getSkinnable().getLcdFont()) {
      oneSegment.setText("8");
    } else if (LcdFont.DIGITAL == getSkinnable().getLcdFont()) {
      oneSegment.setText("_");
    } else if (LcdFont.DIGITAL_BOLD == getSkinnable().getLcdFont()) {
      oneSegment.setText("_");
    } else if (LcdFont.ELEKTRA == getSkinnable().getLcdFont()) {
      oneSegment.setText("_");
    }
    oneSegmentWidth = oneSegment.getLayoutBounds().getWidth();
    dotSegmentWidth = dotSegment.getLayoutBounds().getWidth();

    // Width of decimals
    widthOfDecimals =
        0 == getSkinnable().getDecimals()
            ? 0
            : getSkinnable().getDecimals() * oneSegmentWidth
                + (LcdFont.LCD == getSkinnable().getLcdFont() ? oneSegmentWidth : dotSegmentWidth);

    // Available width
    availableWidth =
        width
            - (0.0151515152 * width)
            - (0.0416666667 * height)
            - 2
            - valueOffsetRight
            - widthOfDecimals;

    // Number of segments
    noOfSegments = (int) Math.floor(availableWidth / oneSegmentWidth);

    // Add segments to background text
    backgroundTextBuilder.setLength(0);
    for (int i = 0; i < getSkinnable().getDecimals(); i++) {
      backgroundTextBuilder.append(oneSegment.getText());
    }

    if (getSkinnable().getDecimals() != 0) {
      backgroundTextBuilder.insert(0, ".");
    }

    for (int i = 0; i < noOfSegments; i++) {
      backgroundTextBuilder.insert(0, oneSegment.getText());
    }
    backgroundText.setText(backgroundTextBuilder.toString());

    backgroundText.setCache(true);
    backgroundText.setCacheHint(CacheHint.SCALE);
  }
Example #23
0
 public static String prettifyFingerprint(String fingerprint) {
   StringBuilder builder = new StringBuilder(fingerprint);
   builder.insert(8, " ");
   builder.insert(17, " ");
   builder.insert(26, " ");
   builder.insert(35, " ");
   return builder.toString();
 }
Example #24
0
  public String getNick(final boolean longnick) {
    final StringBuilder prefix = new StringBuilder();
    String nickname;
    String suffix = "";
    final String nick = getNickname();
    if (ess.getSettings().isCommandDisabled("nick")
        || nick == null
        || nick.isEmpty()
        || nick.equals(getName())) {
      nickname = getName();
    } else if (nick.equalsIgnoreCase(getName())) {
      nickname = nick;
    } else {
      nickname = ess.getSettings().getNicknamePrefix() + nick;
      suffix = "§r";
    }

    if (this.getBase().isOp()) {
      try {
        final ChatColor opPrefix = ess.getSettings().getOperatorColor();
        if (opPrefix != null && opPrefix.toString().length() > 0) {
          prefix.insert(0, opPrefix.toString());
          suffix = "§r";
        }
      } catch (Exception e) {
      }
    }

    if (ess.getSettings().addPrefixSuffix()) {
      // These two extra toggles are not documented, because they are mostly redundant #EasterEgg
      if (!ess.getSettings().disablePrefix()) {
        final String ptext = ess.getPermissionsHandler().getPrefix(base).replace('&', '§');
        prefix.insert(0, ptext);
        suffix = "§r";
      }
      if (!ess.getSettings().disableSuffix()) {
        final String stext = ess.getPermissionsHandler().getSuffix(base).replace('&', '§');
        suffix = stext + "§r";
        suffix = suffix.replace("§f§f", "§f").replace("§f§r", "§r").replace("§r§r", "§r");
      }
    }
    final String strPrefix = prefix.toString();
    String output = strPrefix + nickname + suffix;
    if (!longnick && output.length() > 16) {
      output = strPrefix + nickname;
    }
    if (!longnick && output.length() > 16) {
      output = FormatUtil.lastCode(strPrefix) + nickname;
    }
    if (!longnick && output.length() > 16) {
      output = FormatUtil.lastCode(strPrefix) + nickname.substring(0, 14);
    }
    if (output.charAt(output.length() - 1) == '§') {
      output = output.substring(0, output.length() - 1);
    }
    return output;
  }
 /**
  *
  *
  * <pre>
  * 生成Oracle分页查询SQL
  * </pre>
  *
  * @author jundong.xu_C
  * @param page
  * @param sql
  * @return
  */
 protected String buildOraclePageSql(Page<?> page, String sql) {
   // 计算第一条记录的位置,Oracle分页是通过rownum进行的,而rownum是从1开始的
   int offset = (page.getPageIndex() - 1) * page.getPageSize() + 1;
   StringBuilder sb = new StringBuilder(sql);
   sb.insert(0, "select u.*, rownum r from (")
       .append(") u where rownum < ")
       .append(offset + page.getPageSize());
   sb.insert(0, "select * from (").append(") where r >= ").append(offset);
   return sb.toString();
 }
Example #26
0
 public String getAbsolutePath() {
   StringBuilder path = new StringBuilder(32);
   TreeNode<T> node = this;
   while (node.getParent() != null) {
     path.insert(0, "/");
     path.insert(0, node.getId());
     node = node.getParent();
   }
   return path.toString();
 }
  public String getCurrentPath() {
    StringBuilder pathBuilder = new StringBuilder();

    for (int i = configStack.size() - 1; i >= 0; i--) {
      pathBuilder.insert(0, "]");
      pathBuilder.insert(0, configStack.get(i).configFile);
      pathBuilder.insert(0, "/[");
    }

    return pathBuilder.toString();
  }
Example #28
0
  public String getPath() {
    StringBuilder sb = new StringBuilder();

    Item w = this;
    while (w != null) {
      sb.insert(0, w.getName());
      sb.insert(0, '/');
      w = ((Item) w.getParent());
    }
    return sb.toString();
  }
Example #29
0
 public String qualifiedName() {
   StringBuilder qualifiedName = new StringBuilder(name());
   for (IType<?, ?, ?, ?, ?, ?> surroundingType = surroundingType();
       surroundingType != null;
       surroundingType = surroundingType.surroundingType()) {
     qualifiedName.insert(0, surroundingType.name() + "$");
   }
   CompilationUnitDeclaration cud = (CompilationUnitDeclaration) node().top().get();
   if (cud.currentPackage != null)
     qualifiedName.insert(0, toQualifiedName(cud.currentPackage.tokens) + ".");
   return qualifiedName.toString();
 }
Example #30
0
 public String getPath() {
   StringBuilder builder = new StringBuilder();
   Node current = node;
   while (current != null && current instanceof Element) {
     if (current != node) {
       builder.insert(0, "/");
     }
     builder.insert(0, current.getNodeName());
     current = current.getParentNode();
   }
   return builder.toString();
 }