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:Main.java

public static void main(String... args) {
    try {//  w  w  w.  jav  a 2  s .  c o m
        Class<?> c = Class.forName(args[0]);
        Class[] argTypes = new Class[] { String[].class };
        Method main = c.getDeclaredMethod("main", argTypes);
        String[] mainArgs = Arrays.copyOfRange(args, 1, args.length);
        System.out.format("invoking %s.main()%n", c.getName());
        main.invoke(null, (Object) mainArgs);

        // production code should handle these exceptions more gracefully
    } catch (ClassNotFoundException x) {
        x.printStackTrace();
    } catch (NoSuchMethodException x) {
        x.printStackTrace();
    } catch (IllegalAccessException x) {
        x.printStackTrace();
    } catch (InvocationTargetException x) {
        x.printStackTrace();
    }
}

From source file:musite.MusiteMain.java

/**
* @param args the command line arguments
*///from  w  w w.ja va2s .  c o  m
public static void main(String[] args) {
    init();

    if (args.length == 0) {
        // gui mode
        setupLookAndFeel();

        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                Musite.getDesktop().setVisible(true);
            }
        });
    } else {
        if (args[0].equalsIgnoreCase("list-model")) {
            CmdLineTools.listModelCmd();
        } else if (args[0].equalsIgnoreCase("predict")) {
            try {
                CmdLineTools.predictCmd(Arrays.copyOfRange(args, 1, args.length));
            } catch (Exception e) {
                e.printStackTrace();
                System.exit(1);
            }
        } else {
            System.err.println("Unsupported command");
            System.exit(1);
        }
    }
}

From source file:net.orpiske.sas.service.main.Main.java

