Java Code Examples for java.util.Vector.elementAt()

The following are Jave code examples for showing how to use elementAt() of the java.util.Vector class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: OpenJSharp   File: Whitespace.java   View Source Code Vote up 7 votes
/**
 * Used with quicksort method above
 */
private static int partition(Vector rules, int p, int r) {
    final WhitespaceRule x = (WhitespaceRule)rules.elementAt((p+r) >>> 1);
    int i = p - 1, j = r + 1;
    while (true) {
        while (x.compareTo((WhitespaceRule)rules.elementAt(--j)) < 0) {
        }
        while (x.compareTo((WhitespaceRule)rules.elementAt(++i)) > 0) {
        }
        if (i < j) {
            final WhitespaceRule tmp = (WhitespaceRule)rules.elementAt(i);
            rules.setElementAt(rules.elementAt(j), i);
            rules.setElementAt(tmp, j);
        }
        else {
            return j;
        }
    }
}
 
Example 2
Project: myster   File: FileInfoListerThread.java   View Source Code Vote up 7 votes
private void listDir(RobustMML mml, KeyValue keyValue, String directory,
        String prefix) {
    Vector dirList = mml.list(directory);

    if (dirList == null)
        return;

    for (int i = 0; i < dirList.size(); i++) {
        String name = (String) dirList.elementAt(i);

        if (name == null)
            return;

        String newPath = directory + name;

        if (mml.isADirectory(newPath + "/")) {
            keyValue.addValue(name, " ->");
            listDir(mml, keyValue, newPath + "/", prefix + "  ");
        } else {
            keyValue.addValue(prefix + ((String) dirList.elementAt(i)), mml
                    .get(newPath));
        }
    }
}
 
Example 3
Project: openjdk-jdk10   File: XSDHandler.java   View Source Code Vote up 7 votes
private Vector expandComponents(XSObject[] components, Map<String, Vector> dependencies) {
    Vector newComponents = new Vector();

    for (int i=0; i<components.length; i++) {
        if (!newComponents.contains(components[i])) {
            newComponents.add(components[i]);
        }
    }

    for (int i=0; i<newComponents.size(); i++) {
        final XSObject component = (XSObject) newComponents.elementAt(i);
        expandRelatedComponents(component, newComponents, dependencies);
    }

    return newComponents;
}
 
Example 4
Project: openjdk-jdk10   File: Obj.java   View Source Code Vote up 7 votes
/**
 * Each value in javaCodebase contains a list of space-separated
 * URLs. Each value is independent; we can pick any of the values
 * so we just use the first one.
 * @return an array of URL strings for the codebase
 */
private static String[] getCodebases(Attribute codebaseAttr) throws
    NamingException {
    if (codebaseAttr == null) {
        return null;
    } else {
        StringTokenizer parser =
            new StringTokenizer((String)codebaseAttr.get());
        Vector<String> vec = new Vector<>(10);
        while (parser.hasMoreTokens()) {
            vec.addElement(parser.nextToken());
        }
        String[] answer = new String[vec.size()];
        for (int i = 0; i < answer.length; i++) {
            answer[i] = vec.elementAt(i);
        }
        return answer;
    }
}
 
Example 5
Project: openjdk-jdk10   File: Whitespace.java   View Source Code Vote up 7 votes
/**
 * Used with quicksort method above
 */
private static int partition(Vector rules, int p, int r) {
    final WhitespaceRule x = (WhitespaceRule)rules.elementAt((p+r) >>> 1);
    int i = p - 1, j = r + 1;
    while (true) {
        while (x.compareTo((WhitespaceRule)rules.elementAt(--j)) < 0) {
        }
        while (x.compareTo((WhitespaceRule)rules.elementAt(++i)) > 0) {
        }
        if (i < j) {
            final WhitespaceRule tmp = (WhitespaceRule)rules.elementAt(i);
            rules.setElementAt(rules.elementAt(j), i);
            rules.setElementAt(tmp, j);
        }
        else {
            return j;
        }
    }
}
 
