Example usage for java.lang String split

List of usage examples for java.lang String split

Introduction

In this page you can find the example usage for java.lang String split.

Prototype

public String[] split(String regex) 

Source Link

Document

Splits this string around matches of the given regular expression.

Usage

From source file:com.github.zerkseez.codegen.wrappergenerator.Main.java

public static void main(final String[] args) throws Exception {
    final Options options = new Options();
    options.addOption(Option.builder().longOpt("outputDirectory").hasArg().required().build());
    options.addOption(Option.builder().longOpt("classMappings").hasArgs().required().build());

    final CommandLineParser parser = new DefaultParser();

    try {/*from ww  w .  j  ava  2  s.  co m*/
        final CommandLine line = parser.parse(options, args);
        final String outputDirectory = line.getOptionValue("outputDirectory");
        final String[] classMappings = line.getOptionValues("classMappings");
        for (String classMapping : classMappings) {
            final String[] tokens = classMapping.split(":");
            if (tokens.length != 2) {
                throw new IllegalArgumentException(
                        String.format("Invalid class mapping format \"%s\"", classMapping));
            }
            final Class<?> wrappeeClass = Class.forName(tokens[0]);
            final String fullWrapperClassName = tokens[1];
            final int indexOfLastDot = fullWrapperClassName.lastIndexOf('.');
            final String wrapperPackageName = (indexOfLastDot == -1) ? ""
                    : fullWrapperClassName.substring(0, indexOfLastDot);
            final String simpleWrapperClassName = (indexOfLastDot == -1) ? fullWrapperClassName
                    : fullWrapperClassName.substring(indexOfLastDot + 1);

            System.out.println(String.format("Generating wrapper class for %s...", wrappeeClass));
            final WrapperGenerator generator = new WrapperGenerator(wrappeeClass, wrapperPackageName,
                    simpleWrapperClassName);
            generator.writeTo(outputDirectory, true);
        }
        System.out.println("Done");
    } catch (MissingOptionException e) {
        final HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(String.format("java -cp CLASSPATH %s", Main.class.getName()), options);
    }
}

From source file:org.zht.framework.filter.UserAccessLogFilter.java

public static void main(String[] sd) {
    String sds = "aaa;bbb" + "ccc,";
    String[] asdsads = sds.split("");
    for (String ssss : asdsads) {
        System.out.println(ssss);
    }/*from w w w  .  j av  a2 s  .  c  o  m*/
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String bubba = "this is a test this is a test";
    Map<Integer, Integer> occurrences = new HashMap<Integer, Integer>();

    for (String currentWord : bubba.split(" ")) {
        Integer current = occurrences.get(currentWord.length());
        if (current == null) {
            current = 0;//w ww .  ja v a  2s .  c  om
        }
        occurrences.put(currentWord.length(), current + 1);
    }
    for (Integer currentKey : occurrences.keySet()) {
        System.out.println("There are " + occurrences.get(currentKey) + " " + currentKey + " letter words");
    }
}

From source file:edu.oregonstate.eecs.mcplan.domains.yahtzee2.YahtzeeClient.java

/**
 * @param args// w  ww  . ja v a2  s .com
 * @throws IOException
 */
public static void main(final String[] args) throws IOException {
    final RandomGenerator rng = new MersenneTwister(42);
    final YahtzeeState s0 = new YahtzeeState(rng);
    final YahtzeeSimulator sim = new YahtzeeSimulator(rng, s0);

    final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    while (!sim.state().isTerminal()) {
        printState(sim.state());
        final String cmd = reader.readLine();
        final String[] parts = cmd.split(" ");
        if ("keep".equals(parts[0])) {
            final int[] keepers = new int[Hand.Nfaces];
            for (int i = 1; i < parts.length; ++i) {
                final int v = Integer.parseInt(parts[i]);
                keepers[v - 1] += 1;
            }
            sim.takeAction(new JointAction<YahtzeeAction>(new KeepAction(keepers)));
        } else if ("score".equals(parts[0])) {
            final YahtzeeScores category = YahtzeeScores.valueOf(parts[1]);
            sim.takeAction(new JointAction<YahtzeeAction>(new ScoreAction(category)));
        } else if ("undo".equals(parts[0])) {
            sim.untakeLastAction();
        } else {
            System.out.println("!!! Bad command");
        }
    }
    System.out.println("********** Terminal **********");
    printState(sim.state());
}

