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;
}
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;
}
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();
}
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();
}
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();
}
Aggregations