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:com.pingtel.sipviewer.SIPViewerFrame.java

protected void applyData(Vector vData) {
    m_model.clear();//www  .jav  a2 s.  com

    if (m_sortBranchNodes) {
        // Do some magic to adjust for the case where the response
        // shows up just before the request.
        SipBranchData current = null;
        SipBranchData previous = null;
        String strCurrentBranchId;
        String strPreviousBranchId;
        for (int i = vData.size() - 1; i > 0; i--) {
            current = (SipBranchData) vData.elementAt(i);
            strCurrentBranchId = current.getThisBranchId();

            previous = (SipBranchData) vData.elementAt(i - 1);
            strPreviousBranchId = current.getThisBranchId();

            if ((strCurrentBranchId != null) && (strCurrentBranchId.length() > 0)
                    && (strPreviousBranchId != null) && (strPreviousBranchId.length() > 0)
                    && (strCurrentBranchId.equals(strPreviousBranchId)) && (current.isRequest())
                    && (!previous.isRequest()) && (current.getMethod() != "ack")) {
                vData.set(i, previous);
                vData.set(i - 1, current);

                System.out.println("Req/Resp swapped for branchID: " + strCurrentBranchId);
            }
        }
    }

    SipBranchData data = null;

    // loop over all the data elements and add them
    // to the model
    for (int i = 0; i < vData.size(); i++) {
        data = (SipBranchData) vData.elementAt(i);

        // pass in the for loop index since it is used
        // to set the displayIndex of each message, this
        // displayIndex is used to determine where the
        // message is displayed vertically and weather
        // it is visible or not (displayIndex of
        // -1 is invisible)
        addEntryToModel(data, i);
    }

    // Reset the scroll bar to the top.
    JScrollBar scroll = m_scrollPane.getVerticalScrollBar();
    scroll.setValue(scroll.getMinimum());

    // Revalidate to make sure the drawing pane is resized to match the
    // data.
    m_body.revalidate();
}

From source file:com.l2jfree.gameserver.handler.admincommands.AdminSortMultisellItems.java

private Vector<L2Item> sortItemsByPrice(Vector<L2Item> items, String[] array) {

    Vector<Integer> itemPrice = new Vector<Integer>();

    for (String string : array) {
        String[] param = string.split(splitting);

        if (param.length != 3)
            continue;

        String itemID = (MULTISELL_ID_SORT) ? param[0] : param[1];

        try {//  w w  w.j a v a  2 s  .  c  om
            L2Item item = ItemTable.getInstance().getTemplate(Integer.valueOf(itemID));
            Integer price = Integer.valueOf(param[2]);

            if (item == null)
                continue;

            itemPrice.add(price);
        }

        catch (Exception e) {
            continue;
        }
    }

    for (int x = 0; x < itemPrice.size() - 1; x++)
        for (int y = x + 1; y < itemPrice.size(); y++) {
            if (itemPrice.get(x) > itemPrice.get(y)) {
                try {
                    //swap integers
                    Integer temp = itemPrice.get(x);
                    itemPrice.set(x, itemPrice.get(y));
                    itemPrice.set(y, temp);
                    //swap items
                    L2Item tempItem = items.get(x);
                    items.set(x, items.get(y));
                    items.set(y, tempItem);
                } catch (Exception e) {
                    continue;
                }
            }
        }

    return items;
}

From source file:webServices.RestServiceImpl.java

public Vector<Layer> parseLayersInfo(String info) {
    Vector<Layer> layersInfo = new Vector<Layer>();
    Vector<String> values = new Vector<String>();

    String val = null;
    String[] data;/*from w  w w.  j  av a 2 s.c om*/
    String[] attr;
    String[] layerInfo = info.split("\\{\"nam");

    //For each layer
    for (int i = 1; i < layerInfo.length; i++) {
        //Initialize values temp variable
        values = new Vector<String>();
        data = layerInfo[i].split("\\$");

        //Attributes of each layer
        for (int j = 0; j < data.length - 1; j++) {
            attr = data[j].split("\":\"");
            if (attr.length > 1) {
                val = attr[1];
            } else {
                val = "";
            }
            if (val.equalsIgnoreCase("")) {
                values.add(null);
            } else {
                values.add(val);
            }
        }

        /**
         * Fix null values
         */
        if (values.get(10) == null) {
            values.set(10, "");
        }

        if (values.get(9) == null) {
            values.set(9, "");
        }

        if (values.get(8) == null) {
            values.set(8, "");
        }

        if (values.get(7) == null) {
            values.set(7, "");
        }

        Layer temp = new Layer(values.get(0), values.get(1), Boolean.parseBoolean(values.get(2)), values.get(3),
                values.get(4), values.get(5), values.get(6), values.get(7), values.get(8), values.get(9),
                values.get(10), values.get(11), values.get(12));

        layersInfo.add(temp);
    }

    return layersInfo;
}