Example 6
Project: OpenJSharp   File: SnmpIndex.java   View Source Code Vote up 7 votes
/**
 * Compares two indexes for equality.
 *
 * @param index The index to compare <CODE>this</CODE> with.
 *
 * @return <CODE>true</CODE> if the two indexes are equal, <CODE>false</CODE> otherwise.
 */
public boolean equals(SnmpIndex index) {

    if (size != index.getNbComponents())
        return false;

    // The two vectors have the same length.
    // Compare each single element ...
    //
    SnmpOid oid1;
    SnmpOid oid2;
    Vector<SnmpOid> components= index.getComponents();
    for(int i=0; i <size; i++) {
        oid1= oids.elementAt(i);
        oid2= components.elementAt(i);
        if (oid1.equals(oid2) == false)
            return false;
    }
    return true;
}
 
Example 7
Project: jdk8u-jdk   File: PCMtoPCMCodec.java   View Source Code Vote up 7 votes
/**
 */
public AudioFormat[] getTargetFormats(AudioFormat.Encoding targetEncoding, AudioFormat sourceFormat){

    // filter out targetEncoding from the old getOutputFormats( sourceFormat ) method

    AudioFormat[] formats = getOutputFormats( sourceFormat );
    Vector newFormats = new Vector();
    for(int i=0; i<formats.length; i++ ) {
        if( formats[i].getEncoding().equals( targetEncoding ) ) {
            newFormats.addElement( formats[i] );
        }
    }

    AudioFormat[] formatArray = new AudioFormat[newFormats.size()];

    for (int i = 0; i < formatArray.length; i++) {
        formatArray[i] = (AudioFormat)(newFormats.elementAt(i));
    }

    return formatArray;
}
 
Example 8
Project: openjdk-jdk10   File: IDLGenerator.java   View Source Code Vote up 7 votes
/**
 * Collect and filter type and array references from methods
 * @param mthVec Given Vector of methods
 * @param refHash Hashtable for type references
 * @param spcHash Hashtable for special type references
 * @param arrHash Hashtable for array references
 * @param excHash Hashtable for exceptions thrown
 */
protected void getMethodReferences(
                                   Vector mthVec,
                                   Hashtable refHash,
                                   Hashtable spcHash,
                                   Hashtable arrHash,
                                   Hashtable excHash ) {
    for ( int i1 = 0; i1 < mthVec.size(); i1++ ) {             //forall methods
        CompoundType.Method mth = (CompoundType.Method)mthVec.elementAt( i1 );
        Type[] args = mth.getArguments();
        Type ret = mth.getReturnType();
        getExceptions( mth,excHash );                 //collect exceptions thrown
        for ( int i2 = 0; i2 < args.length; i2++ )             //forall arguments
            addReference( args[i2],refHash,spcHash,arrHash );
        addReference( ret,refHash,spcHash,arrHash );
    }
}
 
Example 9
Project: openaudible   File: TreePath.java   View Source Code Vote up 6 votes
private void readObject(ObjectInputStream s)
        throws IOException, ClassNotFoundException {
    s.defaultReadObject();

    Vector values = (Vector) s.readObject();
    int indexCounter = 0;
    int maxCounter = values.size();

    if (indexCounter < maxCounter && values.elementAt(indexCounter).
            equals("lastPathComponent")) {
        lastPathComponent = values.elementAt(++indexCounter);
        indexCounter++;
    }
}
 
Example 10
Project: MaxSim   File: WinGammaPlatform.java   View Source Code Vote up 6 votes
void tagV(String name, Vector attrs) {
   String s[] = new String[attrs.size()];
   for (int i = 0; i < attrs.size(); i++) {
      s[i] = (String) attrs.elementAt(i);
   }
   startTagPrim(name, s, true);
}
 
Example 11
Project: parabuild-ci   File: ChannelSftp.java   View Source Code Vote up 6 votes
/**
 * This method will check if the given string can be expanded to the
 * unique string.  If it can be expanded to mutiple files, SftpException
 * will be thrown.
 * @return the returned string is unquoted.
 */
