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:org.trustedanalytics.atk.giraph.io.titan.formats.TitanVertexBuilder.java

/**
 * Update vector values using Titan property value
 *
 * @param vector Mahout vector/*  ww w.j  av a 2  s.  c o m*/
 * @param titanProperty Titan property
 * @return Updated Mahout vector
 */
public org.apache.mahout.math.Vector setVector(org.apache.mahout.math.Vector vector,
        TitanProperty titanProperty) {
    Object vertexValueObject = titanProperty.getValue();
    if (enableVectorValue) {
        //one property key has a vector as value
        //split by either space or comma or tab
        String[] valueString = vertexValueObject.toString().split(regexp);
        int size = valueString.length;
        double[] data = new double[size];
        vector = new DenseVector(data);
        for (int i = 0; i < valueString.length; i++) {
            vector.set(i, Double.parseDouble(valueString[i]));
        }
    } else {
        String propertyName = titanProperty.getPropertyKey().getName();
        int propertyIndex = vertexValuePropertyKeys.get(propertyName);
        double vertexValue = Double.parseDouble(vertexValueObject.toString());
        vector.set(propertyIndex, vertexValue);
    }
    return vector;
}

From source file:com.vangent.hieos.logbrowser.servlets.GetTableServlet.java

/**
 *
 * @param column/*  w ww  .  j a  va2  s. co m*/
 * @param sortingStatus
 * @return
 */
private String toJSon(int column, int sortingStatus) {
    try {
        JSONObject response = new JSONObject();
        JSONObject content = new JSONObject();
        JSONArray array = new JSONArray();
        if (column == -1 || sortingStatus == -2) {
            array.put(tableModel.getHeaderVector());
        } else if (column > -1 && sortingStatus > -2 && sortingStatus < 2 /*-1,0 or 1 */) {
            Vector<String> vectorCopy = (Vector<String>) tableModel.getHeaderVector().clone();
            for (int header = 0; header < tableModel.getHeaderVector().size(); header++) {
                if (header == column) {
                    switch (sortingStatus) {
                    case -1:
                        vectorCopy.set(header, vectorCopy.elementAt(header) + " &#8595;");
                        break;
                    case 0:
                        vectorCopy.set(header, vectorCopy.elementAt(header) + " &#8593;&#8595;");
                        break;
                    case 1:
                        vectorCopy.set(header, vectorCopy.elementAt(header) + " &#8593;");
                        break;
                    }
                }
            }
            array.put(vectorCopy);
        }
        for (int row = 0; row < tableModel.getDataVector().size(); row++) {
            array.put((Vector<Object>) tableModel.getDataVector().get(row));
        }
        content.put("table", array);
        content.put("isAdmin", new Boolean(isAdmin).toString());
        response.put("result", content);
        return response.toString();
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}

From source file:org.openmicroscopy.shoola.agents.fsimporter.chooser.FileSelectionTable.java

/**
 * Adds the collection of files to the queue.
 * //from  ww  w . j  a  v  a  2s  .  co m
 * @param files The files to add.
 * @param settings The import settings.
 */
void addFiles(List<FileObject> files, ImportLocationSettings settings) {
    if (CollectionUtils.isEmpty(files))
        return;
    boolean fad = settings.isParentFolderAsDataset();
    GroupData group = settings.getImportGroup();
    ExperimenterData user = settings.getImportUser();
    enabledControl(true);

    DefaultTableModel dtm = (DefaultTableModel) table.getModel();
    //Check if the file has already 
    List<FileElement> inQueue = new ArrayList<FileElement>();
    FileElement element;
    for (int i = 0; i < table.getRowCount(); i++) {
        element = (FileElement) dtm.getValueAt(i, this.fileIndex);
        inQueue.add(element);
    }
    Iterator<FileObject> i = files.iterator();
    DataNode node = settings.getImportLocation();
    if (model.getType() != Importer.SCREEN_TYPE)
        node.setParent(settings.getParentImportLocation());
    String value = null;
    boolean v;
    long gID = group.getId();
    FileObject f;
    while (i.hasNext()) {
        f = i.next();
        if (allowAddToQueue(inQueue, f, gID, user.getId())) {
            element = new FileElement(f, model.getType(), group, user);
            element.setName(f.getName());
            inQueue.add(element);
            value = null;
            v = false;
            value = f.getFolderAsContainerName();
            if (f.isDirectory()) {
                v = fad;
                if (model.getType() == Importer.SCREEN_TYPE) {
                    value = null;
                }
            } else {
                if (fad) {
                    v = true;
                    element.setToggleContainer(v);
                }
            }

            final Vector<Object> row = new Vector<Object>();
            row.setSize(this.columnHeadings.size());

            if (this.fileIndex != null) {
                row.set(this.fileIndex, element);
            }
            if (this.groupIndex != null) {
                row.set(this.groupIndex, group.getName());
            }
            if (this.ownerIndex != null) {
                row.set(this.ownerIndex, user.getUserName());
            }
            if (this.containerIndex != null) {
                row.set(this.containerIndex, new DataNodeElement(node, value));
            }
            if (this.folderAsDatasetIndex != null) {
                row.set(this.folderAsDatasetIndex, v);
            }
            if (this.sizeIndex != null) {
                row.set(this.sizeIndex, element.getFileLengthAsString());
            }
            dtm.addRow(row);
        }
    }
    model.onSelectionChanged();
}

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.
 *//*from  w  w w .  j  a  va2  s . 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);
}