From source file:org.adl.datamodels.ieee.SCORM_2004_DMElement.java

/**
 * Compares the provided value to the value stored in this data model
 * element.//from   w  ww.  jav  a 2  s .  co m
 * 
 * @param iValue A token (<code>RequestToken</code>) object that provides the
 *               value to be compared against the exiting value; this request
 *               may include a set of delimiters.
 * @param iValidate Describes if the value being compared should be
 *                  validated first.
 * 
 * @return An abstract data model error code indicating the result of this
 *         operation.
 */
@Override
public int equals(RequestToken iValue, boolean iValidate) {
    // Assume there is nothing to compare
    int result = DMErrorCodes.COMPARE_NOTHING;

    // Make sure there is something to compare
    if (mValue != null && iValue != null) {
        // Assume these values are equal
        boolean equal = true;

        if (iValidate) {
            // Make sure the value is valid against this element's type
            result = validate(iValue);
        }

        if (result == DMErrorCodes.TYPE_MISMATCH) {
            // An invalid value cannot be equal to any valid (set) data model
            // element.
            equal = false;
        }

        if (equal) {
            int i = 0;

            // If delimiters are defined on this data model element, make sure
            // any provided delimiters are equal, or the existing delimiter
            // value is the default.
            if (mDelimiters != null && mDelimiters.size() > 0) {
                Vector<Boolean> checked = new Vector<Boolean>();

                // Set all delimiters to 'not checked'
                for (int j = 0; j < mDelimiters.size(); j++) {
                    checked.add(false);
                }

                boolean found = true;

                // Compare all delimiters provided with this value
                for (; i < iValue.getDelimiterCount() && equal; i++) {
                    RequestDelimiter del = iValue.getDelimiterAt(i);

                    // Assume this delimiter is not defined for the element
                    found = false;

                    // Check if this element includes the specified delimiter
                    for (int j = 0; j < mDelimiters.size() && equal; j++) {
                        DMDelimiter toCheck = mDelimiters.get(j);

                        if (toCheck.mDescription.mName.equals(del.getName())) {
                            // Make sure we haven't already checked this delimter
                            boolean alreadyChecked = checked.get(j).booleanValue();

                            if (!alreadyChecked) {
                                // Remember we've checked this delimiter
                                found = true;
                                checked.set(j, true);

                                // Check if the value is the delimiter's default
                                if (toCheck.mValue == null) {
                                    if (toCheck.mDescription.mDefault != null) {
                                        // Compare the provided value with the default
                                        if (toCheck.mDescription.mValidator == null) {
                                            equal = equal
                                                    && toCheck.mDescription.mDefault.equals(del.getValue());
                                        } else {
                                            equal = equal && toCheck.mDescription.mValidator.compare(
                                                    toCheck.mDescription.mDefault, del.getValue(), mDelimiters);
                                        }
                                    } else {
                                        equal = false;
                                    }
                                } else {
                                    // Compare the two delimiter values
                                    if (toCheck.mDescription.mValidator == null) {
                                        equal = equal && toCheck.mValue.equals(del.getValue());
                                    } else {
                                        equal = equal && toCheck.mDescription.mValidator.compare(toCheck.mValue,
                                                del.getValue(), mDelimiters);

                                        // If the first compare doesn't work
                                        // test the SPM
                                        if (!equal) {
                                            equal = toCheck.mDescription.mValidator.compare(
                                                    toCheck.mDescription.mValidator.trunc(toCheck.mValue),
                                                    del.getValue(), mDelimiters);
                                        }
                                    }
                                }
                            }

                            break;
                        }
                    }

                    if (!found) {
                        break;
                    }
                }

                if (equal) {
                    // Make sure any delimters not included in the request are 
                    // equal to their defaults
                    for (int j = 0; j < mDelimiters.size() && equal; j++) {
                        boolean check = !checked.get(j).booleanValue();

                        if (check) {
                            DMDelimiter toCheck = mDelimiters.get(j);

                            if (toCheck.mValue != null) {
                                // Compare the current value to the default
                                if (toCheck.mDescription.mValidator != null) {
                                    equal = equal && toCheck.mDescription.mValidator.compare(
                                            toCheck.mDescription.mDefault, toCheck.mValue, mDelimiters);
                                } else {
                                    equal = false;
                                }
                            }
                        }
                    }
                }
            }

            // Only compare the data model values if its delimiters where equal
            if (equal) {

                StringBuilder compareWith = new StringBuilder();

                // Add all 'undefined' delimiters to the validation string
                for (; i < iValue.getDelimiterCount(); i++) {
                    RequestDelimiter del = iValue.getDelimiterAt(i);

                    compareWith.append(del.showDotNotation());
                }

                compareWith.append(iValue.getValue());

                // If no comparison method is defined, just do a string compare
                if (mDescription.mValidator == null) {
                    equal = StringUtils.equals(compareWith.toString(), mValue);
                } else {
                    equal = mDescription.mValidator.compare(compareWith.toString(), mValue, mDelimiters);

                    // If the first compare doesn't work test the SPM
                    if (!equal) {
                        equal = mDescription.mValidator.compare(compareWith.toString(),
                                mDescription.mValidator.trunc(mValue), mDelimiters);
                    }
                }
            }
        }

        // Set the correct result value
        if (equal) {
            result = DMErrorCodes.COMPARE_EQUAL;
        } else {
            result = DMErrorCodes.COMPARE_NOTEQUAL;
        }
    }

    return result;
}

