Search in sources :

Example 11 with StringTokenizer

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

the class StringGroovyMethods method split.

/**
     * Convenience method to split a CharSequence (with whitespace as delimiter).
     * Similar to tokenize, but returns an Array of String instead of a List.
     *
     * @param self the CharSequence to split
     * @return String[] result of split
     * @see #split(String)
     * @since 1.8.2
     */
public static String[] split(CharSequence self) {
    StringTokenizer st = new StringTokenizer(self.toString());
    String[] strings = new String[st.countTokens()];
    for (int i = 0; i < strings.length; i++) {
        strings[i] = st.nextToken();
    }
    return strings;
}
Also used : StringTokenizer(java.util.StringTokenizer) FromString(groovy.transform.stc.FromString) GString(groovy.lang.GString)

Example 12 with StringTokenizer

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

the class TestGetConf method getAddressListFromTool.

/**
   * Using {@link GetConf} methods get the list of given {@code type} of
   * addresses
   * 
   * @param type, TestType
   * @param conf, configuration
   * @param checkPort, If checkPort is true, verify NNPRCADDRESSES whose 
   *      expected value is hostname:rpc-port.  If checkPort is false, the 
   *      expected is hostname only.
   * @param expected, expected addresses
   */
private void getAddressListFromTool(TestType type, HdfsConfiguration conf, boolean checkPort, List<ConfiguredNNAddress> expected) throws Exception {
    String out = getAddressListFromTool(type, conf, expected.size() != 0);
    List<String> values = new ArrayList<String>();
    // Convert list of addresses returned to an array of string
    StringTokenizer tokenizer = new StringTokenizer(out);
    while (tokenizer.hasMoreTokens()) {
        String s = tokenizer.nextToken().trim();
        values.add(s);
    }
    String[] actual = values.toArray(new String[values.size()]);
    // Convert expected list to String[] of hosts
    int i = 0;
    String[] expectedHosts = new String[expected.size()];
    for (ConfiguredNNAddress cnn : expected) {
        InetSocketAddress addr = cnn.getAddress();
        if (!checkPort) {
            expectedHosts[i++] = addr.getHostName();
        } else {
            expectedHosts[i++] = addr.getHostName() + ":" + addr.getPort();
        }
    }
    // Compare two arrays
    assertTrue(Arrays.equals(expectedHosts, actual));
}
Also used : StringTokenizer(java.util.StringTokenizer) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) ConfiguredNNAddress(org.apache.hadoop.hdfs.DFSUtil.ConfiguredNNAddress)

Example 13 with StringTokenizer

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

the class WebHdfsFileSystem method removeOffsetParam.

/** Remove offset parameter, if there is any, from the url */
static URL removeOffsetParam(final URL url) throws MalformedURLException {
    String query = url.getQuery();
    if (query == null) {
        return url;
    }
    final String lower = StringUtils.toLowerCase(query);
    if (!lower.startsWith(OFFSET_PARAM_PREFIX) && !lower.contains("&" + OFFSET_PARAM_PREFIX)) {
        return url;
    }
    //rebuild query
    StringBuilder b = null;
    for (final StringTokenizer st = new StringTokenizer(query, "&"); st.hasMoreTokens(); ) {
        final String token = st.nextToken();
        if (!StringUtils.toLowerCase(token).startsWith(OFFSET_PARAM_PREFIX)) {
            if (b == null) {
                b = new StringBuilder("?").append(token);
            } else {
                b.append('&').append(token);
            }
        }
    }
    query = b == null ? "" : b.toString();
    final String urlStr = url.toString();
    return new URL(urlStr.substring(0, urlStr.indexOf('?')) + query);
}
Also used : StringTokenizer(java.util.StringTokenizer) URL(java.net.URL)

Example 14 with StringTokenizer

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

the class KeyFieldHelper method parseOption.

public void parseOption(String option) {
    if (option == null || option.equals("")) {
        //we will have only default comparison
        return;
    }
    StringTokenizer args = new StringTokenizer(option);
    KeyDescription global = new KeyDescription();
    while (args.hasMoreTokens()) {
        String arg = args.nextToken();
        if (arg.equals("-n")) {
            global.numeric = true;
        }
        if (arg.equals("-r")) {
            global.reverse = true;
        }
        if (arg.equals("-nr")) {
            global.numeric = true;
            global.reverse = true;
        }
        if (arg.startsWith("-k")) {
            KeyDescription k = parseKey(arg, args);
            if (k != null) {
                allKeySpecs.add(k);
                keySpecSeen = true;
            }
        }
    }
    for (KeyDescription key : allKeySpecs) {
        if (!(key.reverse | key.numeric)) {
            key.reverse = global.reverse;
            key.numeric = global.numeric;
        }
    }
    if (allKeySpecs.size() == 0) {
        allKeySpecs.add(global);
    }
}
Also used : StringTokenizer(java.util.StringTokenizer)

Example 15 with StringTokenizer

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

the class KeyFieldHelper method parseKey.

private KeyDescription parseKey(String arg, StringTokenizer args) {
    //we allow for -k<arg> and -k <arg>
    String keyArgs = null;
    if (arg.length() == 2) {
        if (args.hasMoreTokens()) {
            keyArgs = args.nextToken();
        }
    } else {
        keyArgs = arg.substring(2);
    }
    if (keyArgs == null || keyArgs.length() == 0) {
        return null;
    }
    StringTokenizer st = new StringTokenizer(keyArgs, "nr.,", true);
    KeyDescription key = new KeyDescription();
    String token;
    //the key is of the form 1[.3][nr][,1.5][nr]
    if (st.hasMoreTokens()) {
        token = st.nextToken();
        //the first token must be a number
        key.beginFieldIdx = Integer.parseInt(token);
    }
    if (st.hasMoreTokens()) {
        token = st.nextToken();
        if (token.equals(".")) {
            token = st.nextToken();
            key.beginChar = Integer.parseInt(token);
            if (st.hasMoreTokens()) {
                token = st.nextToken();
            } else {
                return key;
            }
        }
        do {
            if (token.equals("n")) {
                key.numeric = true;
            } else if (token.equals("r")) {
                key.reverse = true;
            } else
                break;
            if (st.hasMoreTokens()) {
                token = st.nextToken();
            } else {
                return key;
            }
        } while (true);
        if (token.equals(",")) {
            token = st.nextToken();
            //the first token must be a number
            key.endFieldIdx = Integer.parseInt(token);
            if (st.hasMoreTokens()) {
                token = st.nextToken();
                if (token.equals(".")) {
                    token = st.nextToken();
                    key.endChar = Integer.parseInt(token);
                    if (st.hasMoreTokens()) {
                        token = st.nextToken();
                    } else {
                        return key;
                    }
                }
                do {
                    if (token.equals("n")) {
                        key.numeric = true;
                    } else if (token.equals("r")) {
                        key.reverse = true;
                    } else {
                        throw new IllegalArgumentException("Invalid -k argument. " + "Must be of the form -k pos1,[pos2], where pos is of the form " + "f[.c]nr");
                    }
                    if (st.hasMoreTokens()) {
                        token = st.nextToken();
                    } else {
                        break;
                    }
                } while (true);
            }
            return key;
        }
        throw new IllegalArgumentException("Invalid -k argument. " + "Must be of the form -k pos1,[pos2], where pos is of the form " + "f[.c]nr");
    }
    return key;
}
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