private String isUnique(String path) throws SftpException, Exception{
  Vector v=glob_remote(path);
  if(v.size()!=1){
    throw new SftpException(SSH_FX_FAILURE, path+" is not unique: "+v.toString());
  }
  return (String)(v.elementAt(0));
}
 
Example 12
Project: OpenDiabetes   File: DatabaseManager.java   View Source Code Vote up 6 votes
void saveAsCsv(String filename) {

        try {
            File      file   = new File(filename);
            CSVWriter writer = new CSVWriter(file, null);
            String[]  col    = gResult.getHead();
            int       width  = col.length;
            Vector    data   = gResult.getData();
            String[]  row;
            int       height = data.size();

            writer.writeHeader(col);

            for (int i = 0; i < height; i++) {
                row = (String[]) data.elementAt(i);

                String[] myRow = new String[row.length];

                for (int j = 0; j < row.length; j++) {
                    String r = row[j];

                    if (r.equals("(null)")) {

                        // null is formatted as (null)
                        r = "";
                    }

                    myRow[j] = r;
                }

                writer.writeData(myRow);
            }

            writer.close();
        } catch (IOException e) {
            throw new RuntimeException("IOError: " + e.getMessage());
        }
    }
 
Example 13
Project: OpenJSharp   File: XSDHandler.java   View Source Code Vote up 6 votes
/**
 * Namespace growth
 *
 * Go through the import list of a given grammar and for each imported
 * grammar, check to see if the grammar bucket has a newer version.
 * If a new instance is found, we update the import list with the
 * newer version.
 */
private void updateImportListFor(SchemaGrammar grammar) {
    Vector importedGrammars = grammar.getImportedGrammars();
    if (importedGrammars != null) {
        for (int i=0; i<importedGrammars.size(); i++) {
            SchemaGrammar isg1 = (SchemaGrammar) importedGrammars.elementAt(i);
            SchemaGrammar isg2 = fGrammarBucket.getGrammar(isg1.getTargetNamespace());
            if (isg2 != null && isg1 != isg2) {
                importedGrammars.set(i, isg2);
            }
        }
    }
}
 
Example 14
Project: myster   File: MultiSourceHashSearch.java   View Source Code Vote up 6 votes
private synchronized static SearchEntry[] getSearchEntries(MysterType type) {
    Vector entriesVector = getEntriesForType(type);

    SearchEntry[] entries = new SearchEntry[entriesVector.size()];

    for (int i = 0; i < entries.length; i++) {
        entries[i] = (SearchEntry) entriesVector.elementAt(i);
    }

    return entries;
}
 
Example 15
Project: ibench   File: Hom.java   View Source Code Vote up 5 votes
private static void tryToMap(int pos, int[] srcArr, int[] trgArr, FromClauseList fromCl, FromClauseList toCl,
            Vector foundHoms)
    {
        // if we reached the end of the src Arr it means that we have checked
        // them all so test if we have mapped something or not. If yes, then we
        // report it
        if (pos == srcArr.length)
        {
            Hom hom = new Hom();
//            for (int i = 0, imax = srcArr.length; i < imax; i++)
//                if (srcArr[i] != -1)
//                    hom.addMap(fromCl.getRelationName(i), toCl.getRelationName(srcArr[i]));
            if (hom.size() != 0)
            {
                // we are about to insert it but before we do, let's make sure
                // that there is no other one already computed that includes it.
                boolean isIncludedInAnother = false;
                for (int ii = 0, iimax = foundHoms.size(); ii < iimax; ii++)
                {
                    Hom tmpHom = (Hom) foundHoms.elementAt(ii);
                    if (tmpHom.includes(hom))
                    {
                        isIncludedInAnother = true;
                        break;
                    }
                }
                // if none includes it insert it.
                if (!isIncludedInAnother)
                    foundHoms.add(0, hom);
            }
            return;
        }

        // Get the relation you try to mapp
//        String srcTbl = ((RelationalTableReference) fromCl.getRelation(pos)).getPath().getLabel();
        // try to map it
        for (int i = 0, imax = trgArr.length; i < imax; i++)
        {
            if (trgArr[i] != -1)
                continue; // cannot map to this one
//            String toTbl = ((RelationalTableReference) toCl.getRelation(i)).getPath().getLabel();
//            if (!toTbl.equals(srcTbl))
//                continue; // not compatible tables
            // otherwise they can map
            srcArr[pos] = i;
            trgArr[i] = pos;
            tryToMap(pos + 1, srcArr, trgArr, fromCl, toCl, foundHoms);
            srcArr[pos] = -1;
            trgArr[i] = -1;
        }
        // consider also the case where the pos table is not mapped at all.
        srcArr[pos] = -1;
        tryToMap(pos + 1, srcArr, trgArr, fromCl, toCl, foundHoms);
    }
 
