Search in sources :

Example 26 with StringTokenizer

use of java.util.StringTokenizer in project hadoop by apache.

the class TestProportionalCapacityPreemptionPolicy method mockPreemptionStatus.

// Determine if any of the elements in the queupath have preemption disabled.
// Also must handle the case where preemption disabled property is explicitly
// set to something other than the default. Assumes system-wide preemption
// property is true.
private boolean mockPreemptionStatus(String queuePathName) {
    boolean preemptionDisabled = false;
    StringTokenizer tokenizer = new StringTokenizer(queuePathName, ".");
    String qName = "";
    while (tokenizer.hasMoreTokens()) {
        qName += tokenizer.nextToken();
        preemptionDisabled = conf.getPreemptionDisabled(qName, preemptionDisabled);
        qName += ".";
    }
    return preemptionDisabled;
}
Also used : StringTokenizer(java.util.StringTokenizer) Matchers.anyString(org.mockito.Matchers.anyString)

Example 27 with StringTokenizer

use of java.util.StringTokenizer in project hive by apache.

the class HttpAuthUtils method splitCookieToken.

/**
   * Splits the cookie token into attributes pairs.
   * @param str input token.
   * @return a map with the attribute pairs of the token if the input is valid.
   * Else, returns null.
   */
private static Map<String, String> splitCookieToken(String tokenStr) {
    Map<String, String> map = new HashMap<String, String>();
    StringTokenizer st = new StringTokenizer(tokenStr, COOKIE_ATTR_SEPARATOR);
    while (st.hasMoreTokens()) {
        String part = st.nextToken();
        int separator = part.indexOf(COOKIE_KEY_VALUE_SEPARATOR);
        if (separator == -1) {
            LOG.error("Invalid token string " + tokenStr);
            return null;
        }
        String key = part.substring(0, separator);
        String value = part.substring(separator + 1);
        map.put(key, value);
    }
    return map;
}
Also used : StringTokenizer(java.util.StringTokenizer) HashMap(java.util.HashMap)

Example 28 with StringTokenizer

use of java.util.StringTokenizer in project hive by apache.

the class TestVectorStringExpressions method generateCandidate.

private String generateCandidate(Random control, String pattern) {
    StringBuffer sb = new StringBuffer();
    final StringTokenizer tokens = new StringTokenizer(pattern, "%");
    final boolean leftAnchor = pattern.startsWith("%");
    final boolean rightAnchor = pattern.endsWith("%");
    for (int i = 0; tokens.hasMoreTokens(); i++) {
        String chunk = tokens.nextToken();
        if (leftAnchor && i == 0) {
            // first item
            sb.append(randomizePattern(control, chunk));
        } else if (rightAnchor && tokens.hasMoreTokens() == false) {
            // last item
            sb.append(randomizePattern(control, chunk));
        } else {
            // middle item
            sb.append(randomizePattern(control, chunk));
        }
    }
    return sb.toString();
}
Also used : StringTokenizer(java.util.StringTokenizer)

Example 29 with StringTokenizer

use of java.util.StringTokenizer in project hive by apache.

the class BeeLine method wrap.

/**
   * Wrap the specified string by breaking on space characters.
   *
   * @param toWrap
   *          the string to wrap
   * @param len
   *          the maximum length of any line
   * @param start
   *          the number of spaces to pad at the
   *          beginning of a line
   * @return the wrapped string
   */
String wrap(String toWrap, int len, int start) {
    StringBuilder buff = new StringBuilder();
    StringBuilder line = new StringBuilder();
    char[] head = new char[start];
    Arrays.fill(head, ' ');
    for (StringTokenizer tok = new StringTokenizer(toWrap, " "); tok.hasMoreTokens(); ) {
        String next = tok.nextToken();
        if (line.length() + next.length() > len) {
            buff.append(line).append(separator).append(head);
            line.setLength(0);
        }
        line.append(line.length() == 0 ? "" : " ").append(next);
    }
    buff.append(line);
    return buff.toString();
}
Also used : StringTokenizer(java.util.StringTokenizer)

Example 30 with StringTokenizer

use of java.util.StringTokenizer in project hive by apache.

