Example usage for java.lang StringBuilder reverse

List of usage examples for java.lang StringBuilder reverse

Introduction

In this page you can find the example usage for java.lang StringBuilder reverse.

Prototype

@Override
    public StringBuilder reverse() 

Source Link

Usage

From source file:com.infinities.nova.policy.Rules.java

private static String rstrip(String orig, String strip) {
    char[] origs = orig.toCharArray();
    char[] tokens = strip.toCharArray();
    StringBuilder ret = new StringBuilder();
    boolean isStriped = false;

    for (int i = origs.length - 1; i >= 0; i--) {
        boolean isEquals = false;
        for (int j = 0; j < tokens.length; j++) {
            if (tokens[j] == origs[i]) {
                isEquals = true;//  www. jav a  2s  .  com
            }
        }
        if (isStriped) {
            ret.append(origs[i]);
            continue;
        } else {
            if (isEquals) {
                continue;
            } else {
                isStriped = true;
                ret.append(origs[i]);
            }
        }
    }
    return ret.reverse().toString();
}

From source file:CharSequenceDemo.java

public String toString() {
    StringBuilder s = new StringBuilder(this.s);
    return s.reverse().toString();
}

From source file:CharSequenceDemo.java

public CharSequence subSequence(int start, int end) {
    if (start < 0) {
        throw new StringIndexOutOfBoundsException(start);
    }//from   w ww.  j  av a 2s  .  co  m
    if (end > s.length()) {
        throw new StringIndexOutOfBoundsException(end);
    }
    if (start > end) {
        throw new StringIndexOutOfBoundsException(start - end);
    }
    StringBuilder sub = new StringBuilder(s.subSequence(fromEnd(end), fromEnd(start)));
    return sub.reverse();
}

From source file:eu.ggnet.dwoss.util.ImageFinder.java

public int nextImageId() {
    if (path == null || (!path.exists() && !path.isDirectory()))
        return -1;
    int max = 0;//from ww w . jav a 2s .  c  o m
    for (String name : path.list()) {
        StringBuilder rev = new StringBuilder(name);
        rev.reverse();
        int p = rev.indexOf(".");
        if (p < 0)
            continue;
        rev.delete(0, p + 1);
        p = rev.indexOf("_");
        if (p < 0)
            continue;
        rev.delete(p, rev.length());
        rev.reverse();
        int val = 0;
        try {
            val = Integer.parseInt(rev.toString());
        } catch (NumberFormatException e) {
            continue;
        }
        if (max < val)
            max = val;
    }
    return max + 1;
}

From source file:com.mycompany.HelloWorldTask.java

@Scheduled(fixedRate = 5000)
public void greet() {
    StringBuilder sb = new StringBuilder();
    if (MyFeatures.HELLO_WORLD.isActive()) {
        sb.append(GREETING);/*from   w w w  .  ja  v a  2s  .  co m*/
        if (MyFeatures.REVERSE_GREETING.isActive()) {
            sb.reverse();
        }
    } else {
        sb.append("/dev/null");
    }
    System.out.println(sb.toString());
}

From source file:HSqlPrimerDesign.java

@Deprecated
public static String complementWC(String dna) {
    StringBuilder builder = new StringBuilder();
    for (int i = 0; i < dna.length(); i++) {
        char c = dna.charAt(i);
        if (c == 'T') {
            builder.append('A');
        }//from w  w w  . j  a v a2s  .c o m
        if (c == 'A') {
            builder.append('T');
        }
        if (c == 'C') {
            builder.append('G');
        }
        if (c == 'G') {
            builder.append('T');
        }
    }
    return builder.reverse().toString();
}

From source file:com.givon.baseproject.xinlu.act.ActRegist.java

protected String splitPhoneNum(String phone) {
    StringBuilder builder = new StringBuilder(phone);
    builder.reverse();
    for (int i = 4, len = builder.length(); i < len; i += 5) {
        builder.insert(i, ' ');
    }// www .jav  a2 s .c  o  m
    builder.reverse();
    return builder.toString();
}

From source file:org.folg.places.tools.AnalyzePlaces.java

