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:playground.christoph.evacuation.analysis.AgentsInEvacuationAreaWriter.java

/**
 * @return a graphic showing the number of agents in the evacuated area
 *///from  ww  w. java2s .  c o  m
private JFreeChart getGraphic(String[] modeNames, int inputData[][]) {

    /*
     * Write only the number of defined picture bins to the plot.
     */
    int data[][];
    data = new int[inputData.length][];
    for (int i = 0; i < inputData.length; i++) {
        if (inputData[i].length > this.nofPictureBins) {
            data[i] = Arrays.copyOfRange(inputData[i], 0, this.nofPictureBins);
        } else
            data[i] = inputData[i];
    }

    final XYSeriesCollection xyData = new XYSeriesCollection();

    for (int j = 0; j < modeNames.length; j++) {
        String modeName = modeNames[j];
        int[] d = data[j];

        XYSeries dataSerie = new XYSeries(modeName, false, true);

        for (int i = 0; i < d.length; i++) {
            double hour = i * this.binSize / 60.0 / 60.0;
            dataSerie.add(hour, d[i]);
        }

        xyData.addSeries(dataSerie);
    }

    final JFreeChart chart = ChartFactory.createXYStepChart(
            "agents in evacuated area, all modes, it." + this.iteration, "time", "# agents", xyData,
            PlotOrientation.VERTICAL, true, // legend
            false, // tooltips
            false // urls
    );

    XYPlot plot = chart.getXYPlot();

    final CategoryAxis axis1 = new CategoryAxis("hour");
    axis1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7));
    plot.setDomainAxis(new NumberAxis("time"));
    return chart;
}

From source file:com.haulmont.cuba.gui.relatedentities.RelatedEntitiesBean.java

protected String getRelatedEntitiesFilterXml(MetaClass relatedMetaCLass,
        Collection<? extends Entity> selectedEntities, Filter component, MetaDataDescriptor descriptor) {
    ConditionsTree tree = new ConditionsTree();

    String filterComponentPath = ComponentsHelper.getFilterComponentPath(component);
    String[] strings = ValuePathHelper.parse(filterComponentPath);
    String filterComponentName = ValuePathHelper.format(Arrays.copyOfRange(strings, 1, strings.length));

    String relatedPrimaryKey = metadataTools.getPrimaryKeyName(relatedMetaCLass);
    AbstractCondition condition = getOptimizedCondition(getParentIds(selectedEntities),
            component.getDatasource(), filterComponentName, relatedPrimaryKey, descriptor);

    if (condition == null) {
        condition = getNonOptimizedCondition(relatedMetaCLass, getRelatedIds(selectedEntities, descriptor),
                component, filterComponentName, relatedPrimaryKey);
    }//from www . j  a  v a2 s.c  o  m

    tree.setRootNodes(Collections.singletonList(new Node<>(condition)));

    return filterParser.getXml(tree, Param.ValueProperty.VALUE);
}

From source file:de.cinovo.cloudconductor.api.lib.helper.AbstractApiHandler.java

protected String pathGenerator(String path, String... replace) {
    String[] split = path.split("/");
    if (split.length < 1) {
        return path;
    }//  ww  w .ja v  a2s .  c  om
    StringBuffer buffer = new StringBuffer();
    String[] parts = split;
    if (split[0].isEmpty()) {
        parts = Arrays.copyOfRange(split, 1, split.length);
    }
    int counter = 0;
    for (String part : parts) {
        buffer.append("/");
        if (part.matches(AbstractApiHandler.VAR_PATTERN) && ((replace.length - 1) >= counter)) {
            buffer.append(replace[counter++]);
        } else {
            buffer.append(part);
        }
    }
    return buffer.toString();
}

From source file:com.ebay.nest.io.sede.lazy.LazySimpleSerDe.java

