Example usage for java.util Vector setSize

List of usage examples for java.util Vector setSize

Introduction

In this page you can find the example usage for java.util Vector setSize.

Prototype

public synchronized void setSize(int newSize) 

Source Link

Document

Sets the size of this vector.

Usage

From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.ChartAxisFactory.java

public static ValueAxis createRangeAxis(RangeAxisConfig rangeAxisConfig, PlotInstance plotInstance)
        throws ChartPlottimeException {
    if (rangeAxisConfig.getValueType() == ValueType.UNKNOWN
            || rangeAxisConfig.getValueType() == ValueType.INVALID) {
        return null;
    } else {/*from w w  w. ja va 2s . co m*/
        RangeAxisData rangeAxisData = plotInstance.getPlotData().getRangeAxisData(rangeAxisConfig);

        double initialUpperBound = rangeAxisData.getUpperViewBound();
        double initialLowerBound = rangeAxisData.getLowerViewBound();

        double upperBound = initialUpperBound;
        double lowerBound = initialLowerBound;

        // fetch old zooming
        LinkAndBrushMaster linkAndBrushMaster = plotInstance.getMasterPlotConfiguration()
                .getLinkAndBrushMaster();
        Range axisZoom = linkAndBrushMaster.getRangeAxisZoom(rangeAxisConfig,
                plotInstance.getCurrentPlotConfigurationClone());

        List<ValueSource> valueSources = rangeAxisConfig.getValueSources();
        if (rangeAxisConfig.hasAbsolutStackedPlot()) {
            for (ValueSource valueSource : valueSources) {
                VisualizationType seriesType = valueSource.getSeriesFormat().getSeriesType();
                if (seriesType == VisualizationType.BARS || seriesType == VisualizationType.AREA) {
                    if (valueSource.getSeriesFormat().getStackingMode() == StackingMode.ABSOLUTE) {
                        Pair<Double, Double> minMax = calculateUpperAndLowerBounds(valueSource, plotInstance);
                        if (upperBound < minMax.getSecond()) {
                            upperBound = minMax.getSecond();
                        }
                        if (lowerBound > minMax.getFirst()) {
                            lowerBound = minMax.getFirst();
                        }
                    }
                }
            }
        }

        double margin = upperBound - lowerBound;
        if (lowerBound == upperBound) {
            margin = lowerBound;
        }
        if (margin == 0) {
            margin = 0.1;
        }

        double normalPad = RangeAxisConfig.padFactor * margin;

        if (rangeAxisConfig.isLogarithmicAxis()) {
            if (!rangeAxisConfig.isUsingUserDefinedLowerViewBound()) {
                lowerBound -= RangeAxisConfig.logPadFactor * lowerBound;
            }
            if (!rangeAxisConfig.isUsingUserDefinedUpperViewBound()) {
                upperBound += RangeAxisConfig.logPadFactor * upperBound;
            }
        } else {
            // add margin
            if (!rangeAxisConfig.isUsingUserDefinedLowerViewBound()) {
                lowerBound -= normalPad;
            }
            if (!rangeAxisConfig.isUsingUserDefinedUpperViewBound()) {
                upperBound += normalPad;
            }
        }

        boolean includeZero = false;
        if (isIncludingZero(rangeAxisConfig, initialLowerBound)
                && !rangeAxisConfig.isUsingUserDefinedLowerViewBound()) {
            // if so set lower bound to zero
            lowerBound = 0.0;
            includeZero = true;
        }

        boolean upToOne = false;
        // if there are only relative plots set upper Bound to 1.0
        if (rangeAxisConfig.mustHaveUpperBoundOne(initialUpperBound)
                && !rangeAxisConfig.isUsingUserDefinedUpperViewBound()) {
            upperBound = 1.0;
            upToOne = true;

        }

        if (includeZero && !upToOne) {
            upperBound *= 1.05;
        }

        String label = rangeAxisConfig.getLabel();
        if (label == null) {
            label = I18N.getGUILabel("plotter.unnamed_value_label");
        }

        ValueAxis rangeAxis;

        if (rangeAxisConfig.getValueType() == ValueType.NOMINAL && !valueSources.isEmpty()) {
            // get union of distinct values of all plotValueConfigs on range axis
            int maxValue = Integer.MIN_VALUE;
            for (ValueSource valueSource : rangeAxisData.getRangeAxisConfig().getValueSources()) {
                ValueSourceData valueSourceData = plotInstance.getPlotData().getValueSourceData(valueSource);
                double maxValueInSource = valueSourceData.getMaxValue();
                if (maxValueInSource > maxValue) {
                    maxValue = (int) maxValueInSource;
                }
            }
            Vector<String> yValueStrings = new Vector<String>(maxValue);
            yValueStrings.setSize(maxValue + 1);
            ValueSourceData valueSourceData = plotInstance.getPlotData()
                    .getValueSourceData(valueSources.get(0));

            for (int i = 0; i <= maxValue; ++i) {
                yValueStrings.set(i, valueSourceData.getStringForValue(SeriesUsageType.MAIN_SERIES, i));
            }
            String[] yValueStringArray = new String[yValueStrings.size()];
            int i = 0;
            for (String s : yValueStrings) {
                yValueStringArray[i] = s;
                ++i;
            }
            CustomSymbolAxis symbolRangeAxis = new CustomSymbolAxis(null, yValueStringArray);
            symbolRangeAxis.setVisible(true);
            symbolRangeAxis.setAutoRangeIncludesZero(false);

            symbolRangeAxis.saveUpperBound(upperBound, initialUpperBound);
            symbolRangeAxis.saveLowerBound(lowerBound, initialLowerBound);

            symbolRangeAxis.setLabel(label);
            Font axesFont = plotInstance.getCurrentPlotConfigurationClone().getAxesFont();
            if (axesFont != null) {
                symbolRangeAxis.setLabelFont(axesFont);
                symbolRangeAxis.setTickLabelFont(axesFont);
            }

            // set range if axis has been zoomed before
            if (axisZoom != null) {
                symbolRangeAxis.setRange(axisZoom);
            }
            rangeAxis = symbolRangeAxis;
        } else if (rangeAxisConfig.getValueType() == ValueType.NUMERICAL) {
            NumberAxis numberRangeAxis;
            if (rangeAxisConfig.isLogarithmicAxis()) {
                if (rangeAxisData.getMinYValue() <= 0) {
                    throw new ChartPlottimeException("log_axis_contains_zero", label);
                }
                numberRangeAxis = new CustomLogarithmicAxis(null);
                ((CustomLogarithmicAxis) numberRangeAxis).saveUpperBound(upperBound, initialUpperBound);
                ((CustomLogarithmicAxis) numberRangeAxis).saveLowerBound(lowerBound, initialLowerBound);
            } else {
                numberRangeAxis = new CustomNumberAxis();
                ((CustomNumberAxis) numberRangeAxis).saveUpperBound(upperBound, initialUpperBound);
                ((CustomNumberAxis) numberRangeAxis).saveLowerBound(lowerBound, initialLowerBound);
            }

            numberRangeAxis.setAutoRangeIncludesZero(false);

            numberRangeAxis.setVisible(true);
            numberRangeAxis.setLabel(label);
            Font axesFont = plotInstance.getCurrentPlotConfigurationClone().getAxesFont();
            if (axesFont != null) {
                numberRangeAxis.setLabelFont(axesFont);
                numberRangeAxis.setTickLabelFont(axesFont);
            }

            // set range if axis has been zoomed before
            if (axisZoom != null) {
                numberRangeAxis.setRange(axisZoom);
            }

            rangeAxis = numberRangeAxis;
        } else if (rangeAxisConfig.getValueType() == ValueType.DATE_TIME) {
            CustomDateAxis dateRangeAxis;
            if (rangeAxisConfig.isLogarithmicAxis()) {
                throw new ChartPlottimeException("logarithmic_not_supported_for_value_type", label,
                        ValueType.DATE_TIME);
            } else {
                dateRangeAxis = new CustomDateAxis();
            }

            dateRangeAxis.saveUpperBound(upperBound, initialUpperBound);
            dateRangeAxis.saveLowerBound(lowerBound, initialLowerBound);

            dateRangeAxis.setVisible(true);
            dateRangeAxis.setLabel(label);
            Font axesFont = plotInstance.getCurrentPlotConfigurationClone().getAxesFont();
            if (axesFont != null) {
                dateRangeAxis.setLabelFont(axesFont);
            }

            // set range if axis has been zoomed before
            if (axisZoom != null) {
                dateRangeAxis.setRange(axisZoom);
            }

            rangeAxis = dateRangeAxis;
        } else {
            throw new RuntimeException("Unknown value type. This should not happen");
        }

        // configure format
        formatAxis(plotInstance.getCurrentPlotConfigurationClone(), rangeAxis);
        return rangeAxis;
    }
}