From source file:org.smilec.smile.student.HttpMsgForStudent.java

public Vector<Integer> jsonarraytovector(JSONArray _arrayname) {

    Vector<Integer> vectorarray = null;
    vectorarray = new Vector<Integer>();

    for (int i = 0; i < _arrayname.length(); i++) {
        try {/*from   www .  j a va  2 s . c o  m*/
            if (_arrayname.get(i) == null)
                vectorarray.set(i, 0);
            else
                vectorarray.set(i, (Integer) _arrayname.get(i));
        } catch (JSONException e) {
            Log.i(APP_TAG, "Transition error: JSONArray to Vector");
            e.printStackTrace();
        }
    }

    return vectorarray;
}

From source file:de.blinkt.openvpn.core.ConfigParser.java

public void parseConfig(Reader reader) throws IOException, ConfigParseError {

    HashMap<String, String> optionAliases = new HashMap<>();
    optionAliases.put("server-poll-timeout", "timeout-connect");

    BufferedReader br = new BufferedReader(reader);

    int lineno = 0;
    try {/*from  www  .  j ava2s. co  m*/
        while (true) {
            String line = br.readLine();
            lineno++;
            if (line == null)
                break;

            if (lineno == 1) {
                if ((line.startsWith("PK\003\004") || (line.startsWith("PK\007\008")))) {
                    throw new ConfigParseError(
                            "Input looks like a ZIP Archive. Import is only possible for OpenVPN config files (.ovpn/.conf)");
                }
                if (line.startsWith("\uFEFF")) {
                    line = line.substring(1);
                }
            }

            // Check for OpenVPN Access Server Meta information
            if (line.startsWith("# OVPN_ACCESS_SERVER_")) {
                Vector<String> metaarg = parsemeta(line);
                meta.put(metaarg.get(0), metaarg);
                continue;
            }
            Vector<String> args = parseline(line);

            if (args.size() == 0)
                continue;

            if (args.get(0).startsWith("--"))
                args.set(0, args.get(0).substring(2));

            checkinlinefile(args, br);

            String optionname = args.get(0);
            if (optionAliases.get(optionname) != null)
                optionname = optionAliases.get(optionname);

            if (!options.containsKey(optionname)) {
                options.put(optionname, new Vector<Vector<String>>());
            }
            options.get(optionname).add(args);
        }
    } catch (OutOfMemoryError memoryError) {
        throw new ConfigParseError("File too large to parse: " + memoryError.getLocalizedMessage());
    }
}