public static SerDeParameters initSerdeParams(Configuration job, Properties tbl, String serdeName)
        throws SerDeException {
    SerDeParameters serdeParams = new SerDeParameters();
    // Read the separators: We use 8 levels of separators by default,
    // and 24 if SERIALIZATION_EXTEND_NESTING_LEVELS is set to true
    // The levels possible are the set of control chars that we can use as
    // special delimiters, ie they should absent in the data or escaped.
    // To increase this level further, we need to stop relying
    // on single control chars delimiters

    serdeParams.separators = new byte[8];
    serdeParams.separators[0] = getByte(
            tbl.getProperty(serdeConstants.FIELD_DELIM, tbl.getProperty(serdeConstants.SERIALIZATION_FORMAT)),
            DefaultSeparators[0]);//from   w w w.  j  av a2 s  . c om
    serdeParams.separators[1] = getByte(tbl.getProperty(serdeConstants.COLLECTION_DELIM), DefaultSeparators[1]);
    serdeParams.separators[2] = getByte(tbl.getProperty(serdeConstants.MAPKEY_DELIM), DefaultSeparators[2]);
    String extendedNesting = tbl.getProperty(SERIALIZATION_EXTEND_NESTING_LEVELS);
    if (extendedNesting == null || !extendedNesting.equalsIgnoreCase("true")) {
        //use the default smaller set of separators for backward compatibility
        for (int i = 3; i < serdeParams.separators.length; i++) {
            serdeParams.separators[i] = (byte) (i + 1);
        }
    } else {
        //If extended nesting is enabled, set the extended set of separator chars

        final int MAX_CTRL_CHARS = 29;
        byte[] extendedSeparators = new byte[MAX_CTRL_CHARS];
        int extendedSeparatorsIdx = 0;

        //get the first 3 separators that have already been set (defaults to 1,2,3)
        for (int i = 0; i < 3; i++) {
            extendedSeparators[extendedSeparatorsIdx++] = serdeParams.separators[i];
        }

        for (byte asciival = 4; asciival <= MAX_CTRL_CHARS; asciival++) {

            //use only control chars that are very unlikely to be part of the string
            // the following might/likely to be used in text files for strings
            // 9 (horizontal tab, HT, \t, ^I)
            // 10 (line feed, LF, \n, ^J),
            // 12 (form feed, FF, \f, ^L),
            // 13 (carriage return, CR, \r, ^M),
            // 27 (escape, ESC, \e [GCC only], ^[).

            //reserving the following values for future dynamic level impl
            // 30
            // 31

            switch (asciival) {
            case 9:
            case 10:
            case 12:
            case 13:
            case 27:
                continue;
            }
            extendedSeparators[extendedSeparatorsIdx++] = asciival;
        }

        serdeParams.separators = Arrays.copyOfRange(extendedSeparators, 0, extendedSeparatorsIdx);
    }

    serdeParams.nullString = tbl.getProperty(serdeConstants.SERIALIZATION_NULL_FORMAT, "\\N");
    serdeParams.nullSequence = new Text(serdeParams.nullString);

    String lastColumnTakesRestString = tbl.getProperty(serdeConstants.SERIALIZATION_LAST_COLUMN_TAKES_REST);
    serdeParams.lastColumnTakesRest = (lastColumnTakesRestString != null
            && lastColumnTakesRestString.equalsIgnoreCase("true"));

    LazyUtils.extractColumnInfo(tbl, serdeParams, serdeName);

    // Create the LazyObject for storing the rows
    serdeParams.rowTypeInfo = TypeInfoFactory.getStructTypeInfo(serdeParams.columnNames,
            serdeParams.columnTypes);

    // Get the escape information
    String escapeProperty = tbl.getProperty(serdeConstants.ESCAPE_CHAR);
    serdeParams.escaped = (escapeProperty != null);
    if (serdeParams.escaped) {
        serdeParams.escapeChar = getByte(escapeProperty, (byte) '\\');
    }
    if (serdeParams.escaped) {
        serdeParams.needsEscape = new boolean[128];
        for (int i = 0; i < 128; i++) {
            serdeParams.needsEscape[i] = false;
        }
        serdeParams.needsEscape[serdeParams.escapeChar] = true;
        for (int i = 0; i < serdeParams.separators.length; i++) {
            serdeParams.needsEscape[serdeParams.separators[i]] = true;
        }
    }

    return serdeParams;
}

From source file:com.axelor.studio.service.data.exporter.ExporterService.java