From source file:edu.umn.cs.spatialHadoop.operations.KNN.java

private static <S extends Shape> long knnLocal(Path inFile, Path outPath, OperationsParams params)
        throws IOException, InterruptedException {
    int iterations = 0;
    FileSystem fs = inFile.getFileSystem(params);
    Point queryPoint = (Point) OperationsParams.getShape(params, "point");
    int k = params.getInt("k", 1);
    // Top-k objects are retained in this object
    PriorityQueue<ShapeWithDistance<S>> knn = new KNNObjects<ShapeWithDistance<S>>(k);

    SpatialInputFormat3<Rectangle, Shape> inputFormat = new SpatialInputFormat3<Rectangle, Shape>();

    final GlobalIndex<Partition> gIndex = SpatialSite.getGlobalIndex(fs, inFile);
    double kthDistance = Double.MAX_VALUE;
    if (gIndex != null) {
        // There is a global index, use it
        PriorityQueue<ShapeWithDistance<Partition>> partitionsToProcess = new PriorityQueue<KNN.ShapeWithDistance<Partition>>() {
            {//ww  w  . j  a  v a 2  s .c  o m
                initialize(gIndex.size());
            }

            @Override
            protected boolean lessThan(Object a, Object b) {
                return ((ShapeWithDistance<Partition>) a).distance < ((ShapeWithDistance<Partition>) b).distance;
            }
        };
        for (Partition p : gIndex) {
            double distance = p.getMinDistanceTo(queryPoint.x, queryPoint.y);
            partitionsToProcess.insert(new ShapeWithDistance<Partition>(p.clone(), distance));
        }

        while (partitionsToProcess.size() > 0 && partitionsToProcess.top().distance <= kthDistance) {

            ShapeWithDistance<Partition> partitionToProcess = partitionsToProcess.pop();
            // Process this partition
            Path partitionPath = new Path(inFile, partitionToProcess.shape.filename);
            long length = fs.getFileStatus(partitionPath).getLen();
            FileSplit fsplit = new FileSplit(partitionPath, 0, length, new String[0]);
            RecordReader<Rectangle, Iterable<Shape>> reader = inputFormat.createRecordReader(fsplit, null);
            if (reader instanceof SpatialRecordReader3) {
                ((SpatialRecordReader3) reader).initialize(fsplit, params);
            } else if (reader instanceof RTreeRecordReader3) {
                ((RTreeRecordReader3) reader).initialize(fsplit, params);
            } else if (reader instanceof HDFRecordReader) {
                ((HDFRecordReader) reader).initialize(fsplit, params);
            } else {
                throw new RuntimeException("Unknown record reader");
            }
            iterations++;

            while (reader.nextKeyValue()) {
                Iterable<Shape> shapes = reader.getCurrentValue();
                for (Shape shape : shapes) {
                    double distance = shape.distanceTo(queryPoint.x, queryPoint.y);
                    if (distance <= kthDistance)
                        knn.insert(new ShapeWithDistance<S>((S) shape.clone(), distance));
                }
            }
            reader.close();

            if (knn.size() >= k)
                kthDistance = knn.top().distance;
        }
    } else {
        // No global index, have to scan the whole file
        Job job = new Job(params);
        SpatialInputFormat3.addInputPath(job, inFile);
        List<InputSplit> splits = inputFormat.getSplits(job);

        for (InputSplit split : splits) {
            RecordReader<Rectangle, Iterable<Shape>> reader = inputFormat.createRecordReader(split, null);
            if (reader instanceof SpatialRecordReader3) {
                ((SpatialRecordReader3) reader).initialize(split, params);
            } else if (reader instanceof RTreeRecordReader3) {
                ((RTreeRecordReader3) reader).initialize(split, params);
            } else if (reader instanceof HDFRecordReader) {
                ((HDFRecordReader) reader).initialize(split, params);
            } else {
                throw new RuntimeException("Unknown record reader");
            }
            iterations++;

            while (reader.nextKeyValue()) {
                Iterable<Shape> shapes = reader.getCurrentValue();
                for (Shape shape : shapes) {
                    double distance = shape.distanceTo(queryPoint.x, queryPoint.y);
                    knn.insert(new ShapeWithDistance<S>((S) shape.clone(), distance));
                }
            }

            reader.close();
        }
        if (knn.size() >= k)
            kthDistance = knn.top().distance;
    }
    long resultCount = knn.size();
    if (outPath != null && params.getBoolean("output", true)) {
        FileSystem outFS = outPath.getFileSystem(params);
        PrintStream ps = new PrintStream(outFS.create(outPath));
        Vector<ShapeWithDistance<S>> resultsOrdered = new Vector<ShapeWithDistance<S>>((int) resultCount);
        resultsOrdered.setSize((int) resultCount);
        while (knn.size() > 0) {
            ShapeWithDistance<S> nextAnswer = knn.pop();
            resultsOrdered.set(knn.size(), nextAnswer);
        }

        Text text = new Text();
        for (ShapeWithDistance<S> answer : resultsOrdered) {
            text.clear();
            TextSerializerHelper.serializeDouble(answer.distance, text, ',');
            answer.shape.toText(text);
            ps.println(text);
        }
        ps.close();
    }
    TotalIterations.addAndGet(iterations);
    return resultCount;

}