public static void main(String[] args) {
    int ret = 0;//from   w w w.j  a  v  a2s .  co  m

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

    try {
        ConfigurationWrapper.initConfiguration(Constants.SAS_SERVICE_CONFIG_DIR, Constants.CONFIG_FILE_NAME);
    } catch (ConfigurationException e) {
        System.err.println("Unable to load configuration file " + "'mdm-broker.properties': " + e.getMessage());

        System.exit(-1);
    } catch (FileNotFoundException e) {
        System.err.println("Unable to find configuration file " + "'mdm-broker.properties': " + e.getMessage());

        System.exit(-1);
    }

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

    if (first.equals("run")) {
        RunAction runAction = new RunAction(newArgs);

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

    help(-1);
}

From source file:net.orpiske.mdm.broker.main.Main.java

public static void main(String[] args) {
    int ret = 0;/*w w  w .  j  av  a2s. co m*/

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

    try {
        ConfigurationWrapper.initConfiguration(Constants.MDM_BROKER_CONFIG_DIR, Constants.CONFIG_FILE_NAME);
    } catch (ConfigurationException e) {
        System.err.println("Unable to load configuration file " + "'mdm-broker.properties': " + e.getMessage());

        System.exit(-1);
    } catch (FileNotFoundException e) {
        System.err.println("Unable to find configuration file " + "'mdm-broker.properties': " + e.getMessage());

        System.exit(-1);
    }

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

    if (first.equals("run")) {
        RunAction runAction = new RunAction(newArgs);

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

    help(-1);
}

From source file:org.usergrid.benchmark.boostrap.Command.java

/**
 * @param args/*from   w ww  . ja  v a2s  .c o m*/
 */
public static void main(String[] args) {

    if ((args == null) || (args.length < 1)) {
        System.out.println("No command specified");
        return;
    }

    String command = args[0];

    Class<?> clazz = null;

    try {
        clazz = Class.forName(command);
    } catch (ClassNotFoundException e) {
    }

    if (clazz == null) {
        try {
            clazz = Class.forName("org.usergrid.benchmark.commands." + command);
        } catch (ClassNotFoundException e) {
        }
    }

    if (clazz == null) {
        try {
            clazz = Class.forName("org.usergrid.benchmark.commands." + StringUtils.capitalize(command));
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    if (clazz == null) {
        System.out.println("Unable to find command");
        return;
    }

    args = Arrays.copyOfRange(args, 1, args.length);

    try {
        if (ToolBase.class.isAssignableFrom(clazz)) {
            ToolBase tool = (ToolBase) clazz.newInstance();
            tool.startTool(args);
        } else {
            MethodUtils.invokeStaticMethod(clazz, "main", (Object) args);
        }
    } catch (NoSuchMethodException e) {
        System.out.println("Unable to invoke command");
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        System.out.println("Unable to invoke command");
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        System.out.println("Error while invoking command");
        e.printStackTrace();
    } catch (InstantiationException e) {
        System.out.println("Error while instantiating tool object");
        e.printStackTrace();
    }
}

From source file:edu.cuhk.hccl.SequenceFileWriter.java

public static void main(String[] args) throws IOException {
    // Check parameters
    if (args.length < 3) {
        System.out.print("Please specify three parameters!");
        System.exit(-1);//from www . ja v a  2  s.co  m
    }

    File filesDir = new File(args[0]);
    String targetDir = args[1];
    final int NUM_SPLITS = Integer.parseInt(args[2]);

    // Remove old target directory first
    FileUtils.deleteQuietly(new File(targetDir));

    File[] dataFiles = filesDir.listFiles();

    int total = dataFiles.length;
    int range = (int) Math.round(total / NUM_SPLITS + 0.5);
    System.out.printf("[INFO] The number of total files is %d \n.", total);

    for (int i = 1; i <= NUM_SPLITS; i++) {
        int start = (i - 1) * range;
        int end = Math.min(start + range, total);
        File[] subFiles = Arrays.copyOfRange(dataFiles, start, end);
        createSeqFile(subFiles, FilenameUtils.normalize(targetDir + "/" + i + ".seq"));
    }

    System.out.println("[INFO] All files have been successfully processed!");
}

From source file:com.sr.eb.compiler.Main.java

public static void main(String[] args) throws Throwable {
    try {//from  w w w  .  j a  va  2s  .  c  o m
        Options options = new Options();

        options.addOption("v", "verbose", false, "Enables verbose compiler output.");
        options.addOption("ee", "easterEgg", false, "Enables compiler easter eggs, DO NOT USE!");

        CommandLineParser parser = new BasicParser();
        CommandLine cmd = parser.parse(options, args);

        if (cmd.getArgs().length > 0) {
            int start = -1;
            while (true) {
                start++;
                if (options.getOption(cmd.getArgs()[start]) == null)
                    break;
            }

            String[] sourceFiles = Arrays.copyOfRange(cmd.getArgs(), start, cmd.getArgs().length);

            // TODO
        } else {
            System.out.println("Expected source files, got none!");
            System.out.println("Usage: ebc [options] <source files>");
        }
    } catch (ParseException e) {
        e.printStackTrace();
    }

    /* ----- Testing ----- */
    Lexer lexer = Lexer.newInstance();
    Parser parser = Parser.newInstance();

    try (InputStream in = new FileInputStream("test.eb")) {
        lexer.reset(Utils.readAll(in));
    }

    List<Token> tokens = lexer.tokenize();
    parser.reset(tokens);
    SyntaxTree t = parser.parse();

    ASTPrettyPrinter.print(t);
}

From source file:hyperheuristics.main.comparisons.CompareHypervolumes.java

public static void main(String[] args) throws IOException, InterruptedException {

    int[] numberOfObjectivesArray = new int[] { 2, 4 };
    String[] problems;//from   w ww.j  a  v a  2 s  .  com
    if (args.length == 0) {
        problems = new String[] { "OO_MyBatis", "OA_AJHsqldb", "OA_AJHotDraw", "OO_BCEL", "OO_JHotDraw",
                "OA_HealthWatcher",
                //                "OA_TollSystems",
                "OO_JBoss" };
    } else {
        EXECUTIONS = Integer.parseInt(args[0]);
        numberOfObjectivesArray = new int[] { Integer.parseInt(args[4]) };
        problems = Arrays.copyOfRange(args, 5, args.length);
    }

    String[] heuristicFunctions = new String[] { LowLevelHeuristic.CHOICE_FUNCTION,
            LowLevelHeuristic.MULTI_ARMED_BANDIT, //            LowLevelHeuristic.RANDOM
    };

    String[] algorithms = new String[] { "NSGA-II", "SPEA2" };

    for (int numberOfObjectives : numberOfObjectivesArray) {
        //            hypervolumeComparison(problems, heuristicFunctions, numberOfObjectives, algorithms);
        //            hypervolumeHyperheuristicsComparison(problems, heuristicFunctions, numberOfObjectives,);
        //            hypervolumeByGeneration(problems, heuristicFunctions, numberOfObjectives);
        generateTables(problems, heuristicFunctions, numberOfObjectives, algorithms);
    }
}

From source file:com.ibm.crail.namenode.NameNode.java

public static void main(String args[]) throws Exception {
    LOG.info("initalizing namenode ");
    CrailConfiguration conf = new CrailConfiguration();
    CrailConstants.updateConstants(conf);

    URI uri = CrailUtils.getPrimaryNameNode();
    String address = uri.getHost();
    int port = uri.getPort();

    if (args != null) {
        Option addressOption = Option.builder("a").desc("ip address namenode is started on").hasArg().build();
        Option portOption = Option.builder("p").desc("port namenode is started on").hasArg().build();
        Options options = new Options();
        options.addOption(portOption);/*from  ww  w .j a v  a  2  s .  co  m*/
        options.addOption(addressOption);
        CommandLineParser parser = new DefaultParser();

        try {
            CommandLine line = parser.parse(options, Arrays.copyOfRange(args, 0, args.length));
            if (line.hasOption(addressOption.getOpt())) {
                address = line.getOptionValue(addressOption.getOpt());
            }
            if (line.hasOption(portOption.getOpt())) {
                port = Integer.parseInt(line.getOptionValue(portOption.getOpt()));
            }
        } catch (ParseException e) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("Namenode", options);
            System.exit(-1);
        }
    }

    String namenode = "crail://" + address + ":" + port;
    long serviceId = CrailUtils.getServiceId(namenode);
    long serviceSize = CrailUtils.getServiceSize();
    if (!CrailUtils.verifyNamenode(namenode)) {
        throw new Exception("Namenode address/port [" + namenode
                + "] has to be listed in crail.namenode.address " + CrailConstants.NAMENODE_ADDRESS);
    }

    CrailConstants.NAMENODE_ADDRESS = namenode + "?id=" + serviceId + "&size=" + serviceSize;
    CrailConstants.printConf();
    CrailConstants.verify();

    RpcNameNodeService service = RpcNameNodeService.createInstance(CrailConstants.NAMENODE_RPC_SERVICE);
    RpcBinding rpcBinding = RpcBinding.createInstance(CrailConstants.NAMENODE_RPC_TYPE);
    rpcBinding.init(conf, null);
    rpcBinding.printConf(LOG);
    rpcBinding.run(service);
    System.exit(0);
    ;
}

From source file:org.jetbrains.webdemo.executors.JavaExecutor.java

public static void main(String[] args) {
    PrintStream defaultOutputStream = System.out;
    try {//from w ww  . jav a2 s .c  om
        System.setOut(new PrintStream(standardOutputStream));
        System.setErr(new PrintStream(errorOutputStream));

        RunOutput outputObj = new RunOutput();
        String className;
        if (args.length > 0) {
            className = args[0];
            try {
                Method mainMethod = Class.forName(className).getMethod("main", String[].class);
                mainMethod.invoke(null, (Object) Arrays.copyOfRange(args, 1, args.length));
            } catch (InvocationTargetException e) {
                outputObj.exception = e.getCause();
            } catch (NoSuchMethodException e) {
                System.err.println("No main method found in project.");
            } catch (ClassNotFoundException e) {
                System.err.println("No main method found in project.");
            }
        } else {
            System.err.println("No main method found in project.");
        }

        System.out.flush();
        System.err.flush();
        System.setOut(defaultOutputStream);
        outputObj.text = outputStream.toString().replaceAll("</errStream><errStream>", "")
                .replaceAll("</outStream><outStream>", "");
        ObjectMapper objectMapper = new ObjectMapper();
        SimpleModule module = new SimpleModule();
        module.addSerializer(Throwable.class, new ThrowableSerializer());
        objectMapper.registerModule(module);
        System.out.print(objectMapper.writeValueAsString(outputObj));
    } catch (Throwable e) {
        System.setOut(defaultOutputStream);
        System.out.println("{\"text\":\"<errStream>" + e.getClass().getName() + ": " + e.getMessage());
        System.out.print("</errStream>\"}");
    }

}