protected TokenIterator createTokenIterator(String pString) { return new StringTokenIterator(pString); }
StringTokenIterator tokens = new StringTokenIterator(last, " ", StringTokenIterator.REVERSE); int count = 0; while (count < pIndex && tokens.hasNext()) { blocks = tokens.nextToken(); count++;
private String fetchNext() { // If next is delimiter, return fast if (nextDelimiter != null) { next = nextDelimiter; nextDelimiter = null; return next; } // If no more chars, return null if (position >= maxPosition) { return null; } return reverse ? fetchReverse() : fetchForward(); }
/** * Returns the next element in the iteration. * * @return the next element in the iteration. * @exception java.util.NoSuchElementException iteration has no more elements. */ public String next() { if (!hasNext()) { throw new NoSuchElementException(); } String next = this.next; this.next = fetchNext(); return next; }
@Override public int read() throws IOException { // Each number is one byte. Skip whitespace. if (currentLine == null || !currentLine.hasNext()) { String line = reader.readLine(); if (line == null) { return -1; } currentLine = new StringTokenIterator(line); if (!currentLine.hasNext()) { return -1; } } return Integer.parseInt(currentLine.next()) & 0xff; }
/** * Converts a delimiter separated String to an array of Strings. * * @param pString The comma-separated string * @param pDelimiters The delimiter string * @return a {@code String} array containing the delimiter separated elements */ public static String[] toStringArray(String pString, String pDelimiters) { if (isEmpty(pString)) { return new String[0]; } StringTokenIterator st = new StringTokenIterator(pString, pDelimiters); List<String> v = new ArrayList<String>(); while (st.hasMoreElements()) { v.add(st.nextToken()); } return v.toArray(new String[v.size()]); }
private String fetchReverse() { // Get previous position int prevPos = scanForPrev(); // Store next string next = string.substring(prevPos + 1, maxPosition - position); if (includeDelimiters && prevPos >= 0 && prevPos < maxPosition) { nextDelimiter = string.substring(prevPos, prevPos + 1); } position = maxPosition - prevPos; // Skip empty if (next.length() == 0 && !includeEmpty) { return fetchNext(); } return next; }
private String fetchForward() { // Get next position int nextPos = scanForNext(); // Store next string next = string.substring(position, nextPos); if (includeDelimiters && nextPos >= 0 && nextPos < maxPosition) { nextDelimiter = string.substring(nextPos, nextPos + 1); } position = ++nextPos; // Skip empty if (next.length() == 0 && !includeEmpty) { return fetchNext(); } return next; }
/** * Implementation. * * @param pString the string to be parsed. * @param pDelimiters the delimiters. * @param pDirection iteration direction. * @param pIncludeDelimiters flag indicating whether to return delimiters as tokens. * @param pIncludeEmpty flag indicating whether to return empty tokens */ private StringTokenIterator(String pString, char[] pDelimiters, int pDirection, boolean pIncludeDelimiters, boolean pIncludeEmpty) { if (pString == null) { throw new IllegalArgumentException("string == null"); } string = pString; maxPosition = pString.length(); delimiters = pDelimiters; includeDelimiters = pIncludeDelimiters; reverse = (pDirection == REVERSE); includeEmpty = pIncludeEmpty; maxDelimiter = initMaxDelimiter(pDelimiters); reset(); }
/** * Returns {@code true} if the iteration has more elements. (In other * words, returns {@code true} if {@code next} would return an element * rather than throwing an exception.) * * @return {@code true} if the iterator has more elements. */ public boolean hasNext() { return (next != null || fetchNext() != null); }
/** * Converts a delimiter separated String to an array of Strings. * * @param pString The comma-separated string * @param pDelimiters The delimiter string * @return a {@code String} array containing the delimiter separated elements */ public static String[] toStringArray(String pString, String pDelimiters) { if (isEmpty(pString)) { return new String[0]; } StringTokenIterator st = new StringTokenIterator(pString, pDelimiters); List<String> v = new ArrayList<String>(); while (st.hasMoreElements()) { v.add(st.nextToken()); } return v.toArray(new String[v.size()]); }
@Override public int read() throws IOException { if (leftOver != -1) { int next = leftOver; leftOver = -1; return next; } // Each number is one byte. Skip whitespace. if (currentLine == null || !currentLine.hasNext()) { String line = reader.readLine(); if (line == null) { return -1; } currentLine = new StringTokenIterator(line); if (!currentLine.hasNext()) { return -1; } } int next = Integer.parseInt(currentLine.next()) & 0xffff; leftOver = next & 0xff; return (next >> 8) & 0xff; }
/** * Returns the next element in the iteration. * * @return the next element in the iteration. * @exception java.util.NoSuchElementException iteration has no more elements. */ public String next() { if (!hasNext()) { throw new NoSuchElementException(); } String next = this.next; this.next = fetchNext(); return next; }
private String fetchReverse() { // Get previous position int prevPos = scanForPrev(); // Store next string next = string.substring(prevPos + 1, maxPosition - position); if (includeDelimiters && prevPos >= 0 && prevPos < maxPosition) { nextDelimiter = string.substring(prevPos, prevPos + 1); } position = maxPosition - prevPos; // Skip empty if (next.length() == 0 && !includeEmpty) { return fetchNext(); } return next; }
private String fetchForward() { // Get next position int nextPos = scanForNext(); // Store next string next = string.substring(position, nextPos); if (includeDelimiters && nextPos >= 0 && nextPos < maxPosition) { nextDelimiter = string.substring(nextPos, nextPos + 1); } position = ++nextPos; // Skip empty if (next.length() == 0 && !includeEmpty) { return fetchNext(); } return next; }
/** * Implementation. * * @param pString the string to be parsed. * @param pDelimiters the delimiters. * @param pDirection iteration direction. * @param pIncludeDelimiters flag indicating whether to return delimiters as tokens. * @param pIncludeEmpty flag indicating whether to return empty tokens */ private StringTokenIterator(String pString, char[] pDelimiters, int pDirection, boolean pIncludeDelimiters, boolean pIncludeEmpty) { if (pString == null) { throw new IllegalArgumentException("string == null"); } string = pString; maxPosition = pString.length(); delimiters = pDelimiters; includeDelimiters = pIncludeDelimiters; reverse = (pDirection == REVERSE); includeEmpty = pIncludeEmpty; maxDelimiter = initMaxDelimiter(pDelimiters); reset(); }
/** * Returns {@code true} if the iteration has more elements. (In other * words, returns {@code true} if {@code next} would return an element * rather than throwing an exception.) * * @return {@code true} if the iterator has more elements. */ public boolean hasNext() { return (next != null || fetchNext() != null); }
protected TokenIterator createTokenIterator(String pString, String pDelimiters) { return new StringTokenIterator(pString, pDelimiters); }
StringTokenIterator tokens = new StringTokenIterator(last, " ", StringTokenIterator.REVERSE); int count = 0; while (count < pIndex && tokens.hasNext()) { blocks = tokens.nextToken(); count++;
/** * Converts a delimiter separated String to an array of Strings. * * @param pString The comma-separated string * @param pDelimiters The delimiter string * @return a {@code String} array containing the delimiter separated elements */ public static String[] toStringArray(String pString, String pDelimiters) { if (isEmpty(pString)) { return new String[0]; } StringTokenIterator st = new StringTokenIterator(pString, pDelimiters); List<String> v = new ArrayList<String>(); while (st.hasMoreElements()) { v.add(st.nextToken()); } return v.toArray(new String[v.size()]); }