From source file:de.tudarmstadt.ukp.experiments.argumentation.clustering.entropy.MatrixExperiments.java

public static void main(String[] args) throws Exception {
    File in = new File(args[0]);

    List<String> lines = IOUtils.readLines(new FileInputStream(in));

    int rows = lines.size();
    int cols = lines.iterator().next().split("\\s+").length;

    double[][] matrix = new double[rows][cols];

    Map<Integer, Double> clusterEntropy = new HashMap<>();

    for (int i = 0; i < rows; i++) {
        String line = lines.get(i);

        String[] split = line.split("\\s+");

        for (int j = 0; j < split.length; j++) {
            Double value = Double.valueOf(split[j]);

            matrix[i][j] = value;//w ww .j a v  a2s  . c  o m
        }

        // entropy of the cluster
        Vector v = new DenseVector(matrix[i]);
        //            System.out.print(VectorUtils.entropy(v));
        double entropy = VectorUtils.entropy(VectorUtils.normalize(v));
        System.out.print(entropy);
        System.out.print(" ");

        clusterEntropy.put(i, entropy);
    }

    Map<Integer, Double> sorted = sortByValue(clusterEntropy);
    System.out.println(sorted);

    HeatChart map = new HeatChart(matrix);

    // Step 2: Customise the chart.
    map.setTitle("This is my heat chart title");
    map.setXAxisLabel("X Axis");
    map.setYAxisLabel("Y Axis");

    // Step 3: Output the chart to a file.
    map.saveToFile(new File("/tmp/java-heat-chart.png"));

}

From source file:com.intuit.tank.agent.AgentStartup.java

public static void main(String[] args) {
    AgentStartup agentStartup = new AgentStartup();

    for (int iter = 0; iter < args.length; ++iter) {
        String argument = args[iter];
        String[] values = argument.split("=");

        if (values[0].equalsIgnoreCase("-controller")) {
            if (values.length < 2) {
                usage();// w  w  w  .  ja  v a 2s . c  om
                return;
            }
            agentStartup.controllerBase = values[1];
            continue;
        }

    }
    agentStartup.run();
}

From source file:com.di.bi.nextgen.installattribution.searchcountrycode.SearchCountryCode.java

public static void main(String[] args) throws Exception {
    Map<String, String> map = CSVReader();
    List<String> miss = new ArrayList<>();
    List<String[]> data = new ArrayList<>();
    String csv = "infinity.csv";
    CSVWriter writer = new CSVWriter(new FileWriter(csv));
    List<String[]> outList = new ArrayList<>();
    JSONArray arry = ReadJson();/* w ww .jav  a2  s .co  m*/
    for (String key : map.keySet()) {
        String[] arr = key.split(";");
        boolean isf = false;
        for (int i = 0; i < arry.length(); ++i) {
            JSONObject o = arry.getJSONObject(i);
            if (arr.length > 1) {
                if (o.keySet().contains(arr[1].toUpperCase())) {
                    System.out.println("arr[]1" + arr[1]);
                    System.out.println("o.keySet() " + o.keySet());
                    System.out.println(" bu " + o.keySet().contains(arr[1].toUpperCase()));
                    JSONArray arryC = o.getJSONArray(arr[1].toUpperCase());
                    for (int j = 0; j < arryC.length(); ++j) {
                        String[] tmp = { map.get(key) + "," + key + ";" + arryC.getString(j) };
                        outList.add(tmp);
                    }
                    isf = true;
                    break;
                }
            }
        }
        if (!isf) {
            miss.add(key);
            isf = false;
        }
    }
    writer.writeAll(outList);
    writer.close();
    System.out.println("Miissing" + miss);

}

From source file:com.google.flightmap.parsing.faa.nasr.tools.RecordClassMaker.java