From source file:edu.umn.cs.sthadoop.trajectory.KNNDTW.java

private static <S extends Shape> long knnLocal(Path inFile, Path outPath, OperationsParams params)
        throws IOException, InterruptedException {
    int iterations = 0;
    FileSystem fs = inFile.getFileSystem(params);
    Point queryPoint = (Point) OperationsParams.getShape(params, "point");
    int k = params.getInt("k", 1);
    // Top-k objects are retained in this object
    PriorityQueue<ShapeWithDistance<S>> knn = new KNNObjects<ShapeWithDistance<S>>(k);

    SpatialInputFormat3<Rectangle, Shape> inputFormat = new SpatialInputFormat3<Rectangle, Shape>();

    final GlobalIndex<Partition> gIndex = SpatialSite.getGlobalIndex(fs, inFile);
    double kthDistance = Double.MAX_VALUE;
    if (gIndex != null) {
        // There is a global index, use it
        PriorityQueue<ShapeWithDistance<Partition>> partitionsToProcess = new PriorityQueue<KNNDTW.ShapeWithDistance<Partition>>() {
            {/*from w ww  .  j a  v a2 s  .  c om*/
                initialize(gIndex.size());
            }

            @Override
            protected boolean lessThan(Object a, Object b) {
                return ((ShapeWithDistance<Partition>) a).distance < ((ShapeWithDistance<Partition>) b).distance;
            }
        };
        for (Partition p : gIndex) {
            double distance = p.getMinDistanceTo(queryPoint.x, queryPoint.y);
            partitionsToProcess.insert(new ShapeWithDistance<Partition>(p.clone(), distance));
        }

        while (partitionsToProcess.size() > 0 && partitionsToProcess.top().distance <= kthDistance) {

            ShapeWithDistance<Partition> partitionToProcess = partitionsToProcess.pop();
            // Process this partition
            Path partitionPath = new Path(inFile, partitionToProcess.shape.filename);
            long length = fs.getFileStatus(partitionPath).getLen();
            FileSplit fsplit = new FileSplit(partitionPath, 0, length, new String[0]);
            RecordReader<Rectangle, Iterable<Shape>> reader = inputFormat.createRecordReader(fsplit, null);
            if (reader instanceof SpatialRecordReader3) {
                ((SpatialRecordReader3) reader).initialize(fsplit, params);
            } else if (reader instanceof RTreeRecordReader3) {
                ((RTreeRecordReader3) reader).initialize(fsplit, params);
            } else if (reader instanceof HDFRecordReader) {
                ((HDFRecordReader) reader).initialize(fsplit, params);
            } else {
                throw new RuntimeException("Unknown record reader");
            }
            iterations++;

            while (reader.nextKeyValue()) {
                Iterable<Shape> shapes = reader.getCurrentValue();
                for (Shape shape : shapes) {
                    double distance = shape.distanceTo(queryPoint.x, queryPoint.y);
                    if (distance <= kthDistance)
                        knn.insert(new ShapeWithDistance<S>((S) shape.clone(), distance));
                }
            }
            reader.close();

            if (knn.size() >= k)
                kthDistance = knn.top().distance;
        }
    } else {
        // No global index, have to scan the whole file
        Job job = new Job(params);
        SpatialInputFormat3.addInputPath(job, inFile);
        List<InputSplit> splits = inputFormat.getSplits(job);

        for (InputSplit split : splits) {
            RecordReader<Rectangle, Iterable<Shape>> reader = inputFormat.createRecordReader(split, null);
            if (reader instanceof SpatialRecordReader3) {
                ((SpatialRecordReader3) reader).initialize(split, params);
            } else if (reader instanceof RTreeRecordReader3) {
                ((RTreeRecordReader3) reader).initialize(split, params);
            } else if (reader instanceof HDFRecordReader) {
                ((HDFRecordReader) reader).initialize(split, params);
            } else {
                throw new RuntimeException("Unknown record reader");
            }
            iterations++;

            while (reader.nextKeyValue()) {
                Iterable<Shape> shapes = reader.getCurrentValue();
                for (Shape shape : shapes) {
                    double distance = shape.distanceTo(queryPoint.x, queryPoint.y);
                    knn.insert(new ShapeWithDistance<S>((S) shape.clone(), distance));
                }
            }

            reader.close();
        }
        if (knn.size() >= k)
            kthDistance = knn.top().distance;
    }
    long resultCount = knn.size();
    if (outPath != null && params.getBoolean("output", true)) {
        FileSystem outFS = outPath.getFileSystem(params);
        PrintStream ps = new PrintStream(outFS.create(outPath));
        Vector<ShapeWithDistance<S>> resultsOrdered = new Vector<ShapeWithDistance<S>>((int) resultCount);
        resultsOrdered.setSize((int) resultCount);
        while (knn.size() > 0) {
            ShapeWithDistance<S> nextAnswer = knn.pop();
            resultsOrdered.set(knn.size(), nextAnswer);
        }

        Text text = new Text();
        for (ShapeWithDistance<S> answer : resultsOrdered) {
            text.clear();
            TextSerializerHelper.serializeDouble(answer.distance, text, ',');
            answer.shape.toText(text);
            ps.println(text);
        }
        ps.close();
    }
    TotalIterations.addAndGet(iterations);
    return resultCount;

}

