Example usage for org.apache.commons.lang3 ArrayUtils subarray

List of usage examples for org.apache.commons.lang3 ArrayUtils subarray

Introduction

In this page you can find the example usage for org.apache.commons.lang3 ArrayUtils subarray.

Prototype

public static boolean[] subarray(final boolean[] array, int startIndexInclusive, int endIndexExclusive) 

Source Link

Document

Produces a new boolean array containing the elements between the start and end indices.

The start index is inclusive, the end index exclusive.

Usage

From source file:cn.wanghaomiao.seimi.boot.Run.java

public static void main(String[] args) {
    Seimi s = new Seimi();
    if (ArrayUtils.isNotEmpty(args)) {
        if (args[0].matches("\\d+")) {
            int port = Integer.parseInt(args[0]);
            if (args.length > 1) {
                s.startWithHttpd(port, ArrayUtils.subarray(args, 1, args.length));
            } else {
                s.startAllWithHttpd(port);
            }/*from w  w w.ja v  a  2 s . c  om*/
        } else {
            s.start(args);
        }
    } else {
        s.startAll();
    }
}

From source file:com.conversantmedia.mapreduce.tool.RunJob.java

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

    // Get the base packages from the classpath resource
    String[] scanPackages = getBasePackagesToScanForDrivers();

    // Initialize the reflections object
    Reflections reflections = initReflections((Object[]) scanPackages);

    // Search the classpath for Tool and Driver annotations
    Map<String, DriverMeta> idMap = findAllDrivers(reflections);

    if (idMap.isEmpty()) {
        System.out.printf("No drivers found in package(s) [%s]\n", StringUtils.join(scanPackages, ","));
        System.exit(0);/*from  w  w  w.j  a  v a2  s  . c o m*/
    }

    // Expects the first argument to be the id of the
    // tool to run. Otherwise list them all:
    if (args.length < 1) {
        outputDriversTable(idMap);
        System.exit(0);
    }

    // Shift off the first (driver id) argument
    String id = args[0];
    args = ArrayUtils.subarray(args, 1, args.length);

    DriverMeta driverMeta = idMap.get(id);
    if (driverMeta == null) {
        if (StringUtils.isNotBlank(id) && !StringUtils.startsWith(id, "-")) { // don't output message if no driver was specified
            // or if the first arg is an argument such as --conf (from runjob script)
            System.out.println("No Tool or Driver class found with id [" + id + "]");
        }
        outputDriversTable(idMap);
        System.exit(1);
    }

    // Finally, run the tool
    runDriver(driverMeta, args);
}

From source file:eu.amidst.flinklink.examples.misc.DynamicParallelVMPExtended.java

/**
*
* ./bin/flink run -m yarn-cluster -yn 8 -ys 4 -yjm 1024 -ytm 9000
*              -c eu.amidst.flinklink.examples.misc.DynamicParallelVMPExtended ../flinklink.jar 0 10 1000000 100 100 100 3 0
*
*
* @param args command line arguments//from  w w  w .jav a  2 s.c o  m
* @throws Exception
*/
public static void main(String[] args) throws Exception {

    int nCVars = Integer.parseInt(args[0]);
    int nMVars = Integer.parseInt(args[1]);
    int nSamples = Integer.parseInt(args[2]);
    int windowSize = Integer.parseInt(args[3]);
    int globalIter = Integer.parseInt(args[4]);
    int localIter = Integer.parseInt(args[5]);
    int nsets = Integer.parseInt(args[6]);
    int seed = Integer.parseInt(args[7]);
    boolean generateData = Boolean.parseBoolean(args[8]);

    /*
     * Generate dynamic datasets
     */
    if (generateData) {
        String[] argsDatasets = ArrayUtils.addAll(ArrayUtils.subarray(args, 0, 4),
                ArrayUtils.subarray(args, 6, 8));
        DynamicDataSets dynamicDataSets = new DynamicDataSets();
        dynamicDataSets.generateDynamicDataset(argsDatasets);
    }

    /*
     * Logging
     */
    //PropertyConfigurator.configure(args[6]);
    BasicConfigurator.configure();

    logger.info("Starting DynamicVMPExtended experiments");

    //String fileName = "hdfs:///tmp"+nCVars+"_"+nMVars+"_"+nSamples+"_"+nsets+"_"+seed;
    String fileName = "./datasets/tmp" + nCVars + "_" + nMVars + "_" + nSamples + "_" + nsets + "_" + seed;

    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

    DataFlink<DynamicDataInstance> data0 = DataFlinkLoader.loadDynamicDataFromFolder(env,
            fileName + "_iter_" + 0 + ".arff", false);

    DynamicDAG hiddenNB = getHiddenDynamicNaiveBayesStructure(data0.getAttributes(), false);

    System.out.println(hiddenNB.toString());

    //Structure learning is excluded from the test, i.e., we use directly the initial Asia network structure
    // and just learn then test the parameter learning

    long start = System.nanoTime();

    //Parameter Learning
    DynamicParallelVB parallelVB = new DynamicParallelVB();
    parallelVB.setGlobalThreshold(0.1);
    parallelVB.setMaximumGlobalIterations(globalIter);
    parallelVB.setLocalThreshold(0.1);
    parallelVB.setMaximumLocalIterations(localIter);
    parallelVB.setSeed(5);
    parallelVB.setOutput(true);

    //Set the window size
    parallelVB.setBatchSize(windowSize);
    parallelVB.setDAG(hiddenNB);
    parallelVB.initLearning();

    System.out.println("--------------- DATA " + 0 + " --------------------------");
    parallelVB.updateModelWithNewTimeSlice(0, data0);

    for (int i = 1; i < nsets; i++) {
        logger.info("--------------- DATA " + i + " --------------------------");
        DataFlink<DynamicDataInstance> dataNew = DataFlinkLoader.loadDynamicDataFromFolder(env,
                fileName + "_iter_" + i + ".arff", false);
        parallelVB.updateModelWithNewTimeSlice(i, dataNew);
    }

    logger.info(parallelVB.getLearntDynamicBayesianNetwork().toString());

    long duration = (System.nanoTime() - start) / 1;
    double seconds = duration / 1000000000.0;
    logger.info("Running time: {} seconds.", seconds);

}