From source file:edu.umn.cs.spatialHadoop.nasa.StockQuadTree.java

/**
 * Perform a selection query that retrieves all points in the given range.
 * The range is specified in the two-dimensional array positions.
 * @param in/*from  www  . j  av  a  2 s  .c  o  m*/
 * @param query_mbr
 * @param output
 * @return number of matched records
 * @throws IOException
 */
public static int selectionQuery(FSDataInputStream in, Rectangle query_mbr, ResultCollector<PointValue> output)
        throws IOException {
    long treeStartPosition = in.getPos();
    int numOfResults = 0;
    int resolution = in.readInt();
    short fillValue = in.readShort();
    int cardinality = in.readInt();
    long[] timestamps = new long[cardinality];
    for (int i = 0; i < cardinality; i++)
        timestamps[i] = in.readLong();
    Vector<Integer> selectedStarts = new Vector<Integer>();
    Vector<Integer> selectedEnds = new Vector<Integer>();
    StockQuadTree stockQuadTree = getOrCreateStockQuadTree(resolution);
    // Nodes to be searched. Contains node positions in the array of nodes
    Stack<Integer> nodes_2b_searched = new Stack<Integer>();
    nodes_2b_searched.add(0); // Root node (ID=1)
    Rectangle node_mbr = new Rectangle();
    while (!nodes_2b_searched.isEmpty()) {
        int node_pos = nodes_2b_searched.pop();
        stockQuadTree.getNodeMBR(node_pos, node_mbr);
        if (query_mbr.contains(node_mbr)) {
            // Add this node to the selection list and stop this branch
            if (!selectedEnds.isEmpty()
                    && selectedEnds.lastElement() == stockQuadTree.nodesStartPosition[node_pos]) {
                // Merge with an adjacent range
                selectedEnds.set(selectedEnds.size() - 1, stockQuadTree.nodesEndPosition[node_pos]);
            } else {
                // add a new range
                selectedStarts.add(stockQuadTree.nodesStartPosition[node_pos]);
                selectedEnds.add(stockQuadTree.nodesEndPosition[node_pos]);
            }
            numOfResults += stockQuadTree.nodesEndPosition[node_pos]
                    - stockQuadTree.nodesStartPosition[node_pos];
        } else if (query_mbr.intersects(node_mbr)) {
            int first_child_id = stockQuadTree.nodesID[node_pos] * 4 + 0;
            int first_child_pos = Arrays.binarySearch(stockQuadTree.nodesID, first_child_id);
            if (first_child_pos < 0) {
                // No children. Hit a leaf node
                // Scan and add matching points only
                java.awt.Point record_coords = new Point();
                for (int record_pos = stockQuadTree.nodesStartPosition[node_pos]; record_pos < stockQuadTree.nodesEndPosition[node_pos]; record_pos++) {
                    stockQuadTree.getRecordCoords(record_pos, record_coords);
                    if (query_mbr.contains(record_coords)) {
                        // matched a record.
                        if (!selectedEnds.isEmpty() && selectedEnds.lastElement() == record_pos) {
                            // Merge with an adjacent range
                            selectedEnds.set(selectedEnds.size() - 1, record_pos + 1);
                        } else {
                            // Add a new range of unit width
                            selectedStarts.add(record_pos);
                            selectedEnds.add(record_pos + 1);
                        }
                        numOfResults++;
                    }
                }
            } else {
                // Non-leaf node. Add all children to the list of nodes to search
                // Add in reverse order to the stack so that results come in sorted order
                nodes_2b_searched.add(first_child_pos + 3);
                nodes_2b_searched.add(first_child_pos + 2);
                nodes_2b_searched.add(first_child_pos + 1);
                nodes_2b_searched.add(first_child_pos + 0);
            }
        }
    }
    if (output != null) {
        PointValue returnValue = new PointValue();
        long dataStartPosition = treeStartPosition + getValuesStartOffset(cardinality);
        // Return all values in the selected ranges
        for (int iRange = 0; iRange < selectedStarts.size(); iRange++) {
            int treeStart = selectedStarts.get(iRange);
            int treeEnd = selectedEnds.get(iRange);
            long startPosition = dataStartPosition + selectedStarts.get(iRange) * cardinality * 2;
            in.seek(startPosition);
            for (int treePos = treeStart; treePos < treeEnd; treePos++) {
                // Retrieve the coords for the point at treePos
                stockQuadTree.getRecordCoords(treePos, returnValue);
                // Read all entries at current position
                for (int iValue = 0; iValue < cardinality; iValue++) {
                    short value = in.readShort();
                    if (value != fillValue) {
                        returnValue.value = value;
                        returnValue.timestamp = timestamps[iValue];
                        output.collect(returnValue);
                    }
                }
            }
        }
    }
    return numOfResults;
}