From source file:edu.umn.cs.sthadoop.operations.HSPKNNQ.java

private static <S extends Shape> long knnLocal(Path inFile, Path outPath, OperationsParams params)
        throws IOException, InterruptedException {
    int iterations = 0;
    FileSystem fs = inFile.getFileSystem(params);
    Point queryPoint = (Point) OperationsParams.getShape(params, "point");
    int k = params.getInt("k", 1);
    // Top-k objects are retained in this object
    PriorityQueue<ShapeWithDistance<S>> knn = new KNNObjects<ShapeWithDistance<S>>(k);

    SpatialInputFormat3<Rectangle, Shape> inputFormat = new SpatialInputFormat3<Rectangle, Shape>();

    final GlobalIndex<Partition> gIndex = SpatialSite.getGlobalIndex(fs, inFile);
    double kthDistance = Double.MAX_VALUE;
    if (gIndex != null) {
        // There is a global index, use it
        PriorityQueue<ShapeWithDistance<Partition>> partitionsToProcess = new PriorityQueue<HSPKNNQ.ShapeWithDistance<Partition>>() {
            {//from   ww w  .  ja v  a2 s  .  co  m
                initialize(gIndex.size());
            }

            @Override
            protected boolean lessThan(Object a, Object b) {
                return ((ShapeWithDistance<Partition>) a).distance < ((ShapeWithDistance<Partition>) b).distance;
            }
        };
        for (Partition p : gIndex) {
            double distance = p.getMinDistanceTo(queryPoint.x, queryPoint.y);
            partitionsToProcess.insert(new ShapeWithDistance<Partition>(p.clone(), distance));
        }

        while (partitionsToProcess.size() > 0 && partitionsToProcess.top().distance <= kthDistance) {

            ShapeWithDistance<Partition> partitionToProcess = partitionsToProcess.pop();
            // Process this partition
            Path partitionPath = new Path(inFile, partitionToProcess.shape.filename);
            long length = fs.getFileStatus(partitionPath).getLen();
            FileSplit fsplit = new FileSplit(partitionPath, 0, length, new String[0]);
            RecordReader<Rectangle, Iterable<Shape>> reader = inputFormat.createRecordReader(fsplit, null);
            if (reader instanceof SpatialRecordReader3) {
                ((SpatialRecordReader3) reader).initialize(fsplit, params);
            } else if (reader instanceof RTreeRecordReader3) {
                ((RTreeRecordReader3) reader).initialize(fsplit, params);
            } else if (reader instanceof HDFRecordReader) {
                ((HDFRecordReader) reader).initialize(fsplit, params);
            } else {
                throw new RuntimeException("Unknown record reader");
            }
            iterations++;

            while (reader.nextKeyValue()) {
                Iterable<Shape> shapes = reader.getCurrentValue();
                for (Shape shape : shapes) {
                    double distance = shape.distanceTo(queryPoint.x, queryPoint.y);
                    if (distance <= kthDistance)
                        knn.insert(new ShapeWithDistance<S>((S) shape.clone(), distance));
                }
            }
            reader.close();

            if (knn.size() >= k)
                kthDistance = knn.top().distance;
        }
    } else {
        // No global index, have to scan the whole file
        Job job = new Job(params);
        SpatialInputFormat3.addInputPath(job, inFile);
        List<InputSplit> splits = inputFormat.getSplits(job);

        for (InputSplit split : splits) {
            RecordReader<Rectangle, Iterable<Shape>> reader = inputFormat.createRecordReader(split, null);
            if (reader instanceof SpatialRecordReader3) {
                ((SpatialRecordReader3) reader).initialize(split, params);
            } else if (reader instanceof RTreeRecordReader3) {
                ((RTreeRecordReader3) reader).initialize(split, params);
            } else if (reader instanceof HDFRecordReader) {
                ((HDFRecordReader) reader).initialize(split, params);
            } else {
                throw new RuntimeException("Unknown record reader");
            }
            iterations++;

            while (reader.nextKeyValue()) {
                Iterable<Shape> shapes = reader.getCurrentValue();
                for (Shape shape : shapes) {
                    double distance = shape.distanceTo(queryPoint.x, queryPoint.y);
                    knn.insert(new ShapeWithDistance<S>((S) shape.clone(), distance));
                }
            }

            reader.close();
        }
        if (knn.size() >= k)
            kthDistance = knn.top().distance;
    }
    long resultCount = knn.size();
    if (outPath != null && params.getBoolean("output", true)) {
        FileSystem outFS = outPath.getFileSystem(params);
        PrintStream ps = new PrintStream(outFS.create(outPath));
        Vector<ShapeWithDistance<S>> resultsOrdered = new Vector<ShapeWithDistance<S>>((int) resultCount);
        resultsOrdered.setSize((int) resultCount);
        while (knn.size() > 0) {
            ShapeWithDistance<S> nextAnswer = knn.pop();
            resultsOrdered.set(knn.size(), nextAnswer);
        }

        Text text = new Text();
        for (ShapeWithDistance<S> answer : resultsOrdered) {
            text.clear();
            TextSerializerHelper.serializeDouble(answer.distance, text, ',');
            answer.shape.toText(text);
            ps.println(text);
        }
        ps.close();
    }
    TotalIterations.addAndGet(iterations);
    return resultCount;

}

