Example usage for java.util Arrays copyOfRange

List of usage examples for java.util Arrays copyOfRange

Introduction

In this page you can find the example usage for java.util Arrays copyOfRange.

Prototype

public static boolean[] copyOfRange(boolean[] original, int from, int to) 

Source Link

Document

Copies the specified range of the specified array into a new array.

Usage

From source file:de.whs.poodle.Poodle.java

public static void main(String[] args) {
    /* if the first argument is "cli", we run the CLI, otherwise the
     * web application. *//*from ww w.j  a  va  2  s  .co m*/
    boolean runCli = args.length > 0 && args[0].equals("cli");

    if (runCli) {
        // remove first argument ("cli"), the CLI doesn't care about it
        String[] cliArgs = Arrays.copyOfRange(args, 1, args.length);
        PoodleCli.run(cliArgs);
    } else {
        // run as normal web app
        SpringApplication.run(Poodle.class, args);
    }
}

From source file:net.orpiske.dcd.main.Main.java

/**
 * @param args//ww  w  .j a  va  2  s  .  c o m
 */
public static void main(String[] args) {
    int ret = 0;

    if (args.length == 0) {
        help(1);
    }

    String first = args[0];
    String[] newArgs = Arrays.copyOfRange(args, 1, args.length);

    initConfiguration();
    initDomainConfiguration();

    // TODO: add a fetching action
    if (first.equals("fetch")) {

    }

    if (first.equals("parse")) {
        ParseAction parseAction = new ParseAction(newArgs);

        ret = parseAction.run();
        System.exit(ret);
    }

    if (first.equals("dispatch")) {

    }

}

From source file:com.cdd.bao.Main.java