From source file:com.smash.revolance.ui.cmdline.Main.java

private static String[] getOpts(String[] args) {
    return ArrayUtils.subarray(args, 1, args.length);
}

From source file:com.ewcms.util.HtmlFileUtil.java

public static String readText(InputStream is, String encoding) {
    try {//  w  w  w  . j av  a2 s  . c  om
        byte bs[] = readByte(is);
        if (encoding.equalsIgnoreCase("UTF-8")
                && HtmlStringUtil.hexEncode(ArrayUtils.subarray(bs, 0, 3)).equals("efbbbf"))
            bs = ArrayUtils.subarray(bs, 3, bs.length);
        return new String(bs, encoding);
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:com.fuerve.villageelder.client.commandline.Main.java

/**
 * The entry point into the Village Elder command line utility.
 * @param args Command line arguments.//from  ww w.j a va 2s  . c  om
 */
public static int run(String[] args) {
    if (args.length < 1) {
        return 1;
    } else {
        final String commandName = args[0];
        final String[] remainingArgs = ArrayUtils.subarray(args, 1, args.length);

        if (commandMap.containsKey(commandName)) {
            final Command command = commandMap.get(commandName);
            command.execute(remainingArgs);
        }
        return 0;
    }
}

From source file:name.martingeisse.stackd.common.cubes.RawCubes.java

/**
 * Decompresses and deserializes an object of this type from the specified array,
 * skipping the first byte since it is assumed to contain the compression scheme.
 * /*  w  w  w  .ja  v  a  2  s .  com*/
 * @param clusterSize the cluster size
 * @param compressedData the compressed data
 * @return the cubes object, or null if not successful
 */
public static RawCubes decompress(final ClusterSize clusterSize, final byte[] compressedData) {
    final byte[] deflatedCubes = ArrayUtils.subarray(compressedData, 1, compressedData.length);
    final byte[] cubes = CompressionUtil.inflate(deflatedCubes,
            StackdConstants.INTERACTIVE_SECTION_DATA_COMPRESSION_DICTIONARY);
    return new RawCubes(cubes);
}

From source file:com.mac.holdempoker.app.hands.Straight.java

private Card[] findStraight() {
    Card[] hand;//from  w ww .j a  v  a 2  s .c  om
    for (int i = 9; i >= 0; i--) {
        int j = i + 5;
        hand = ArrayUtils.subarray(cards, i, j);
        if (isStraight(hand)) {
            return hand;
        }
    }
    return null;
}

From source file:com.addthis.hydra.data.query.op.MergedRowFactory.java

@Override
public DiskBackedMap.DiskObject fromBytes(byte[] bytes) {
    MergedRow mergedRow = new MergedRow(conf, new ListBundle(format));
    mergedRow.numMergedRows = LessBytes.toInt(ArrayUtils.subarray(bytes, 0, Integer.SIZE / 8));
    ListBundleFormat format = new ListBundleFormat();
    ListBundle listBundle = new ListBundle(format);
    try {/*from  w w w .  j  ava 2 s  . c  o  m*/
        DataChannelCodec.decodeBundle(listBundle, ArrayUtils.subarray(bytes, Integer.SIZE / 8, bytes.length));
        int i = 0;
        for (MergedValue map : conf) {
            ValueObject value = listBundle.getValue(format.getField("" + i));
            i += 1;
            mergedRow.setValue(map.getTo(), value);
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return mergedRow;
}

From source file:net.dv8tion.discord.commands.PermissionsCommand.java

@Override
public void onCommand(MessageReceivedEvent e, String[] args) {
    if (!Permissions.getPermissions().isOp(e.getAuthor())) {
        sendMessage(e, Permissions.OP_REQUIRED_MESSAGE);
        return;//from  w w w .  j a va2  s  . com
    }

    if (args[0].contains(".perms") || args[0].contains(".permissions")) {
        args = ArrayUtils.subarray(args, 1, args.length); //We cut off the .perms or .permissions to make the array behave as .op would
    } else {
        args[0] = args[0].replace(".", ""); //Cut off the leading .
    }

    if (args.length < 1) //If the command sent was just '.perms', and we removed that above, then we have an array of length 0 currently.
    {
        sendMessage(e, "**Improper syntax, no permissions group provided!**");
        return;
    }
    switch (args[0]) {
    //Only 1 case for now. Later we will have more user permissions types...probably.
    case "op":
        processOp(e, args);
        break;
    default:
        sendMessage(e,
                new MessageBuilder().append("**Improper syntax, unrecognized permission group:** ")
                        .append(args[0]).append("\n**Provided Command:** ").append(e.getMessage().getContent())
                        .build());
        return;
    }
}