From source file:org.adl.datamodels.ieee.SCORM_2004_DMElement.java

/**
 * Validates a dot-notation token against this data model's defined data
 * type./*from  w w  w  .jav  a 2 s . c  o m*/
 * 
 * @param iValue A token (<code>RequestToken</code>) object that provides
 *               the value to be checked, possibily including a set of
 *               delimiters.
 * 
 * @return An abstract data model error code indicating the result of this
 *         operation.
 */
@Override
public int validate(RequestToken iValue) {

    // Assume no processing errors
    int result = DMErrorCodes.NO_ERROR;

    // Remember where the last 'good' delimiter was located
    int i = 0;

    if (mDelimiters != null && mDelimiters.size() > 0) {
        Vector<Boolean> checked = new Vector<Boolean>();

        // Set all delimiters to 'not checked'
        for (int j = 0; j < mDelimiters.size(); j++) {
            checked.add(false);
        }

        boolean found = true;

        // Validate all delimiters provided with this value
        for (; i < iValue.getDelimiterCount() && found; i++) {
            RequestDelimiter del = iValue.getDelimiterAt(i);

            // Assume this delimiter is not defined for the element
            found = false;

            // Check for invalid whitespace around a 'known' delimiter
            String trim = del.getName(); /* .trim(); */
            boolean ws = trim.length() != del.getName().length();

            // Check if this element includes the specified delimiter
            for (int j = 0; j < mDelimiters.size() && !found; j++) {
                DMDelimiter toCheck = mDelimiters.get(j);

                if (toCheck.mDescription.mName.equals(trim)) {
                    // Make sure we haven't already checked this delimter
                    boolean alreadyChecked = checked.get(j).booleanValue();

                    if (!alreadyChecked) {
                        // If a known delimiter has whitespace, flag the error
                        if (ws) {
                            result = DMErrorCodes.TYPE_MISMATCH;
                            break;
                        } else {
                            // Remember we've checked this delimiter
                            found = true;
                            checked.set(j, true);

                            // Validate the delimiter's value
                            if (toCheck.mDescription.mValidator != null) {
                                result = toCheck.mDescription.mValidator.validate(del.getValue());

                                // If any of the delimiters are invalid, we are done
                                if (result != DMErrorCodes.NO_ERROR) {
                                    break;
                                }
                            }
                        }
                    } else {
                        // We already found this delimiter
                        break;
                    }
                }
            }

            if (result != DMErrorCodes.NO_ERROR) {
                break;
            }
        }

        // If we didn't find this delimiter, move back one in those provided
        if (!found) {
            i--;
        }
    }

    // Validate the value if all of the delimiters are valid
    if (result == DMErrorCodes.NO_ERROR) {
        StringBuilder toValidate = new StringBuilder();

        // Add all 'undefined' delimiters to the validation string
        for (; i < iValue.getDelimiterCount(); i++) {
            RequestDelimiter del = iValue.getDelimiterAt(i);

            toValidate.append(del.showDotNotation());
        }

        // Add the token value to the validation string
        toValidate.append(iValue.getValue());

        if (mDescription.mValidator != null) {
            result = mDescription.mValidator.validate(toValidate.toString());

            if (result == DMErrorCodes.SPM_EXCEEDED) {
                // Type validation SPM Exceeded, create warning.
                String warn = mDescription.mValidator.getTypeName() + " SPM exceeded";

                // Add the SPM Exceeded warning to the message log
                DetailedLogMessageCollection.getInstance()
                        .addMessage(new LogMessage(MessageType.WARNING, warn));

                // Clear this error
                result = DMErrorCodes.NO_ERROR;
            }
        }
    }

    return result;
}