private void updateDocMap(DataReader reader) {

    String[] keys = reader.getKeys();

    if (keys == null || keys.length == 1) {
        return;/*from   w  w  w. j  a  v  a2s .  c  om*/
    }

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

    for (String key : keys) {

        log.debug("Loading key: {}", key);
        String lastKey = key;

        for (int count = 0; count < reader.getTotalLines(key); count++) {

            String[] row = reader.read(key, count);
            if (row == null) {
                continue;
            }

            if (count == 0) {
                if (row.length > CommonService.HELP) {
                    docMap.put(lastKey, Arrays.copyOfRange(row, CommonService.HELP, row.length));
                }
                continue;
            }

            String name = getFieldName(row);

            String type = row[CommonService.TYPE];
            if (type == null) {
                continue;
            }

            String model = row[CommonService.MODEL];
            if (model != null) {
                model = common.inflector.camelize(model);
            }

            String view = row[CommonService.VIEW];
            if (model != null && view == null) {
                view = ViewLoaderService.getDefaultViewName(model, "form");
            }

            if (updateComment(lastKey, type, row)) {
                continue;
            }

            lastKey = model + "," + view + "," + getFieldType(type) + "," + name;
            if (row.length > CommonService.HELP) {
                docMap.put(lastKey, Arrays.copyOfRange(row, CommonService.HELP, row.length));
            }
        }
    }

}

From source file:bachelorthesis.methods.detection.bayesian.BayesianDetection.java

private double[] copyOfRange(double[] array, int from, int to) {
    return Arrays.copyOfRange(array, from, Math.min(to, array.length));
}

From source file:com.cloudant.sync.datastore.DatastoreSchemaTests.java

private static String j(String... components) {
    String path = components[0];/*ww  w .  j a v a 2 s  . c  om*/
    String[] remainder = Arrays.copyOfRange(components, 1, components.length);
    for (String pathComponent : remainder) {
        path = path + File.separator + pathComponent;
    }
    return path;
}

From source file:com.opengamma.maths.lowlevelapi.datatypes.primitive.CompressedSparseColumnFormatMatrix.java

@Override
public double[] getColumnElements(int index) {
    double[] tmp = new double[_cols];
    int ptr = 0;/*from  w  w  w . j  a v a  2 s . c  om*/
    for (int i = _colPtr[index]; i <= _colPtr[index + 1] - 1; i++) { // loops through elements of correct column
        tmp[ptr] = _values[i];
        ptr++;
    }
    return Arrays.copyOfRange(tmp, 0, ptr);
}

From source file:cn.cnic.bigdatalab.flume.sink.mongodb.EventParser.java

private DBObject populateDocument(DocumentFieldDefinition fd, String document) {
    DBObject dbObject = null;//from   ww w  . j a  va 2s  .  co m
    final String delimiter = fd.getDelimiter();
    if (!StringUtils.isEmpty(delimiter)) {
        String[] documentAsArrray = document.split(Pattern.quote(delimiter));
        dbObject = new BasicDBObject();
        Map<String, FieldDefinition> documentMapping = new LinkedHashMap<String, FieldDefinition>(
                fd.getDocumentMapping());
        int i = 0;
        for (Map.Entry<String, FieldDefinition> documentField : documentMapping.entrySet()) {
            if (DOCUMENT_TYPE.equalsIgnoreCase(documentField.getValue().getType().name())) {
                dbObject.put(documentField.getKey(), parseValue(documentField.getValue(), StringUtils.join(
                        Arrays.copyOfRange(documentAsArrray, i, documentAsArrray.length), fd.getDelimiter())));
                i += ((DocumentFieldDefinition) documentField.getValue()).getDocumentMapping().size();
            } else {
                dbObject.put(documentField.getKey(),
                        parseValue(documentField.getValue(), documentAsArrray[i++]));
            }
        }
    } else {
        throw new MongoSinkException("Delimiter char must be set");
    }

    return dbObject;
}

From source file:bachelorthesis.methods.detection.bayesian.BayesianDetection.java

private double[][] copyOfRange(double[][] array, int from, int to) {
    return Arrays.copyOfRange(array, from, Math.min(to, array.length));
}