public static void main(String[] args) {
    try {/*  ww w.  ja  v  a2  s  .  co  m*/
        final BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        final String name = in.readLine();
        final List<RecordEntry> entries = new LinkedList<RecordEntry>();
        String line;
        while ((line = in.readLine()) != null) {
            final String[] parts = line.split("\\s+");
            final int length = Integer.parseInt(parts[0]);
            final int start = Integer.parseInt(parts[1]);
            final String entryName = parts[2];
            entries.add(new RecordEntry(length, start, entryName));
        }
        (new RecordClassMaker(name, entries)).execute();
    } catch (Exception ex) {
        ex.printStackTrace();
        System.exit(1);
    }
}

From source file:PCC.java

/**
 * @param args the command line arguments
 * @throws java.io.IOException//from   w w  w .  j a  va2s . com
 */

public static void main(String[] args) throws IOException {
    // TODO code application logic here

    PearsonsCorrelation corel = new PearsonsCorrelation();
    PCC method = new PCC();
    ArrayList<String> name = new ArrayList<>();
    Multimap<String, String> genes = ArrayListMultimap.create();
    BufferedWriter bw = new BufferedWriter(new FileWriter(args[1]));
    BufferedReader br = new BufferedReader(new FileReader(args[0]));
    String str;
    while ((str = br.readLine()) != null) {
        String[] a = str.split("\t");
        name.add(a[0]);
        for (int i = 1; i < a.length; i++) {
            genes.put(a[0], a[i]);
        }
    }
    for (String key : genes.keySet()) {
        double[] first = new double[genes.get(key).size()];
        int element1 = 0;
        for (String value : genes.get(key)) {
            double d = Double.parseDouble(value);
            first[element1] = d;
            element1++;
        }
        for (String key1 : genes.keySet()) {
            if (!key.equals(key1)) {
                double[] second = new double[genes.get(key1).size()];
                int element2 = 0;
                for (String value : genes.get(key1)) {
                    double d = Double.parseDouble(value);
                    second[element2] = d;
                    element2++;

                }
                double corrlation = corel.correlation(first, second);
                if (corrlation > 0.5) {
                    bw.write(key + "\t" + key1 + "\t" + corrlation + "\t"
                            + method.pvalue(corrlation, second.length) + "\n");
                }
            }
        }
    }
    br.close();
    bw.close();
}

From source file:de.tudarmstadt.ukp.experiments.dip.wp1.documents.Step2FillWithRetrievedResults.java

public static void main(String[] args) throws IOException {
    // input dir - list of xml query containers
    File inputDir = new File(args[0]);

    // retrieved results from Technion
    // ltr-50queries-100docs.txt
    File ltr = new File(args[1]);

    // output dir
    File outputDir = new File(args[2]);
    if (!outputDir.exists()) {
        outputDir.mkdirs();/*from w w w  . ja v  a2 s. co  m*/
    }

    // load the query containers first (into map: id + container)
    Map<String, QueryResultContainer> queryResults = new HashMap<>();
    for (File f : FileUtils.listFiles(inputDir, new String[] { "xml" }, false)) {
        System.out.println(f);
        QueryResultContainer queryResultContainer = QueryResultContainer
                .fromXML(FileUtils.readFileToString(f, "utf-8"));
        queryResults.put(queryResultContainer.qID, queryResultContainer);
    }

    // iterate over IR results
    for (String line : FileUtils.readLines(ltr)) {
        String[] split = line.split("\\s+");
        Integer origQueryId = Integer.valueOf(split[0]);
        String clueWebID = split[2];
        Integer rank = Integer.valueOf(split[3]);
        double score = Double.valueOf(split[4]);
        String additionalInfo = split[5];

        // get the container for this result
        QueryResultContainer container = queryResults.get(origQueryId.toString());

        if (container != null) {
            // add new result
            QueryResultContainer.SingleRankedResult result = new QueryResultContainer.SingleRankedResult();
            result.clueWebID = clueWebID;
            result.rank = rank;
            result.score = score;
            result.additionalInfo = additionalInfo;

            if (container.rankedResults == null) {
                container.rankedResults = new ArrayList<>();
            }
            container.rankedResults.add(result);
        }
    }

    // save all containers to the output dir
    for (QueryResultContainer queryResultContainer : queryResults.values()) {
        File outputFile = new File(outputDir, queryResultContainer.qID + ".xml");
        FileUtils.writeStringToFile(outputFile, queryResultContainer.toXML(), "utf-8");
        System.out.println("Finished " + outputFile);
    }
}