From source file:edu.umn.cs.spatialHadoop.core.RTree.java

/**
 * k nearest neighbor query/*from  w w  w .j  a v a 2 s  .  c  o m*/
 * @param qx
 * @param qy
 * @param k
 * @param output
 */
public int knn(final double qx, final double qy, int k, final ResultCollector2<T, Double> output) {
    double query_area = ((getMBR().x2 - getMBR().x1) * (getMBR().y2 - getMBR().y1)) * k / getElementCount();
    double query_radius = Math.sqrt(query_area / Math.PI);

    boolean result_correct;
    final Vector<Double> distances = new Vector<Double>();
    final Vector<T> shapes = new Vector<T>();
    // Find results in the range and increase this range if needed to ensure
    // correctness of the answer
    do {
        // Initialize result and query range
        distances.clear();
        shapes.clear();
        Rectangle queryRange = new Rectangle();
        queryRange.x1 = qx - query_radius;
        queryRange.y1 = qy - query_radius;
        queryRange.x2 = qx + query_radius;
        queryRange.y2 = qy + query_radius;
        // Retrieve all results in range
        search(queryRange, new ResultCollector<T>() {
            @Override
            public void collect(T shape) {
                distances.add(shape.distanceTo(qx, qy));
                shapes.add((T) shape.clone());
            }
        });
        if (shapes.size() < k) {
            // Didn't find k elements in range, double the range to get more items
            if (shapes.size() == getElementCount()) {
                // Already returned all possible elements
                result_correct = true;
            } else {
                query_radius *= 2;
                result_correct = false;
            }
        } else {
            // Sort items by distance to get the kth neighbor
            IndexedSortable s = new IndexedSortable() {
                @Override
                public void swap(int i, int j) {
                    double temp_distance = distances.elementAt(i);
                    distances.set(i, distances.elementAt(j));
                    distances.set(j, temp_distance);

                    T temp_shape = shapes.elementAt(i);
                    shapes.set(i, shapes.elementAt(j));
                    shapes.set(j, temp_shape);
                }

                @Override
                public int compare(int i, int j) {
                    // Note. Equality is not important to check because items with the
                    // same distance can be ordered anyway. 
                    if (distances.elementAt(i) == distances.elementAt(j))
                        return 0;
                    if (distances.elementAt(i) < distances.elementAt(j))
                        return -1;
                    return 1;
                }
            };
            IndexedSorter sorter = new QuickSort();
            sorter.sort(s, 0, shapes.size());
            if (distances.elementAt(k - 1) > query_radius) {
                result_correct = false;
                query_radius = distances.elementAt(k);
            } else {
                result_correct = true;
            }
        }
    } while (!result_correct);

    int result_size = Math.min(k, shapes.size());
    if (output != null) {
        for (int i = 0; i < result_size; i++) {
            output.collect(shapes.elementAt(i), distances.elementAt(i));
        }
    }
    return result_size;
}

From source file:com.fluidops.iwb.api.ReadDataManagerImpl.java

/**
 * compose a total query result from subresults by dataset variables
* @param datasetValues/*from   w w w . java2 s. co  m*/
 * @param output 
 * @param input 
* @param subResults
 * @param aggType 