From source file:opendap.threddsHandler.ThreddsCatalogUtil.java

public Vector<String> getDDXUrls(String catalogUrlString, boolean recurse) throws InterruptedException {

    Vector<String> datasetUrls = getDataAccessURLs(catalogUrlString, SERVICE.OPeNDAP, recurse);
    String url;//from  w ww .j a v  a2s .c  o  m

    for (int i = 0; i < datasetUrls.size(); i++) {
        url = datasetUrls.get(i);
        log.debug("Found DAP dataset URL: " + url);
        datasetUrls.set(i, url + ".ddx");
    }

    return datasetUrls;

}

From source file:com.mobilesorcery.sdk.builder.linux.deb.DebBuilder.java

/**
 *
 * @param os/*from w ww.  j a v  a2  s .com*/
 */
private void doWriteControl(File f) throws Exception {
    Vector<Header> order = new Vector<Header>(20);
    FileOutputStream fos = new FileOutputStream(f);
    BufferedOutputStream bos = new BufferedOutputStream(fos);

    // Add Installed-Size header
    addHeader(new SizeHeader(m_installedSize));

    // FIXME: Replace with priority queue
    for (int i = 0; i < 20; i++)
        order.add(null);

    // Check if the mandatory headers are there
    for (String s : Header.getMandatory())
        if (m_headerMap.containsKey(s) == false)
            throw new Exception("Mandatory header '" + s + "' is missing");

    // Put the headers in a priority queue to get correct order
    for (Header h : m_headerMap.values())
        order.set(h.getPriority(), h);

    // Write them
    for (Header h : order) {
        if (h == null)
            continue;

        bos.write(h.toString().getBytes());
        bos.write(0x0a);
    }

    bos.close();
    fos.close();
}

From source file:org.zywx.wbpalmstar.engine.universalex.EUExBase.java

/**
 * viewid// w w w .  j  a v  a2  s .com
 *
 * @param index
 * @param opid
 */
public final void removeSubviewFromContainer(final int index, final String opid) {
    if (null == mBrwView || opid == null) {
        return;
    }
    ((EBrowserActivity) mContext).runOnUiThread(new Runnable() {

        @Override
        public void run() {
            EBrowserWindow mWindow = mBrwView.getBrowserWindow();
            int count = mWindow.getChildCount();
            for (int i = 0; i < count; i++) {
                View view = mWindow.getChildAt(i);
                if (view instanceof ContainerViewPager) {
                    ContainerViewPager pager = (ContainerViewPager) view;
                    if (opid.equals((String) pager.getContainerVO().getId())) {
                        ContainerAdapter adapter = (ContainerAdapter) pager.getAdapter();
                        Vector<FrameLayout> views = adapter.getViewList();
                        if (index < views.size() && index >= 0) {
                            adapter.destroyItem(pager, index, null);
                            views.get(index).removeAllViews();
                            views.set(index, new FrameLayout(mContext));
                        } else {
                            return;
                        }
                        adapter.setViewList(views);
                        adapter.notifyDataSetChanged();
                        return;
                    } //end equals opid
                } //end instanceof
            } //end for
        }// end run 
    });// end runOnUI
}