Example usage for java.util Vector set

List of usage examples for java.util Vector set

Introduction

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

Prototype

public synchronized E set(int index, E element) 

Source Link

Document

Replaces the element at the specified position in this Vector with the specified element.

Usage

From source file:Main.java

public static void main(String[] args) {
    Vector<String> v = new Vector<String>();
    v.add("1");/*from w ww .jav a2 s .c  o  m*/
    v.add("2");
    v.add("3");

    v.set(1, "REPLACED ELEMENT");

    for (String str : v) {
        System.out.println(str);
    }
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    DefaultTableModel model = new DefaultTableModel();
    JTable table = new JTable(model);
    model.addColumn("Col1");
    model.addRow(new Object[] { "r1" });
    model.addRow(new Object[] { "r2" });
    model.addRow(new Object[] { "r3" });

    Vector data = model.getDataVector();
    Vector row = (Vector) data.elementAt(1);
    // Overwrite the first row with the copy
    Vector firstRow = (Vector) data.elementAt(0);
    for (int i = 0; i < row.size(); i++) {
        firstRow.set(i, row.get(i));
    }/*w  w  w . j a v  a2s.c  om*/

    JFrame f = new JFrame();
    f.setSize(300, 300);
    f.add(new JScrollPane(table));
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {

    Vector<Integer> vec = new Vector<Integer>(4);

    vec.add(4);/*w  w  w  .j a  v  a2s. c  o  m*/
    vec.add(3);
    vec.add(2);
    vec.add(1);

    // set 15 at 2nd index position
    vec.set(2, 15);

    for (Integer number : vec) {
        System.out.println("Number = " + number);
    }
}

From source file:Main.java

public static void main(String args[]) {
    Vector<Object> v = new Vector<Object>(5);
    for (int i = 0; i < 10; i++) {
        v.add(0, i);/*from   w w w  .j  av a2  s.  co  m*/
    }
    System.out.println(v);

    for (int i = 0; i < 10; i++) {
        v.set(i, "A");
    }

    System.out.println(v);
}

From source file:VectorBenchmark1.java

public static void main(String[] args) {
    Vector v = new Vector();

    long start = System.currentTimeMillis();
    for (int i = 0; i < MaxSize; i++)
        v.add(new Integer(i));
    long end = System.currentTimeMillis();
    System.out.println("Allocating vector elements: " + (end - start) + " milliseconds");

    Integer[] integerArray = new Integer[1];
    start = System.currentTimeMillis();
    for (int i = 0; i < MaxSize; i++) {
        if (i >= integerArray.length) {
            Integer[] b = new Integer[i * 2];
            System.arraycopy(integerArray, 0, b, 0, integerArray.length);
            integerArray = b;/*from  w w  w .j a v a2s  .co  m*/
        }
        integerArray[i] = new Integer(i);
    }
    end = System.currentTimeMillis();
    System.out.println("Allocating array elements:  " + (end - start) + " milliseconds");

    start = System.currentTimeMillis();
    for (int j = 0; j < NTRIES; j++)
        for (int i = 0; i < MaxSize; i++) {
            Integer r = (Integer) v.get(i);
            v.set(i, new Integer(r.intValue() + 1));
        }
    end = System.currentTimeMillis();
    System.out.println("Accessing vector elements:  " + (end - start) + " milliseconds");

    start = System.currentTimeMillis();
    for (int j = 0; j < NTRIES; j++)
        for (int i = 0; i < MaxSize; i++) {
            Integer r = integerArray[i];
            integerArray[i] = new Integer(r.intValue() + 1);
        }
    end = System.currentTimeMillis();
    System.out.println("Accessing array elements:   " + (end - start) + " milliseconds");
}

From source file:edu.umn.cs.sthadoop.hdfs.KNNJoin.java

public static <S extends Shape> Vector<ShapeWithDistance<S>> orderResults(
        KNNObjects<ShapeWithDistance<S>, S> knn) {
    Vector<ShapeWithDistance<S>> resultsOrdered = new Vector<ShapeWithDistance<S>>();
    // double KthDistance = knn.top().distance;
    resultsOrdered.setSize(knn.size());//from w  w  w  .  j a  v  a  2s.c o  m
    while (knn.size() > 0) {
        ShapeWithDistance<S> nextAnswer = knn.pop();
        resultsOrdered.set(knn.size(), nextAnswer);
    }
    return resultsOrdered;
}

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  2 s .  c om*/
        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>>() {
            {//from   w  ww .  j  av  a  2s  .  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.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>>() {
            {//  w w  w. j av  a 2 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  .j ava 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;

}