public static void main(String[] argv) {
    //org.apache.log4j.Logger.getRootLogger().setLevel(org.apache.log4j.Level.OFF);
    org.apache.logging.log4j.status.StatusLogger.getLogger().setLevel(org.apache.logging.log4j.Level.OFF);

    if (argv.length > 0 && (argv[0].equals("-h") || argv[0].equals("--help"))) {
        printHelp();/*from   w w w .j av  a 2 s. com*/
        return;
    }

    // look for additional options that affect overall state
    String[] extraOnto = null, exclOnto = null;
    for (int n = 0; n < argv.length;) {
        if (argv[n].startsWith("--onto")) {
            argv = ArrayUtils.remove(argv, n);
            while (n < argv.length) {
                if (argv[n].startsWith("-"))
                    break;
                extraOnto = ArrayUtils.add(extraOnto, argv[n]);
                argv = ArrayUtils.remove(argv, n);
            }
        } else if (argv[n].startsWith("--excl")) {
            argv = ArrayUtils.remove(argv, n);
            while (n < argv.length) {
                if (argv[n].startsWith("-"))
                    break;
                exclOnto = ArrayUtils.add(exclOnto, argv[n]);
                argv = ArrayUtils.remove(argv, n);
            }
        } else
            n++;
    }
    Vocabulary.setExtraOntology(extraOnto);
    Vocabulary.setExclOntology(exclOnto);

    // main command-induced functionality
    if (argv.length == 0)
        new MainApplication().exec(new String[0]);
    else if (argv[0].equals("edit")) {
        String[] subset = Arrays.copyOfRange(argv, 1, argv.length);
        new MainApplication().exec(subset);
    } else if (argv[0].equals("geneont")) {
        try {
            ImportGeneOntology impgo = new ImportGeneOntology();
            impgo.load(argv[1]);
            impgo.save(argv[2]);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    } else if (argv[0].equals("filter")) {
        try {
            OntologyFilter filt = new OntologyFilter();
            filt.load(argv[1]);
            filt.save(argv[2]);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    } else if (argv[0].equals("compare")) {
        try {
            diffVocab(ArrayUtils.remove(argv, 0));
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    } else if (argv[0].equals("compile")) {
        try {
            compileSchema(ArrayUtils.remove(argv, 0));
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    } else if (argv[0].equals("check")) {
        try {
            checkTemplate(ArrayUtils.remove(argv, 0));
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    } else if (argv[0].equals("import")) {
        try {
            importKeywords(ArrayUtils.remove(argv, 0));
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    } else if (argv[0].equals("scanaxioms")) {
        try {
            new ScanAxioms().exec();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    } else {
        Util.writeln("Unknown option '" + argv[0] + "'");
        printHelp();
    }
}

From source file:fr.jamgotchian.jcompgen.example.Example1.java

public static void main(String[] args) {
    if (args.length < 1) {
        printUsage();//w  ww  . j  a v a 2s .c  o m
    }
    String command = args[0];
    Options options = OPTIONS_PER_COMMAND.get(command);
    if (options == null) {
        printUsage();
    }
    try {
        CommandLineParser parser = new PosixParser();
        CommandLine line = parser.parse(options, Arrays.copyOfRange(args, 1, args.length));
        System.out.println("executing command " + command + "...");
    } catch (ParseException e) {
        System.err.println("error: " + e.getMessage());
        printCommandUsage(command, options);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:de.zib.scalaris.examples.wikipedia.data.xml.Main.java

/**
 * The main function of the application. Some articles are blacklisted and
 * will not be processed (see implementation for a list of them).
 * //from  ww  w  .j  av a2s.  c om
 * @param args
 *            first argument should be the xml file to convert.
 */
public static void main(String[] args) {
    try {
        String filename = args[0];

        if (args.length > 1) {
            if (args[1].equals("filter")) {
                doFilter(filename, Arrays.copyOfRange(args, 2, args.length));
            } else if (args[1].equals("import-xml")) {
                doImport(filename, Arrays.copyOfRange(args, 2, args.length), ImportType.IMPORT_XML);
            } else if (args[1].equals("import-db")) {
                doImport(filename, Arrays.copyOfRange(args, 2, args.length), ImportType.IMPORT_DB);
            } else if (args[1].equals("prepare")) {
                doImport(filename, Arrays.copyOfRange(args, 2, args.length), ImportType.PREPARE_DB);
            } else if (args[1].equals("xml2db")) {
                doImport(filename, Arrays.copyOfRange(args, 2, args.length), ImportType.XML_2_DB);
            } else if (args[1].equals("convert")) {
                doConvert(filename, Arrays.copyOfRange(args, 2, args.length));
            } else if (args[1].equals("dumpdb-addlinks")) {
                doDumpdbAddlinks(filename, Arrays.copyOfRange(args, 2, args.length));
            } else if (args[1].equals("dumpdb-filter")) {
                doDumpdbFilter(filename, Arrays.copyOfRange(args, 2, args.length));
            }
        }
    } catch (SAXException e) {
        System.err.println(e.getMessage());
        System.exit(-1);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        System.exit(-1);
    } catch (IOException e) {
        e.printStackTrace();
        System.exit(-1);
    }
}

From source file:edu.msu.cme.rdp.seqmatch.cli.SeqMatchMain.java

public static void main(String[] args) throws Exception {

    if (args.length == 0) {
        System.err.println("USAGE: SeqMatchMain [train|seqmatch] <args>");
        return;//from ww  w  .j a  v  a 2s. c om
    }

    String cmd = args[0];
    args = Arrays.copyOfRange(args, 1, args.length);

    if (cmd.equals("train")) {
        if (args.length != 2) {
            System.err.println("USAGE: train <reference sequences> <trainee_out_file_prefix>"
                    + "\nMultiple trainee output files might be created, each containing maximum "
                    + Trainee.MAX_NUM_SEQ + " sequences");
            return;
        }

        File refSeqs = new File(args[0]);
        File traineeFileOut = new File(args[1]);

        //maybe more than 1 trainee files need to be created, depending on the number of seqs
        CreateMultiMatchFromFile.getMultiTrainee(refSeqs, traineeFileOut);
    } else if (cmd.equals("seqmatch")) {
        File refFile = null;
        File queryFile = null;
        HashMap<String, String> descMap = new HashMap<String, String>();
        PrintStream out = new PrintStream(System.out);
        int knn = 20;
        float minSab = .5f;

        try {
            CommandLine line = new PosixParser().parse(options, args);

            if (line.hasOption("knn")) {
                knn = Integer.parseInt(line.getOptionValue("knn"));
            }

            if (line.hasOption("sab")) {
                minSab = Float.parseFloat(line.getOptionValue("sab"));
            }
            if (line.hasOption("desc")) {
                descMap = readDesc(new File(line.getOptionValue("desc")));
            }
            if (line.hasOption("outFile")) {
                out = new PrintStream(new File(line.getOptionValue("outFile")));
            }

            args = line.getArgs();

            if (args.length != 2) {
                throw new Exception("Unexpected number of command line arguments");
            }

            refFile = new File(args[0]);
            queryFile = new File(args[1]);

        } catch (Exception e) {
            new HelpFormatter().printHelp("seqmatch <refseqs | trainee_file_or_dir> <query_file>\n"
                    + " trainee_file_or_dir is a single trainee file or a directory containing multiple trainee files",
                    options);
            System.err.println("Error: " + e.getMessage());
            return;
        }

        SeqMatch seqmatch = null;
        if (refFile.isDirectory()) { // a directory of trainee files
            List<SeqMatch> engineList = new ArrayList<SeqMatch>();
            for (File f : refFile.listFiles()) {
                if (!f.isHidden()) {
                    TwowaySeqMatch match = new TwowaySeqMatch(new SeqMatchEngine(new StorageTrainee(f)));
                    engineList.add(match);
                }
            }
            seqmatch = new MultiTraineeSeqMatch(engineList);
        } else { // a single fasta file or trainee file
            if (SeqUtils.guessFileFormat(refFile) == SequenceFormat.UNKNOWN) {
                seqmatch = CLISeqMatchFactory.trainTwowaySeqMatch(new StorageTrainee(refFile));
            } else {
                seqmatch = CreateMultiMatchFromFile.getMultiMatch(refFile);
            }
        }

        out.println("query name\tmatch seq\torientation\tS_ab score\tunique oligomers\tdescription");

        SeqReader reader = new SequenceReader(queryFile);
        Sequence seq;

        while ((seq = reader.readNextSequence()) != null) {
            SeqMatchResultSet resultSet = seqmatch.match(seq, knn);
            for (SeqMatchResult result : resultSet) {
                char r = '+';
                if (result.isReverse()) {
                    r = '-';
                }

                if (result.getScore() > minSab) {
                    out.println(seq.getSeqName() + "\t" + result.getSeqName() + "\t" + r + "\t"
                            + result.getScore() + "\t" + resultSet.getQueryWordCount() + "\t"
                            + descMap.get(result.getSeqName()));
                }
            }
        }

        out.close();
    } else {
        throw new IllegalArgumentException("USAGE: SeqMatchMain [train|seqmatch] <args>");
    }
}

From source file:com.ibm.crail.storage.StorageServer.java

public static void main(String[] args) throws Exception {
    Logger LOG = CrailUtils.getLogger();
    CrailConfiguration conf = new CrailConfiguration();
    CrailConstants.updateConstants(conf);
    CrailConstants.printConf();//ww w.j a  v a  2s  .c om
    CrailConstants.verify();

    int splitIndex = 0;
    for (String param : args) {
        if (param.equalsIgnoreCase("--")) {
            break;
        }
        splitIndex++;
    }

    //default values
    StringTokenizer tokenizer = new StringTokenizer(CrailConstants.STORAGE_TYPES, ",");
    if (!tokenizer.hasMoreTokens()) {
        throw new Exception("No storage types defined!");
    }
    String storageName = tokenizer.nextToken();
    int storageType = 0;
    HashMap<String, Integer> storageTypes = new HashMap<String, Integer>();
    storageTypes.put(storageName, storageType);
    for (int type = 1; tokenizer.hasMoreElements(); type++) {
        String name = tokenizer.nextToken();
        storageTypes.put(name, type);
    }
    int storageClass = -1;

    //custom values
    if (args != null) {
        Option typeOption = Option.builder("t").desc("storage type to start").hasArg().build();
        Option classOption = Option.builder("c").desc("storage class the server will attach to").hasArg()
                .build();
        Options options = new Options();
        options.addOption(typeOption);
        options.addOption(classOption);
        CommandLineParser parser = new DefaultParser();

        try {
            CommandLine line = parser.parse(options, Arrays.copyOfRange(args, 0, splitIndex));
            if (line.hasOption(typeOption.getOpt())) {
                storageName = line.getOptionValue(typeOption.getOpt());
                storageType = storageTypes.get(storageName).intValue();
            }
            if (line.hasOption(classOption.getOpt())) {
                storageClass = Integer.parseInt(line.getOptionValue(classOption.getOpt()));
            }
        } catch (ParseException e) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("Storage tier", options);
            System.exit(-1);
        }
    }
    if (storageClass < 0) {
        storageClass = storageType;
    }

    StorageTier storageTier = StorageTier.createInstance(storageName);
    if (storageTier == null) {
        throw new Exception("Cannot instantiate datanode of type " + storageName);
    }

    String extraParams[] = null;
    splitIndex++;
    if (args.length > splitIndex) {
        extraParams = new String[args.length - splitIndex];
        for (int i = splitIndex; i < args.length; i++) {
            extraParams[i - splitIndex] = args[i];
        }
    }
    storageTier.init(conf, extraParams);
    storageTier.printConf(LOG);

    RpcClient rpcClient = RpcClient.createInstance(CrailConstants.NAMENODE_RPC_TYPE);
    rpcClient.init(conf, args);
    rpcClient.printConf(LOG);

    ConcurrentLinkedQueue<InetSocketAddress> namenodeList = CrailUtils.getNameNodeList();
    ConcurrentLinkedQueue<RpcConnection> connectionList = new ConcurrentLinkedQueue<RpcConnection>();
    while (!namenodeList.isEmpty()) {
        InetSocketAddress address = namenodeList.poll();
        RpcConnection connection = rpcClient.connect(address);
        connectionList.add(connection);
    }
    RpcConnection rpcConnection = connectionList.peek();
    if (connectionList.size() > 1) {
        rpcConnection = new RpcDispatcher(connectionList);
    }
    LOG.info("connected to namenode(s) " + rpcConnection.toString());

    StorageServer server = storageTier.launchServer();
    StorageRpcClient storageRpc = new StorageRpcClient(storageType, CrailStorageClass.get(storageClass),
            server.getAddress(), rpcConnection);

    HashMap<Long, Long> blockCount = new HashMap<Long, Long>();
    long sumCount = 0;
    while (server.isAlive()) {
        StorageResource resource = server.allocateResource();
        if (resource == null) {
            break;
        } else {
            storageRpc.setBlock(resource.getAddress(), resource.getLength(), resource.getKey());
            DataNodeStatistics stats = storageRpc.getDataNode();
            long newCount = stats.getFreeBlockCount();
            long serviceId = stats.getServiceId();

            long oldCount = 0;
            if (blockCount.containsKey(serviceId)) {
                oldCount = blockCount.get(serviceId);
            }
            long diffCount = newCount - oldCount;
            blockCount.put(serviceId, newCount);
            sumCount += diffCount;
            LOG.info("datanode statistics, freeBlocks " + sumCount);
        }
    }

    while (server.isAlive()) {
        DataNodeStatistics stats = storageRpc.getDataNode();
        long newCount = stats.getFreeBlockCount();
        long serviceId = stats.getServiceId();

        long oldCount = 0;
        if (blockCount.containsKey(serviceId)) {
            oldCount = blockCount.get(serviceId);
        }
        long diffCount = newCount - oldCount;
        blockCount.put(serviceId, newCount);
        sumCount += diffCount;

        LOG.info("datanode statistics, freeBlocks " + sumCount);
        Thread.sleep(2000);
    }
}

From source file:eu.itesla_project.commons.tools.Main.java

public static void main(String[] args) throws IOException {
    if (args.length < 1) {
        printUsage();/*from   w ww  .  j a  v a 2  s  .c  o  m*/
    }

    Tool tool = findTool(args[0]);
    if (tool == null) {
        printUsage();
    }

    try {
        CommandLineParser parser = new PosixParser();
        CommandLine line = parser.parse(getOptionsWithHelp(tool.getCommand().getOptions()),
                Arrays.copyOfRange(args, 1, args.length));
        if (line.hasOption("help")) {
            printCommandUsage(tool.getCommand());
        } else {
            tool.run(line);
        }
    } catch (ParseException e) {
        System.err.println("error: " + e.getMessage());
        printCommandUsage(tool.getCommand());
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:co.cask.tigon.StandaloneMain.java

public static void main(String[] args) {
    System.out.println("Tigon Standalone Client");
    if (args.length > 0) {
        if ("--help".equals(args[0]) || "-h".equals(args[0])) {
            usage(false);//  w  w  w  .  j a v a 2  s  .c  o  m
            return;
        }

        if (args.length < 2) {
            usage(true);
        }

        File jarPath = new File(args[0]);
        String mainClassName = args[1];

        Map<String, String> runtimeArgs = null;
        try {
            runtimeArgs = DeployClient.fromPosixArray(Arrays.copyOfRange(args, 2, args.length));
        } catch (IllegalArgumentException e) {
            usage(true);
        }

        try {
            StandaloneMain main;
            main = createStandaloneMain();
            main.startUp(jarPath, mainClassName, runtimeArgs);
        } catch (Exception e) {
            LOG.error(e.getMessage(), e);
        }
    }
}

From source file:at.tuwien.ifs.somtoolbox.apps.SOMToolboxMain.java

/**
 * Central Main for SOMToolbox.//from w  w  w  .j  a v  a2s.c  om
 * 
 * @param args the command line args
 */
public static void main(String[] args) {
    int screenWidth = 80;
    try {
        screenWidth = Integer.parseInt(System.getenv("COLUMNS"));
    } catch (Exception e) {
        screenWidth = 80;
    }

    JSAP jsap = new JSAP();
    try {
        jsap.registerParameter(new UnflaggedOption("main", JSAP.STRING_PARSER, null, false, false));
        jsap.registerParameter(new Switch("gui", 'G', "gui"));
        jsap.registerParameter(new Switch("version", JSAP.NO_SHORTFLAG, "version"));
        jsap.registerParameter(new Switch("listmains", JSAP.NO_SHORTFLAG, "list-mains"));
        jsap.registerParameter(
                new FlaggedOption("help", JSAP.STRING_PARSER, null, false, JSAP.NO_SHORTFLAG, "help"));
    } catch (JSAPException e) {
        assert false;
    }
    JSAPResult result = jsap.parse(args);

    ArrayList<Class<? extends SOMToolboxApp>> runnables = SubClassFinder.findSubclassesOf(SOMToolboxApp.class,
            true);
    Collections.sort(runnables, SOMToolboxApp.TYPE_GROUPED_COMPARATOR);

    // args > 0
    boolean useGUI = result.getBoolean("gui", false);
    if (useGUI) {
        UiUtils.setSOMToolboxLookAndFeel();
    }

    if (result.getBoolean("listmains")) {
        if (useGUI) {
            showAvailableRunnables(runnables, args);
        } else {
            printAvailableRunnables(screenWidth, runnables);
        }
    } else if (result.getBoolean("version")) {
        if (result.userSpecified("main")) {
            printVersion(result.getString("main"));
        } else {
            printVersion("somtoolbox");
        }
    } else if (result.userSpecified("main")) {
        String mainClass = result.getString("main");
        String[] cleanArgs = Arrays.copyOfRange(args, 1, args.length);
        if (!invokeMainClass(runnables, mainClass, cleanArgs, useGUI)) {
            Logger.getLogger("at.tuwien.ifs.somtoolbox").severe("Runnable \"" + mainClass + "\" not found.");
            printAvailableRunnables(screenWidth, runnables);
        }
    } else if (result.contains("help")) {
        if (result.getString("help") != null) {
            invokeMainClass(runnables, result.getString("help"), new String[] { "--help" }, useGUI);
        } else {
            printHelp();
        }
    } else {
        if (useGUI) {
            showAvailableRunnables(runnables, args);
        } else {
            printAvailableRunnables(screenWidth, runnables);
        }

    }
}