* @return
 * @throws QueryEvaluationException 
*/
private Map<Value, Vector<Number>> aggregateSubresults(Value[] datasetValues, String input, String output,
        Map<Value, MutableTupleQueryResult> subResults, AggregationType aggType)
        throws QueryEvaluationException {
    Map<Value, Vector<Number>> totalResult = new HashMap<Value, Vector<Number>>();

    String[] outputAsList = new String[1];
    outputAsList[0] = output;

    for (int i = 0; i < datasetValues.length; i++) {
        MutableTupleQueryResult subResult = subResults.get(datasetValues[i]);
        if (subResult != null) {
            Map<Value, Vector<Number>> subAggregate = aggregateQueryResult(subResult, aggType, input,
                    outputAsList);

            for (Entry<Value, Vector<Number>> entry : subAggregate.entrySet()) {
                Value v = entry.getKey();
                Vector<Number> nv = totalResult.get(v);
                if (nv == null) {
                    // initialize vector of appropriate size (one
                    // entry for each "dataset" value
                    nv = new Vector<Number>();
                    for (int j = 0; j < datasetValues.length; j++)
                        nv.add(null);

                    totalResult.put(v, nv);
                }
                nv.set(i, entry.getValue().get(0)); // field 0 always defined
            }
        }
    }

    return totalResult;
}

From source file:com.ricemap.spateDB.core.RTree.java

/**
 * k nearest neighbor query Note: Current algorithm is approximate just for
 * simplicity. Writing an exact algorithm is on our TODO list
 * /*w  w  w  .  j a v a  2  s .  com*/
 * @param qx
 * @param qy
 * @param k
 * @param output
 */
public int knn(final double qt, final double qx, final double qy, int k,
        final ResultCollector2<T, Double> output) {
    double query_area = ((getMBR().x2 - getMBR().x1) * (getMBR().y2 - getMBR().y1)) * k / getElementCount();
    double query_radius = Math.sqrt(query_area / Math.PI);

    boolean result_correct;
    final Vector<Double> distances = new Vector<Double>();
    final Vector<T> shapes = new Vector<T>();
    // Find results in the range and increase this range if needed to ensure
    // correctness of the answer
    do {
        // Initialize result and query range
        distances.clear();
        shapes.clear();
        Prism queryRange = new Prism();
        queryRange.x1 = qx - query_radius / 2;
        queryRange.y1 = qy - query_radius / 2;
        queryRange.x2 = qx + query_radius / 2;
        queryRange.y2 = qy + query_radius / 2;
        // Retrieve all results in range
        searchColumnar(queryRange, new ResultCollector<Writable>() {
            @Override
            public void collect(Writable shape) {
                distances.add(((T) shape).distanceTo(qt, qx, qy));
                shapes.add((T) ((T) shape).clone());
            }
        }, null);
        if (shapes.size() < k) {
            // Didn't find k elements in range, double the range to get more
            // items
            if (shapes.size() == getElementCount()) {
                // Already returned all possible elements
                result_correct = true;
            } else {
                query_radius *= 2;
                result_correct = false;
            }
        } else {
            // Sort items by distance to get the kth neighbor
            IndexedSortable s = new IndexedSortable() {
                @Override
                public void swap(int i, int j) {
                    double temp_distance = distances.elementAt(i);
                    distances.set(i, distances.elementAt(j));
                    distances.set(j, temp_distance);

                    T temp_shape = shapes.elementAt(i);
                    shapes.set(i, shapes.elementAt(j));
                    shapes.set(j, temp_shape);
                }

                @Override
                public int compare(int i, int j) {
                    // Note. Equality is not important to check because
                    // items with the
                    // same distance can be ordered anyway.
                    if (distances.elementAt(i) < distances.elementAt(j))
                        return -1;
                    return 1;
                }
            };
            IndexedSorter sorter = new QuickSort();
            sorter.sort(s, 0, shapes.size());
            if (distances.elementAt(k - 1) > query_radius) {
                result_correct = false;
                query_radius = distances.elementAt(k);
            } else {
                result_correct = true;
            }
        }
    } while (!result_correct);

    int result_size = Math.min(k, shapes.size());
    if (output != null) {
        for (int i = 0; i < result_size; i++) {
            output.collect(shapes.elementAt(i), distances.elementAt(i));
        }
    }
    return result_size;
}