From source file:org.opentestsystem.airose.linear.Matrix.java

@SuppressWarnings("rawtypes")
public Vector getRowVector(int row) {
    Vector<Double> vector = new Vector<Double>();
    vector.setSize(columns());
    for (int i = 0; i < columns(); i++) {
        vector.set(i, _matrix.getEntry(row, i));
    }//from w w w .  j a v  a  2  s.c  om
    return vector;
}

From source file:com.eviware.soapui.impl.wsdl.support.wss.IncomingWss.java

public Vector<Object> processIncoming(Document soapDocument, PropertyExpansionContext context)
        throws WSSecurityException {
    Element header = WSSecurityUtil.findWsseSecurityHeaderBlock(soapDocument, soapDocument.getDocumentElement(),
            false);//from w  w  w  . j a  v a 2s  . c  om
    if (header == null)
        return null;

    try {
        WSSecurityEngine wssecurityEngine = new WSSecurityEngine();
        WssCrypto signatureCrypto = getWssContainer().getCryptoByName(getSignatureCrypto());
        WssCrypto decryptCrypto = getWssContainer().getCryptoByName(getDecryptCrypto());
        Crypto sig = signatureCrypto == null ? null : signatureCrypto.getCrypto();
        Crypto dec = decryptCrypto == null ? null : decryptCrypto.getCrypto();

        if (sig == null && dec == null)
            throw new WSSecurityException("Missing cryptos");

        if (sig == null)
            sig = dec;
        else if (dec == null)
            dec = sig;

        List<WSSecurityEngineResult> incomingResult = wssecurityEngine.processSecurityHeader(soapDocument,
                (String) null, new WSSCallbackHandler(dec), sig, dec);

        Vector<Object> wssResult = new Vector<Object>();
        wssResult.setSize(incomingResult.size());
        Collections.copy(wssResult, incomingResult);
        return wssResult;

    } catch (WSSecurityException e) {
        SoapUI.logError(e);
        throw e;
    }
}