the class MetaDataPrettyFormatUtils method breakCommentIntoMultipleLines.

/**
   * If the specified comment is too long, add line breaks at appropriate
   * locations.  Note that the comment may already include line-breaks
   * specified by the user at table creation time.
   * @param columnsAlreadyConsumed The number of columns on the current line
   * that have already been consumed by the column name, column type and
   * and the surrounding delimiters.
   * @return The comment with line breaks added at appropriate locations.
   */
private static String breakCommentIntoMultipleLines(String comment, int columnsAlreadyConsumed, int prettyOutputNumCols) {
    if (prettyOutputNumCols == -1) {
        // XXX fixed to 80 to remove jline dep
        prettyOutputNumCols = 80 - 1;
    }
    int commentNumCols = prettyOutputNumCols - columnsAlreadyConsumed;
    if (commentNumCols < MIN_COMMENT_COLUMN_LEN) {
        commentNumCols = MIN_COMMENT_COLUMN_LEN;
    }
    // Track the number of columns allocated for the comment that have
    // already been consumed on the current line.
    int commentNumColsConsumed = 0;
    StringTokenizer st = new StringTokenizer(comment, " \t\n\r\f", true);
    // We use a StringTokenizer instead of a BreakIterator, because
    // table comments often contain text that looks like code. For eg:
    // 'Type0' => 0, // This is Type 0
    // 'Type1' => 1, // This is Type 1
    // BreakIterator is meant for regular text, and was found to give
    // bad line breaks when we tried it out.
    StringBuilder commentBuilder = new StringBuilder(comment.length());
    while (st.hasMoreTokens()) {
        String currWord = st.nextToken();
        if (currWord.equals("\n") || currWord.equals("\r") || currWord.equals("\f")) {
            commentBuilder.append(currWord);
            commentNumColsConsumed = 0;
            continue;
        }
        if (commentNumColsConsumed + currWord.length() > commentNumCols) {
            // currWord won't fit on the current line
            if (currWord.length() > commentNumCols) {
                // may be smaller.
                while (currWord.length() > commentNumCols) {
                    int remainingLineLen = commentNumCols - commentNumColsConsumed;
                    String wordChunk = currWord.substring(0, remainingLineLen);
                    commentBuilder.append(wordChunk);
                    commentBuilder.append(MetaDataFormatUtils.LINE_DELIM);
                    commentNumColsConsumed = 0;
                    currWord = currWord.substring(remainingLineLen);
                }
                // Handle the last chunk
                if (currWord.length() > 0) {
                    commentBuilder.append(currWord);
                    commentNumColsConsumed = currWord.length();
                }
            } else {
                // Start on a new line
                commentBuilder.append(MetaDataFormatUtils.LINE_DELIM);
                if (!currWord.equals(" ")) {
                    // When starting a new line, do not start with a space.
                    commentBuilder.append(currWord);
                    commentNumColsConsumed = currWord.length();
                } else {
                    commentNumColsConsumed = 0;
                }
            }
        } else {
            commentBuilder.append(currWord);
            commentNumColsConsumed += currWord.length();
        }
    }
    return commentBuilder.toString();
}
Also used : StringTokenizer(java.util.StringTokenizer)

Aggregations

StringTokenizer (java.util.StringTokenizer)2182 ArrayList (java.util.ArrayList)430 IOException (java.io.IOException)219 HashSet (java.util.HashSet)137 HashMap (java.util.HashMap)135 File (java.io.File)108 Map (java.util.Map)92 Set (java.util.Set)88 BufferedReader (java.io.BufferedReader)87 Iterator (java.util.Iterator)80 ParseResult (pcgen.rules.persistence.token.ParseResult)68 List (java.util.List)65 InputStreamReader (java.io.InputStreamReader)50 URL (java.net.URL)48 NoSuchElementException (java.util.NoSuchElementException)43 FileReader (java.io.FileReader)40 CDOMReference (pcgen.cdom.base.CDOMReference)40 Vector (java.util.Vector)39 Properties (java.util.Properties)36 Prerequisite (pcgen.core.prereq.Prerequisite)36