From source file:com.fluidops.iwb.api.ReadDataManagerImpl.java

@Override
public Map<Value, Vector<Number>> aggregateQueryResult(TupleQueryResult res, AggregationType aggType,
        String input, String[] outputs) throws QueryEvaluationException {

    Map<Value, Vector<Number>> valueMap = new HashMap<Value, Vector<Number>>();
    Map<Value, Vector<Integer>> cntMap = new HashMap<Value, Vector<Integer>>();

    while (res.hasNext()) {
        BindingSet curBindingSet = res.next();

        // the new sesame aggregation mechanism returns unbound values for
        // input if the result set is empty; we just ignore such inputs (bug #6263)
        if (curBindingSet.getBinding(input) == null)
            continue;

        Value value = curBindingSet.getBinding(input).getValue();

        // get the value and count map for the current value
        Vector<Number> curValues = valueMap.get(value);
        Vector<Integer> curCnts = cntMap.get(value);

        // initialize valueMap for value if not used before
        if (curValues == null) {
            curValues = new Vector<Number>();
            for (int i = 0; i < outputs.length; i++) {
                if (aggType == AggregationType.COUNT)
                    curValues.add(0);/*from  w  ww.  j  a v  a2s .c  o  m*/
                else
                    curValues.add(Double.valueOf(0));
            }
            valueMap.put(value, curValues);
        }

        // initialize cntMap for value if not used before
        if (curCnts == null) {
            curCnts = new Vector<Integer>();
            for (int i = 0; i < outputs.length; i++)
                curCnts.add(0);
            cntMap.put(value, curCnts);
        }

        // iterate over output fields
        for (int i = 0; i < outputs.length; i++) {
            // if no aggregation is set, we just remember the value (in
            // case there are several values, we randomly pick one)
            if (aggType == AggregationType.NONE) {
                Binding b = curBindingSet.getBinding(outputs[i]);
                if (b != null)
                    curValues.set(i, (b.getValue() == null) ? null : ((Literal) b.getValue()).doubleValue());
            }
            // COUNT simply counts the number of bound values
            else if (aggType == AggregationType.COUNT) {
                if (curBindingSet.getBinding(outputs[i]) != null)
                    curValues.set(i, curValues.get(i).intValue() + 1);
            }
            // SUM sums up all bound values that cat be cast to double
            else if (aggType == AggregationType.SUM) {
                try {
                    Binding b = curBindingSet.getBinding(outputs[i]);
                    if (b != null)
                        curValues.set(i,
                                curValues.get(i).doubleValue() + ((Literal) b.getValue()).doubleValue());
                } catch (ClassCastException e) {
                    // ignore, sometimes the data is just not clean                                                    
                } catch (NumberFormatException e) {
                    // ignore, sometimes the data is just not clean                            
                }
            }
            // AVG works like sum, but in addition counts the summations
            else if (aggType == AggregationType.AVG) {
                try {
                    Binding b = curBindingSet.getBinding(outputs[i]);
                    if (b != null) {
                        curValues.set(i,
                                curValues.get(i).doubleValue() + ((Literal) b.getValue()).doubleValue());
                        curCnts.set(i, curCnts.get(i).intValue() + 1); // increase couint
                    }
                } catch (ClassCastException e) {
                    // ignore, sometimes the data is just not clean                                                    
                } catch (NumberFormatException e) {
                    // ignore, sometimes the data is just not clean                            
                }
            }
        }
    }

    // valueMap now represents the final result except for the
    // aggregation case, where we have to divide the fields through
    // the respective counts for the values:
    if (aggType == AggregationType.AVG) {
        for (Entry<Value, Vector<Number>> valueEntry : valueMap.entrySet()) {
            Value value = valueEntry.getKey();
            Vector<Number> sums = valueEntry.getValue();
            for (int i = 0; i < sums.size(); i++) {
                Double sum = sums.get(i).doubleValue();
                Integer cnt = cntMap.get(value).get(i);

                if (cnt == 0)
                    valueMap.get(value).set(i, null); // undefined
                else
                    valueMap.get(value).set(i, new Double((((int) (100 * sum / (double) cnt)) / 100.0)));
            }
        }
    }

    return valueMap;
}

From source file:Main.java