From source file:org.apache.axis.encoding.ser.VectorDeserializer.java

/**
 * The registerValueTarget code above causes this set function to be invoked when
 * each value is known.//  ww w .  j  a  v  a  2s.  co m
 * @param value is the value of an element
 * @param hint is an Integer containing the index
 */
public void setChildValue(Object value, Object hint) throws SAXException {
    if (log.isDebugEnabled()) {
        log.debug(Messages.getMessage("gotValue00", "VectorDeserializer", "" + value));
    }
    int offset = ((Integer) hint).intValue();
    Vector v = (Vector) this.value;

    // If the vector is too small, grow it 
    if (offset >= v.size()) {
        v.setSize(offset + 1);
    }
    v.setElementAt(value, offset);
}

From source file:net.java.sen.tools.DictionaryMaker.java

int getIdList(String csv[], Vector result, int parent) {
    result.setSize(ruleList.size());

    for (int j = 0; j < ruleList.size(); j++)
        result.set(j, new Integer(j));
    //    System.out.println("in:ruleList.size()=" + ruleList.size());
    //    System.out.println("ruleList size="+ruleList.size());
    //    System.out.println("result size="+result.size());
    //    pass/*  w ww .  j av a 2s. com*/

    for (int j = 0; j < csv.length; j++) {
        int k = 0;
        for (int n = 0; n < result.size(); n++) {
            int i = ((Integer) result.get(n)).intValue();
            String rl_ij = ((String[]) ruleList.get(i))[j];
            if ((parent == 0 && csv[j].charAt(0) == '*') || (parent == 1 && rl_ij.charAt(0) == '*')
                    || rl_ij.equals(csv[j])) {

                result.set(k++, result.get(n));
            }
        }
        result.setSize(k);
    }
    return result.size();
}