Example 16
Project: MARF-for-Android   File: TransitionTable.java   View Source Code Vote up 5 votes
/**
 * Serialize in text mode. Loading is not implemented.
 * TODO: migrate to MARF's dump/store mechanism.
 *
 * @param piOperation - 0 - LOAD, 1 - SAVE
 * @return <code>true</code> if serialization was successful
 */
public boolean serialize(int piOperation) {
    if (piOperation == 0) {
        System.err.println("TransitionTable::serialize(LOAD) - Not implemented.");
        return false;
    } else {
        // A row of terminals
        int iTermNum = this.oTerminals.size();

        System.out.print("   Terminals(" + iTermNum + "): \t");

        for (int t = 0; t < iTermNum; t++) {
            Terminal oTerminal = (Terminal) this.oTerminals.elementAt(t);
            System.out.print("(" + oTerminal.getID() + ")" + oTerminal.getName() + "\t");
        }

        System.out.println();

        // Non terminals and rules...
        int iNonTemNum = this.oNonTerminals.size();

        System.out.println("NonTerminals(" + iNonTemNum + "): \t");

        for (int n = 0; n < iNonTemNum; n++) {
            System.out.print(((NonTerminal) this.oNonTerminals.elementAt(n)).getName() + "\t");

            for (int t = 0; t < iTermNum; t++) {
                Vector oRow = (Vector) this.oTT.elementAt(n);

                Object oEntry = oRow.elementAt(t);

                if (oEntry instanceof Rule) {
                    Rule oRule = (Rule) oRow.elementAt(t);
                    System.out.print(oRule.toAbbrString() + "\t");
                } else {
                    SyntaxError oSyntaxError = (SyntaxError) oEntry;
                    System.out.print("e\t");
                    Debug.debug(oSyntaxError.getMessage() + "\t");
                }
            }

            System.out.println();
        }

        return true;
    }
}
 
Example 17
Project: jdk8u-jdk   File: DerInputStream.java   View Source Code Vote up 5 votes
protected DerValue[] readVector(int startLen) throws IOException {
    DerInputStream  newstr;

    byte lenByte = (byte)buffer.read();
    int len = getLength(lenByte, buffer);

    if (len == -1) {
       // indefinite length encoding found
       int readLen = buffer.available();
       int offset = 2;     // for tag and length bytes
       byte[] indefData = new byte[readLen + offset];
       indefData[0] = tag;
       indefData[1] = lenByte;
       DataInputStream dis = new DataInputStream(buffer);
       dis.readFully(indefData, offset, readLen);
       dis.close();
       DerIndefLenConverter derIn = new DerIndefLenConverter();
       buffer = new DerInputBuffer(derIn.convert(indefData));
       if (tag != buffer.read())
            throw new IOException("Indefinite length encoding" +
                    " not supported");
       len = DerInputStream.getLength(buffer);
    }

    if (len == 0)
        // return empty array instead of null, which should be
        // used only for missing optionals
        return new DerValue[0];

    /*
     * Create a temporary stream from which to read the data,
     * unless it's not really needed.
     */
    if (buffer.available() == len)
        newstr = this;
    else
        newstr = subStream(len, true);

    /*
     * Pull values out of the stream.
     */
    Vector<DerValue> vec = new Vector<DerValue>(startLen);
    DerValue value;

    do {
        value = new DerValue(newstr.buffer);
        vec.addElement(value);
    } while (newstr.available() > 0);

    if (newstr.available() != 0)
        throw new IOException("Extra data at end of vector");

    /*
     * Now stick them into the array we're returning.
     */
    int             i, max = vec.size();
    DerValue[]      retval = new DerValue[max];

    for (i = 0; i < max; i++)
        retval[i] = vec.elementAt(i);

    return retval;
}
 