private void doMain() throws SAXParseException, IOException {

    Normalizer normalizer = null;
    if (useTokenizer) {
        normalizer = Normalizer.getInstance();
    }/*w w  w. ja v a2  s  .  c  o  m*/

    PrintWriter reversedWordsWriter = analysisPlacesOut != null
            ? new PrintWriter(new File(analysisPlacesOut, "reversedWords.txt"))
            : new PrintWriter(System.out);

    BufferedReader bufferedReader = new BufferedReader(new FileReader(placesIn));

    int lineCount = 0;
    while (bufferedReader.ready()) {
        String nextLine = bufferedReader.readLine();
        nextLine = nextLine.trim().toLowerCase();
        if (nextLine.length() == 0)
            continue;

        lineCount++;
        if (lineCount % 5000 == 0)
            System.out.println("indexing line " + lineCount);

        placesCountCC.add(nextLine);
        totalPlacesCount++;

        String[] placeList = nextLine.split(SPLIT_REGEX);

        for (String place : placeList) {
            place = place.trim();

            if (place.length() == 0)
                continue;

            if (NumberUtils.isNumber(place)) {
                numbersCountCC.add(place);
                totalNumbersCount++;
            } else {
                wordsCountCC.add(place);
                totalWordsCount++;
            }
        }

        int lastCommaIndx = nextLine.lastIndexOf(",");
        String lastWord = nextLine.substring(lastCommaIndx + 1).trim();
        if (lastWord.length() > 0) {
            endingsOfPlacesCC.add(lastWord);
            endingsOfPlacesTotalCount++;
        }

        if (lineCount % REVERSE_EVERY_N == 0) {
            StringBuilder reversedWord = new StringBuilder(nextLine);
            reversedWordsWriter.println(reversedWord.reverse());
        }

        if ((useTokenizer) && (lineCount % TOKENIZE_EVERY_N == 0)) {
            List<List<String>> levels = normalizer.tokenize(nextLine);
            for (List<String> levelWords : levels) {
                tokenizerPlacesCountCC.addAll(levelWords);
                totalTokenizerPlacesCount += levelWords.size();
            }
        }
    }

    System.out.println("total number of lines in files " + lineCount);

    System.out.println("Indexed a total of " + totalPlacesCount + " places.");
    System.out.println("Found a total of " + getPlacesCountCC().size() + " unique places.");
    getPlacesCountCC().writeSorted(false, 1,
            analysisPlacesOut != null ? new PrintWriter(new File(analysisPlacesOut, "placesCount.txt"))
                    : new PrintWriter(System.out));

    System.out.println("Indexed a total of " + totalWordsCount + " words.");
    System.out.println("Found a total of " + getWordsCountCC().size() + " unique words.");
    getWordsCountCC().writeSorted(false, 1,
            analysisPlacesOut != null ? new PrintWriter(new File(analysisPlacesOut, "wordsCount.txt"))
                    : new PrintWriter(System.out));

    System.out.println("Indexed a total of " + totalNumbersCount + " numbers.");
    System.out.println("Found a total of " + getNumbersCountCC().size() + " unique numbers.");
    getNumbersCountCC().writeSorted(false, 1,
            analysisPlacesOut != null ? new PrintWriter(new File(analysisPlacesOut, "numbersCount.txt"))
                    : new PrintWriter(System.out));

    System.out.println("Indexed a total of " + endingsOfPlacesTotalCount + " endings.");
    System.out.println("Found a total of " + getEndingsOfPlacesCC().size() + " unique endings.");
    getEndingsOfPlacesCC().writeSorted(false, 1,
            analysisPlacesOut != null ? new PrintWriter(new File(analysisPlacesOut, "endingsCount.txt"))
                    : new PrintWriter(System.out));

    if (useTokenizer) {
        System.out.println("Indexed a total of " + totalTokenizerPlacesCount + " normalized words.");
        System.out.println("Found a total of " + getTokenizerPlacesCountCC().size() + " normalized words.");
        getTokenizerPlacesCountCC().writeSorted(false, 1,
                analysisPlacesOut != null
                        ? new PrintWriter(new File(analysisPlacesOut, "normalizedWordsCount.txt"))
                        : new PrintWriter(System.out));
    }

}

From source file:apm.common.utils.PrettyTimeUtils.java

/**
 * ****** ******  123 10?//from ww  w  . ja va2 s .c  o m
 *
 * @return
 */
public static final String prettySeconds(int totalSeconds) {
    StringBuilder s = new StringBuilder();
    int second = totalSeconds % 60;
    if (totalSeconds > 0) {
        s.append("");
        s.append(StringUtils.reverse(String.valueOf(second)));
    }

    totalSeconds = totalSeconds / 60;
    int minute = totalSeconds % 60;
    if (totalSeconds > 0) {
        s.append("");
        s.append(StringUtils.reverse(String.valueOf(minute)));
    }

    totalSeconds = totalSeconds / 60;
    int hour = totalSeconds % 24;
    if (totalSeconds > 0) {
        s.append(StringUtils.reverse("?"));
        s.append(StringUtils.reverse(String.valueOf(hour)));
    }

    totalSeconds = totalSeconds / 24;
    int day = totalSeconds % 31;
    if (totalSeconds > 0) {
        s.append("");
        s.append(StringUtils.reverse(String.valueOf(day)));
    }

    totalSeconds = totalSeconds / 31;
    int month = totalSeconds % 12;
    if (totalSeconds > 0) {
        s.append("");
        s.append(StringUtils.reverse(String.valueOf(month)));
    }

    totalSeconds = totalSeconds / 12;
    int year = totalSeconds;
    if (totalSeconds > 0) {
        s.append("");
        s.append(StringUtils.reverse(String.valueOf(year)));
    }
    return s.reverse().toString();
}

From source file:org.asoem.greyfish.utils.collect.AbstractBitStringImplementationTest.java

@Test
public void testGet() throws Exception {
    // given/*from w w w . ja  v  a2 s  .c  o m*/
    final String bitString = "001010010";
    final BitString sequence1 = createSequence(bitString);

    // when
    final StringBuilder stringBuilder = new StringBuilder();
    for (int i = 0; i < sequence1.size(); i++) {
        stringBuilder.append(sequence1.get(i) ? '1' : '0');
    }

    // then
    assertThat(stringBuilder.reverse().toString(), is(equalTo(bitString)));
}