From source file:edu.brown.utils.UniqueCombinationIterator.java

/**
 * Find the next unique combination/* www.ja va  2 s.co  m*/
 */
private void getNext() {
    assert (this.next == null);
    final boolean trace = LOG.isTraceEnabled();
    final boolean debug = LOG.isDebugEnabled();

    if (debug)
        LOG.debug("Finding next combination [call=" + (this.attempt_ctr++) + "]");

    boolean valid = false;
    Vector<Integer> buffer = null;
    for (int i = this.last.get(0); i < this.num_elements; i++) {
        if (trace)
            LOG.trace("\n" + this);

        buffer = new Vector<Integer>();
        buffer.setSize(this.combo_size);
        buffer.set(0, i);

        // We have a new combination!
        if (this.calculateCombinations(buffer, 1)) {
            if (trace)
                LOG.trace("Found new combination: " + buffer);
            valid = true;
            break;
        }
        if (trace)
            LOG.trace("No combination found that starts with index #" + i);
        buffer = null;
        this.initializeLast(i + 1);
    } // FOR

    if (trace)
        LOG.trace("VALID = " + valid);
    if (valid) {
        assert (this.combo_size == buffer.size());
        this.next = new ListOrderedSet<E>();
        for (int i = 0; i < this.combo_size; i++) {
            this.next.add(this.data.get(buffer.get(i)));
        } // FOR
        if (trace)
            LOG.trace("NEXT = " + this.next);

        // Increase the last position's counter so that it is different next
        // time
        this.last.set(this.combo_size - 1, this.last.lastElement() + 1);
        if (trace)
            LOG.trace("NEW LAST = " + this.last);

        this.finished = false;
    } else {
        this.finished = true;
    }
}

From source file:de.bund.bfr.knime.node.editableTable.JSONDataTable.java

/**
 * Creates a new data table which can be serialized into a JSON string from a given BufferedDataTable.
 * @param dTable the data table to read the rows from
 * @param firstRow the first row to store (must be greater than zero)
 * @param maxRows the number of rows to store (must be zero or more)
 * @param excludeColumns a list of columns to exclude
 * @param execMon the object listening to our progress and providing cancel functionality.
 * @throws CanceledExecutionException If the execution of the node has been cancelled.
 *///  w ww .  jav  a2s.  c  o  m