Example 18
Project: OpenJSharp   File: ValueGen.java   View Source Code Vote up 5 votes
public int read (int index, String indent, String name, SymtabEntry entry, PrintWriter stream)
{
  // First do the state members from concrete parent hierarchy
  Vector vParents = ((ValueEntry) entry).derivedFrom ();
  if (vParents != null && vParents.size() != 0)
  {
    ValueEntry parent = (ValueEntry) vParents.elementAt (0);
    if (parent == null)
      return index;
    // Per Simon, 4/6/99 - call parent read. <d60929>
    if (! Util.javaQualifiedName(parent).equals ("java.io.Serializable")) // <d60929>
        stream.println(indent + Util.helperName (parent, true) + ".read (istream, value);"); // <d60929> // <d61056>
  }

  Vector vMembers = ((ValueEntry) entry).state ();
  int noOfMembers = vMembers == null ? 0 : vMembers.size ();

  for (int k = 0; k < noOfMembers; k++)
  {
    TypedefEntry member = (TypedefEntry)((InterfaceState)vMembers.elementAt (k)).entry;
    String memberName = member.name ();
    SymtabEntry mType = member.type ();

    if (mType instanceof PrimitiveEntry ||
        mType instanceof TypedefEntry   ||
        mType instanceof SequenceEntry  ||
        mType instanceof StringEntry    ||
        !member.arrayInfo ().isEmpty ())
      index = ((JavaGenerator)member.generator ()).read (index, indent, name + '.' + memberName, member, stream);
    else if (mType instanceof ValueEntry)
    {
      String returnType = Util.javaQualifiedName (mType);
      if (mType instanceof ValueBoxEntry)
        // <f46082.51> Remove -stateful.
        //returnType = Util.javaStatefulName (mType);
        returnType = Util.javaName (mType);
      stream.println ("    " + name + '.' + memberName + " = (" + returnType +
                      ") ((org.omg.CORBA_2_3.portable.InputStream)istream).read_value (" + Util.helperName (mType, true) +  // <d61056>
                      ".get_instance ());"); // <d61056>
    }
    else
      stream.println (indent + name + '.' + memberName + " = " +
                      Util.helperName (mType, true) + ".read (istream);"); // <d61056>
  }

  return index;
}
 
Example 19
Project: jdk8u-jdk   File: JList.java   View Source Code Vote up 4 votes
/**
 * Constructs a <code>JList</code> that displays the elements in
 * the specified <code>Vector</code>. This constructor creates a read-only
 * model for the given {@code Vector}, and then delegates to the constructor
 * that takes a {@code ListModel}.
 * <p>
 * Attempts to pass a {@code null} value to this method results in
 * undefined behavior and, most likely, exceptions. The created model
 * references the given {@code Vector} directly. Attempts to modify the
 * {@code Vector} after constructing the list results in undefined behavior.
 *
 * @param  listData  the <code>Vector</code> to be loaded into the
 *                   data model, {@code non-null}
 */
public JList(final Vector<? extends E> listData) {
    this (
        new AbstractListModel<E>() {
            public int getSize() { return listData.size(); }
            public E getElementAt(int i) { return listData.elementAt(i); }
        }
    );
}
 
Example 20
Project: OpenJSharp   File: DefaultTableModel.java   View Source Code Vote up 3 votes
/**
 * Returns an attribute value for the cell at <code>row</code>
 * and <code>column</code>.
 *
 * @param   row             the row whose value is to be queried
 * @param   column          the column whose value is to be queried
 * @return                  the value Object at the specified cell
 * @exception  ArrayIndexOutOfBoundsException  if an invalid row or
 *               column was given
 */
public Object getValueAt(int row, int column) {
    Vector rowVector = (Vector)dataVector.elementAt(row);
    return rowVector.elementAt(column);
}