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:org.apache.hadoop.raid.Encoder.java

private Vector<Path> getPartialPaths(int encodingUnit, int expectedNum, FileStatus[] stats, Codec codec,
        long numStripes) throws IOException {
    Vector<Path> partialPaths = new Vector<Path>(expectedNum);
    partialPaths.setSize(expectedNum);
    for (FileStatus stat : stats) {
        int startStripeIdx;
        try {/*from   w  ww .  j  av a  2s.co m*/
            startStripeIdx = Integer.parseInt(stat.getPath().getName());
        } catch (NumberFormatException nfe) {
            throw new IOException("partial file " + stat.getPath() + " is not a number");
        }
        if (startStripeIdx % encodingUnit != 0) {
            throw new IOException("partial file " + stat.getPath() + " couldn't " + "match " + encodingUnit);
        }
        long numBlocks = RaidNode.numBlocks(stat);
        long expectedNumBlocks = Math.min(encodingUnit, numStripes - startStripeIdx) * codec.parityLength;
        if (numBlocks != expectedNumBlocks) {
            throw new IOException("partial file " + stat.getPath() + " has " + numBlocks
                    + " blocks, but it should be " + expectedNumBlocks);
        }
        partialPaths.set(startStripeIdx / encodingUnit, stat.getPath());
    }
    return partialPaths;
}

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

/**
 * Adds the collection of files to the queue.
 * /*from w w  w. j a  v a2 s  .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:org.apache.felix.webconsole.internal.compendium.ConfigManager.java

private String applyConfiguration(HttpServletRequest comingRequest, ConfigurationAdmin ca, String pid)
        throws IOException {
    if (comingRequest.getParameter("delete") != null) {
        // only delete if the PID is not our place holder
        if (!SAVED_PID.equals(pid)) {
            // TODO: should log this here !!
            Configuration config = ca.getConfiguration(pid, null);
            config.delete();//www . j  a v  a  2 s .c  om
        }
        return comingRequest.getHeader("Referer");
    }

    String factoryPid = comingRequest.getParameter(ConfigManager.factoryPID);
    Configuration tempConfig = null;

    String propertyList = comingRequest.getParameter("propertylist");
    if (propertyList == null) {
        String propertiesString = comingRequest.getParameter("properties");

        if (propertiesString != null) {
            byte[] propBytes = propertiesString.getBytes("ISO-8859-1");
            ByteArrayInputStream bin = new ByteArrayInputStream(propBytes);
            Properties props = new Properties();
            props.load(bin);

            tempConfig = getConfiguration(ca, pid, factoryPid);
            tempConfig.update(props);
        }
    } else {
        tempConfig = getConfiguration(ca, pid, factoryPid);

        Dictionary propsBook = tempConfig.getProperties();
        if (propsBook == null) {
            propsBook = new Hashtable();
        }

        Map attrDefMap = this.getAttributeDefinitionMap(tempConfig, null);
        if (attrDefMap != null) {
            StringTokenizer propTokens = new StringTokenizer(propertyList, ",");
            while (propTokens.hasMoreTokens()) {
                String propName = propTokens.nextToken();
                AttributeDefinition currAttrDef = (AttributeDefinition) attrDefMap.get(propName);
                if (currAttrDef == null || (currAttrDef.getCardinality() == 0
                        && currAttrDef.getType() == AttributeDefinition.STRING)) {
                    String currPropName = comingRequest.getParameter(propName);
                    if (currPropName != null) {
                        propsBook.put(propName, currPropName);
                    }
                } else if (currAttrDef.getCardinality() == 0) {
                    // scalar of non-string
                    String curProp = comingRequest.getParameter(propName);
                    if (curProp != null) {
                        try {
                            propsBook.put(propName, this.getType(currAttrDef.getType(), curProp));
                        } catch (NumberFormatException nfe) {
                            // don't care
                        }
                    }
                } else {
                    // array or vector of any type
                    Vector tempVec = new Vector();

                    String[] properties = comingRequest.getParameterValues(propName);
                    if (properties != null) {
                        for (int i = 0; i < properties.length; i++) {
                            try {
                                tempVec.add(this.getType(currAttrDef.getType(), properties[i]));
                            } catch (NumberFormatException nfe) {
                                // don't care
                            }
                        }
                    }

                    // but ensure size
                    int maxSize = Math.abs(currAttrDef.getCardinality());
                    if (tempVec.size() > maxSize) {
                        tempVec.setSize(maxSize);
                    }

                    if (currAttrDef.getCardinality() < 0) {
                        // keep the vector
                        propsBook.put(propName, tempVec);
                    } else {
                        // convert to an array
                        propsBook.put(propName, this.getArray(currAttrDef.getType(), tempVec));
                    }
                }
            }
        }

        tempConfig.update(propsBook);
    }

    // redirect to the new configuration (if existing)
    return (tempConfig != null) ? tempConfig.getPid() : "";
}

From source file:edu.ku.brc.specify.utilapps.BuildSampleDatabase.java

/**
 * @param conn//from w  w w .  j  a v a2s.  co m
 * @param stmt
 * @param levelNames
 * @param startIndex
 * @param numColumns
 * @param parent
 * @param nodeList
 * @param rankedItems
 * @param txTreeDefId
 * @throws SQLException
 */
public void convertTaxonNodes(final Connection conn, final Statement stmt, final String[] header,
        final String[] levelNames, final int numColumns, final Pair<String, Integer> parent,
        final Vector<Pair<String, Integer>> nodeList, final Vector<TaxonTreeDefItem> rankedItems,
        final int txTreeDefId) throws SQLException {
    /*
     * kingdom     phylum      class   order       superfamily family      genus       species   subspecies  species author  species source  species guid    species common name family common name  subspecies author   subspecies source   subspecies lsid subspecies common name
       Animalia    Arthropoda  Insecta Orthoptera  Acridoidea  Acrididae   Abisares    depressus             Uvarov 1938 orthoptera.speciesfile.org  urn:lsid:catalogueoflife.org:taxon:e32007de-29c1-102b-9a4a-00304854f820:ac2008                      
     */
    String fullName = "";

    for (int i = 0; i < numColumns; i++) {
        int inx = i + 1;
        if (StringUtils.isEmpty(levelNames[i])) {
            break;
        }

        Integer depthInx = taxonIndexes.get(header[i]);
        if (depthInx == null && taxonExtraColsIndexes.get(header[i]) != null) {
            break;
        }
        TaxonTreeDefItem ttdi = rankedItems.get(depthInx);

        if (ttdi.getIsInFullName()) {
            if (StringUtils.isNotEmpty(ttdi.getTextBefore())) {
                fullName += ttdi.getTextBefore();
            }
            fullName += levelNames[i];
            if (StringUtils.isNotEmpty(ttdi.getTextAfter())) {
                fullName += ttdi.getTextAfter();
            }
            if (StringUtils.isNotEmpty(ttdi.getFullNameSeparator())) {
                fullName += ttdi.getFullNameSeparator();
            }
        }

        if (inx == nodeList.size() || !levelNames[i].equals(nodeList.get(inx).first)) {
            for (int j = inx; j < nodeList.size(); j++) {
                recycler.push(nodeList.get(j));
            }
            nodeList.setSize(inx);
            Pair<String, Integer> node = createTaxonNode(conn, stmt, levelNames[i], txTreeDefId, ttdi,
                    nodeList.get(i).second, fullName.trim(), levelNames);
            nodeList.add(node);
        }
    }
}