public JSONDataTable(final DataTable dTable, final int firstRow, final int maxRows,
        final String[] excludeColumns, final ExecutionMonitor execMon) throws CanceledExecutionException {

    if (dTable == null) {
        throw new NullPointerException("Must provide non-null data table" + " for DataArray");
    }
    if (firstRow < 1) {
        throw new IllegalArgumentException("Starting row must be greater" + " than zero");
    }
    if (maxRows < 0) {
        throw new IllegalArgumentException("Number of rows to read must be" + " greater than or equal zero");
    }

    int numOfColumns = 0;
    ArrayList<Integer> includeColIndices = new ArrayList<Integer>();
    DataTableSpec spec = dTable.getDataTableSpec();
    for (int i = 0; i < spec.getNumColumns(); i++) {
        String colName = spec.getColumnNames()[i];
        if (!Arrays.asList(excludeColumns).contains(colName)) {
            includeColIndices.add(i);
            numOfColumns++;
        }
    }
    long numOfRows = maxRows;
    if (dTable instanceof BufferedDataTable) {
        numOfRows = Math.min(((BufferedDataTable) dTable).size(), maxRows);
    }

    //int numOfColumns = spec.getNumColumns();
    DataCell[] maxValues = new DataCell[numOfColumns];
    DataCell[] minValues = new DataCell[numOfColumns];
    Object[] minJSONValues = new Object[numOfColumns];
    Object[] maxJSONValues = new Object[numOfColumns];

    // create a new list for the values - but only for native string columns
    Vector<LinkedHashSet<Object>> possValues = new Vector<LinkedHashSet<Object>>();
    possValues.setSize(numOfColumns);
    for (int c = 0; c < numOfColumns; c++) {
        if (spec.getColumnSpec(includeColIndices.get(c)).getType().isCompatible(NominalValue.class)) {
            possValues.set(c, new LinkedHashSet<Object>());
        }
    }

    RowIterator rIter = dTable.iterator();
    int currentRowNumber = 0;
    int numRows = 0;

    ArrayList<String> rowColorList = new ArrayList<String>();
    ArrayList<JSONDataTableRow> rowList = new ArrayList<JSONDataTableRow>();

    while ((rIter.hasNext()) && (currentRowNumber + firstRow - 1 < maxRows)) {
        // get the next row
        DataRow row = rIter.next();
        currentRowNumber++;

        if (currentRowNumber < firstRow) {
            // skip all rows until we see the specified first row
            continue;
        }

        String rC = CSSUtils.cssHexStringFromColor(spec.getRowColor(row).getColor());
        rowColorList.add(rC);

        String rowKey = row.getKey().getString();
        rowList.add(new JSONDataTableRow(rowKey, numOfColumns));
        numRows++;

        // add cells, check min, max values and possible values for each column
        for (int c = 0; c < numOfColumns; c++) {
            int col = includeColIndices.get(c);
            DataCell cell = row.getCell(col);

            Object cellValue;
            if (!cell.isMissing()) {
                cellValue = getJSONCellValue(cell);
            } else {
                cellValue = null;
            }

            rowList.get(currentRowNumber - firstRow).getData()[c] = cellValue;
            if (cellValue == null) {
                continue;
            }

            DataValueComparator comp = spec.getColumnSpec(col).getType().getComparator();

            // test the min value
            if (minValues[c] == null) {
                minValues[c] = cell;
                minJSONValues[c] = getJSONCellValue(cell);
            } else {
                if (comp.compare(minValues[c], cell) > 0) {
                    minValues[c] = cell;
                    minJSONValues[c] = getJSONCellValue(cell);
                }
            }
            // test the max value
            if (maxValues[c] == null) {
                maxValues[c] = cell;
                maxJSONValues[c] = getJSONCellValue(cell);
            } else {
                if (comp.compare(maxValues[c], cell) < 0) {
                    maxValues[c] = cell;
                    maxJSONValues[c] = getJSONCellValue(cell);
                }
            }
            // add it to the possible values if we record them for this col
            LinkedHashSet<Object> possVals = possValues.get(c);
            if (possVals != null) {
                // non-string cols have a null list and will be skipped here
                possVals.add(getJSONCellValue(cell));
            }
        }
        if (execMon != null) {
            execMon.setProgress(((double) currentRowNumber - firstRow) / numOfRows,
                    "Creating JSON table. Processing row " + (currentRowNumber - firstRow) + " of "
                            + numOfRows);
        }
    }

    // TODO: Add extensions (color, shape, size, inclusion, selection, hiliting, ...)
    Object[][] extensionArray = null;

    JSONDataTableSpec jsonTableSpec = new JSONDataTableSpec(spec, excludeColumns, numRows);
    jsonTableSpec.setMinValues(minJSONValues);
    jsonTableSpec.setMaxValues(maxJSONValues);
    jsonTableSpec.setPossibleValues(possValues);

    setSpec(jsonTableSpec);
    getSpec().setRowColorValues(rowColorList.toArray(new String[0]));
    setRows(rowList.toArray(new JSONDataTableRow[0]));
    setExtensions(extensionArray);
}