/**
 * Method sortVectorRecursive.//from   w  ww.  j  a v a2 s .  c o m
 * @param vector Vector
 * @param getter String
 * @param low double
 * @param high double
 * @param sortDirection int
 * @param caseSensitiveSort boolean
 * @throws Exception
 */
private static void sortVectorRecursive(Vector vector, String getter, double low, double high,
        int sortDirection, boolean caseSensitiveSort) throws Exception {
    Class[] cls = new Class[0];
    Object[] objs = new Object[0];
    Object middleVectorElem = vector.elementAt((int) ((low + high) / 2));
    Method method = null;
    Object middleObject = null;

    if (middleVectorElem != null) {
        method = middleVectorElem.getClass().getMethod(getter, cls);
        middleObject = method.invoke(middleVectorElem, objs);
    }

    Object tmpElement;
    Object compareVectorElem;
    Object compareObject;
    int i = (int) high;
    int j = (int) low;

    Class[] objectClass = new Class[1];
    objectClass[0] = Class.forName("java.lang.Object");
    Class[] stringObjectClass = new Class[1];
    stringObjectClass[0] = Class.forName("java.lang.String");

    Object[] object = new Object[1];
    object[0] = middleObject;
    Object compResult;
    boolean repeatDo;

    do {
        do {
            compareVectorElem = vector.elementAt(j);
            if (compareVectorElem != null) {
                method = compareVectorElem.getClass().getMethod(getter, cls);
                compareObject = method.invoke(compareVectorElem, objs);
                if (compareObject != null) {
                    if (!caseSensitiveSort && compareObject instanceof String && object[0] instanceof String) {
                        method = compareObject.getClass().getMethod("compareToIgnoreCase", stringObjectClass);
                    } else {
                        method = compareObject.getClass().getMethod("compareTo", objectClass);
                    }
                    if (object[0] != null) {
                        compResult = method.invoke(compareObject, object);
                    } else {
                        compResult = new Integer(1);
                    }
                } else {
                    if (object[0] != null) {
                        compResult = new Integer(-1);
                    } else {
                        compResult = new Integer(0);
                    }
                }
            } else {
                if (object[0] != null) {
                    compResult = new Integer(-1);
                } else {
                    compResult = new Integer(0);
                }
            }

            if (((sortDirection == SORT_UP) && (((Integer) compResult).intValue() < 0))
                    || ((sortDirection == SORT_DOWN) && (((Integer) compResult).intValue() > 0))) {
                j++;
                repeatDo = true;
            } else {
                repeatDo = false;
            }
        } while (repeatDo);

        do {
            compareVectorElem = vector.elementAt(i);
            if (compareVectorElem != null) {
                method = compareVectorElem.getClass().getMethod(getter, cls);
                compareObject = method.invoke(compareVectorElem, objs);
                if (compareObject != null) {
                    if (!(caseSensitiveSort) && compareObject instanceof String
                            && object[0] instanceof String) {
                        method = compareObject.getClass().getMethod("compareToIgnoreCase", stringObjectClass);
                    } else {
                        method = compareObject.getClass().getMethod("compareTo", objectClass);
                    }

                    if (object[0] != null) {
                        compResult = method.invoke(compareObject, object);
                    } else {
                        compResult = new Integer(1);
                    }
                } else {
                    if (object[0] != null) {
                        compResult = new Integer(-1);
                    } else {
                        compResult = new Integer(0);
                    }
                }
            } else {
                if (object[0] != null) {
                    compResult = new Integer(-1);
                } else {
                    compResult = new Integer(0);
                }
            }
            if (((sortDirection == SORT_UP) && (((Integer) compResult).intValue() > 0))
                    || ((sortDirection == SORT_DOWN) && (((Integer) compResult).intValue() < 0))) {
                i--;
                repeatDo = true;
            } else {
                repeatDo = false;
            }
        } while (repeatDo);

        if (i >= j) {
            if (i != j) {
                tmpElement = vector.elementAt(i);

                vector.set(i, vector.elementAt(j));
                vector.set(j, tmpElement);
            }

            i--;
            j++;
        }
    } while (j <= i);

    if (low < i) {
        sortVectorRecursive(vector, getter, low, (double) i, sortDirection, caseSensitiveSort);
    }

    if (j < high) {
        sortVectorRecursive(vector, getter, (double) j, high, sortDirection, caseSensitiveSort);
    }
}