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

The following are Jave code examples for showing how to use addElement() 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: ipack   File: BEROctetString.java   View Source Code Vote up 7 votes
private Vector generateOcts()
{ 
    Vector vec = new Vector();
    for (int i = 0; i < string.length; i += MAX_LENGTH) 
    { 
        int end; 

        if (i + MAX_LENGTH > string.length) 
        { 
            end = string.length; 
        } 
        else 
        { 
            end = i + MAX_LENGTH; 
        } 

        byte[] nStr = new byte[end - i]; 

        System.arraycopy(string, i, nStr, 0, nStr.length);

        vec.addElement(new DEROctetString(nStr));
     } 
    
     return vec; 
}
 
Example 2
Project: logistimo-web-service   File: MessageUtil.java   View Source Code Vote up 7 votes
public static Vector getCleanMessages(Vector messages, String messageId)
    throws ProtocolException {
  if (messages == null || messageId == null) {
    return messages;
  }
  Vector cleanMessages = new Vector();
  Enumeration en = messages.elements();
  while (en.hasMoreElements()) {
    String msg = (String) en.nextElement();
    MessageHeader hd = new MessageHeader(msg);
    if (messageId.equals(hd.getMessageId())) {
      cleanMessages.addElement(msg);
    }
  }
  return cleanMessages;
}
 
Example 3
Project: openjdk-jdk10   File: BreakIteratorTest.java   View Source Code Vote up 7 votes
private Vector testFirstAndNext(BreakIterator bi, String text) {
    int p = bi.first();
    int lastP = p;
    Vector<String> result = new Vector<String>();

    if (p != 0)
        errln("first() returned " + p + " instead of 0");
    while (p != BreakIterator.DONE) {
        p = bi.next();
        if (p != BreakIterator.DONE) {
            if (p <= lastP)
                errln("next() failed to move forward: next() on position "
                                + lastP + " yielded " + p);

            result.addElement(text.substring(lastP, p));
        }
        else {
            if (lastP != text.length())
                errln("next() returned DONE prematurely: offset was "
                                + lastP + " instead of " + text.length());
        }
        lastP = p;
    }
    return result;
}
 
Example 4
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 5
Project: burstcoin   File: Speed.java   View Source Code Vote up 6 votes
private static void addFun(String name, String cspec,
	Vector sha3classes)
{
	int n = cspec.indexOf(',');
	if (n < 0) {
		NAME_TO_CLASSNAMES.put(name, cspec);
		ORDERED_CLASSNAMES.addElement(cspec);
	} else {
		String base = cspec.substring(0, n);
		NAME_TO_CLASSNAMES.put(name + "224", base + "224");
		ORDERED_CLASSNAMES.addElement(base + "224");
		NAME_TO_CLASSNAMES.put(name + "256", base + "256");
		ORDERED_CLASSNAMES.addElement(base + "256");
		NAME_TO_CLASSNAMES.put(name + "384", base + "384");
		ORDERED_CLASSNAMES.addElement(base + "384");
		NAME_TO_CLASSNAMES.put(name + "512", base + "512");
		ORDERED_CLASSNAMES.addElement(base + "512");
		int len = cspec.length();
		StringBuffer sb = new StringBuffer();
		n ++;
		while (n < len) {
			int p = cspec.indexOf(',', n);
			if (p < 0)
				p = len;
			String suffix = cspec.substring(n, p);
			if (sb.length() > 0)
				sb.append(',');
			String cname = base + suffix;
			sb.append(cname);
			if (sha3classes != null)
				sha3classes.addElement(cname);
			n = p + 1;
		}
		String ac = sb.toString();
		NAME_TO_CLASSNAMES.put(name, ac);
	}
}
 
Example 6
Project: OpenJSharp   File: JavaClass.java   View Source Code Vote up 6 votes
private void addSubclassInstances(Vector<JavaHeapObject> v) {
    for (int i = 0; i < subclasses.length; i++) {
        subclasses[i].addSubclassInstances(v);
    }
    for (int i = 0; i < instances.size(); i++) {
        v.addElement(instances.elementAt(i));
    }
}
 
Example 7
Project: jdk8u-jdk   File: BinaryMember.java   View Source Code Vote up 6 votes
/**
 * Get arguments
 */
public Vector getArguments() {
    if (isConstructor() && (getClassDefinition().getSuperClass() == null)) {
        Vector v = new Vector();
        v.addElement(new LocalMember(0, getClassDefinition(), 0,
                                    getClassDefinition().getType(), idThis));
        return v;
    }
    return null;
}
 
Example 8
Project: lams   File: StandardSyntaxParser.java   View Source Code Vote up 6 votes
final public QueryNode ConjQuery(CharSequence field) throws ParseException {
QueryNode first, c;
Vector<QueryNode> clauses = null;
  first = ModClause(field);
  label_3:
  while (true) {
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case AND:
      ;
      break;
    default:
      jj_la1[6] = jj_gen;
      break label_3;
    }
    jj_consume_token(AND);
    c = ModClause(field);
   if (clauses == null) {
       clauses = new Vector<>();
       clauses.addElement(first);
   }
   clauses.addElement(c);
  }
  if (clauses != null) {
    {if (true) return new AndQueryNode(clauses);}
  } else {
      {if (true) return first;}
  }
  throw new Error("Missing return statement in function");
}
 
Example 9
Project: s-store   File: ZaurusEditor.java   View Source Code Vote up 6 votes
private Vector getAllTables() {

        Vector result = new Vector(20);

        try {
            if (cConn == null) {
                return null;
            }

            dbmeta = cConn.getMetaData();

            String[] tableTypes = { "TABLE" };
            ResultSet allTables = dbmeta.getTables(null, null, null,
                                                   tableTypes);

            while (allTables.next()) {
                String aktTable = allTables.getString("TABLE_NAME");
                ResultSet primKeys = dbmeta.getPrimaryKeys(null, null,
                    aktTable);

                // take only table with a primary key
                if (primKeys.next()) {
                    result.addElement(aktTable);
                }

                primKeys.close();
            }

            allTables.close();
        } catch (SQLException e) {

            // System.out.println("SQL Exception: " + e.getMessage());
        }

        return result;
    }
 
Example 10
Project: routerapp   File: Graph.java   View Source Code Vote up 6 votes
public void contextReturn(Algorithm alg)
{
    Vector<Command> oldCommands = commandsStack.pop();
    oldCommands.addElement(alg);
    commands = oldCommands;
    currentCommand = commands.size() - 1;
}
 
Example 11
Project: AgentWorkbench   File: AgentStartConfiguration.java   View Source Code Vote up 6 votes
/**
 * Adds a further ontoReference as start argument to the vector of start arguments.
 *
 * @param agentReference the agent reference
 * @param ontoReference the onto reference
 * @return the index position of the new element
 */
public int addReference(String agentReference, String ontoReference) {
	
	if (ontoReference==null) return -1;
	
	Vector<AgentStartArgument> argumentVector = this.get(agentReference);
	if (argumentVector==null) {
		argumentVector = new Vector<AgentStartArgument>();
		this.put(agentReference, argumentVector);
	}
	AgentStartArgument agentStartArgument = new AgentStartArgument(argumentVector.size()+1, ontoReference);
	argumentVector.addElement(agentStartArgument);
	return argumentVector.size()-1;
}
 
Example 12
Project: gate-core   File: AnnotationSetImpl.java   View Source Code Vote up 6 votes
@Override
public synchronized void addGateListener(GateListener l) {
  @SuppressWarnings("unchecked")
  Vector<GateListener> v = gateListeners == null ? new Vector<GateListener>(2) : (Vector<GateListener>)gateListeners
          .clone();
  if(!v.contains(l)) {
    v.addElement(l);
    gateListeners = v;
  }
}
 
Example 13
Project: OpenJSharp   File: DOMImplementationRegistry.java   View Source Code Vote up 6 votes
/**
 * Return a list of implementations that support the
 * desired features.
 *
 * @param features
 *            A string that specifies which features are required. This is
 *            a space separated list in which each feature is specified by
 *            its name optionally followed by a space and a version number.
 *            This is something like: "XML 1.0 Traversal +Events 2.0"
 * @return A list of DOMImplementations that support the desired features.
 */
public DOMImplementationList getDOMImplementationList(final String features) {
    final Vector implementations = new Vector();
    int size = sources.size();
    for (int i = 0; i < size; i++) {
        DOMImplementationSource source =
            (DOMImplementationSource) sources.elementAt(i);
        DOMImplementationList impls =
            source.getDOMImplementationList(features);
        for (int j = 0; j < impls.getLength(); j++) {
            DOMImplementation impl = impls.item(j);
            implementations.addElement(impl);
        }
    }
    return new DOMImplementationList() {
            public DOMImplementation item(final int index) {
                if (index >= 0 && index < implementations.size()) {
                    try {
                        return (DOMImplementation)
                            implementations.elementAt(index);
                    } catch (ArrayIndexOutOfBoundsException e) {
                        return null;
                    }
                }
                return null;
            }

            public int getLength() {
                return implementations.size();
            }
        };
}
 
Example 14
Project: OpenJSharp   File: JPopupMenu.java   View Source Code Vote up 6 votes
/**
 * Inserts the specified component into the menu at a given
 * position.
 *
 * @param component  the <code>Component</code> to insert
 * @param index      specifies the position at which
 *                   to insert the component, where 0 is the first
 * @exception IllegalArgumentException if <code>index</code> &lt; 0
 */
public void insert(Component component, int index) {
    if (index < 0) {
        throw new IllegalArgumentException("index less than zero.");
    }

    int nitems = getComponentCount();
    // PENDING(ges): Why not use an array?
    Vector<Component> tempItems = new Vector<Component>();

    /* Remove the item at index, nitems-index times
       storing them in a temporary vector in the
       order they appear on the menu.
       */
    for (int i = index ; i < nitems; i++) {
        tempItems.addElement(getComponent(index));
        remove(index);
    }

    add(component);

    /* Add the removed items back to the menu, they are
       already in the correct order in the temp vector.
       */
    for (Component tempItem : tempItems) {
        add(tempItem);
    }
}
 
Example 15
Project: dev-courses   File: TestDataStructures.java   View Source Code Vote up 5 votes
public void testSpeed() {

        randomGenerator = new Random(System.currentTimeMillis());

        int           TEST_RUNS     = 100000;
        int           LOOP_COUNT    = 1000;
        HsqlArrayList arrayList     = new HsqlArrayList(TEST_RUNS);
        ArrayList     utilArrayList = new ArrayList(TEST_RUNS);
        Vector        vector        = new Vector(TEST_RUNS);
        Integer       value         = new Integer(randomGenerator.nextInt());
        Integer       INT_0         = new Integer(0);
        StopWatch     sw            = new StopWatch();

        System.out.println(sw.currentElapsedTimeToMessage("time"));

        for (int i = 0; i < TEST_RUNS; i++) {
            arrayList.add(INT_0);
        }

        for (int i = 0; i < TEST_RUNS; i++) {
            for (int j = 0; j < LOOP_COUNT; j++) {
                arrayList.set(i, INT_0);
            }
        }

        System.out.println(
            sw.currentElapsedTimeToMessage("time HsqlArrayLsit"));
        sw.zero();

        for (int i = 0; i < TEST_RUNS; i++) {
            utilArrayList.add(INT_0);
        }

        for (int i = 0; i < TEST_RUNS; i++) {
            for (int j = 0; j < LOOP_COUNT; j++) {
                utilArrayList.set(i, INT_0);
            }
        }

        System.out.println(sw.currentElapsedTimeToMessage("time ArrayList"));
        sw.zero();

        for (int i = 0; i < TEST_RUNS; i++) {
            vector.addElement(INT_0);
        }

        for (int i = 0; i < TEST_RUNS; i++) {
            for (int j = 0; j < LOOP_COUNT; j++) {
                vector.setElementAt(INT_0, i);
            }
        }

        System.out.println(sw.currentElapsedTimeToMessage("time Vector"));
    }
 
Example 16
Project: jdk8u-jdk   File: CryptoPermissions.java   View Source Code Vote up 5 votes
/**
 * Get the minimum of the two given PermissionCollection
 * <code>thisPc</code> and <code>thatPc</code>.
 *
 * @param thisPc the first given PermissionColloection
 * object.
 *
 * @param thatPc the second given PermissionCollection
 * object.
 */
private CryptoPermission[] getMinimum(PermissionCollection thisPc,
                                      PermissionCollection thatPc) {
    Vector<CryptoPermission> permVector = new Vector<>(2);

    Enumeration<Permission> thisPcPermissions = thisPc.elements();

    // For each CryptoPermission in
    // thisPc object, do the following:
    // 1) if this CryptoPermission is implied
    //     by thatPc, this CryptoPermission
    //     should be returned, and we can
    //     move on to check the next
    //     CryptoPermission in thisPc.
    // 2) otherwise, we should return
    //     all CryptoPermissions in thatPc
    //     which
    //     are implied by this CryptoPermission.
    //     Then we can move on to the
    //     next CryptoPermission in thisPc.
    while (thisPcPermissions.hasMoreElements()) {
        CryptoPermission thisCp =
            (CryptoPermission)thisPcPermissions.nextElement();

        Enumeration<Permission> thatPcPermissions = thatPc.elements();
        while (thatPcPermissions.hasMoreElements()) {
            CryptoPermission thatCp =
                (CryptoPermission)thatPcPermissions.nextElement();

            if (thatCp.implies(thisCp)) {
                permVector.addElement(thisCp);
                break;
            }
            if (thisCp.implies(thatCp)) {
                permVector.addElement(thatCp);
            }
        }
    }

    CryptoPermission[] ret = new CryptoPermission[permVector.size()];
    permVector.copyInto(ret);
    return ret;
}
 
Example 17
Project: OpenJSharp   File: SymtabEntry.java   View Source Code Vote up 5 votes
void initDynamicVars ()
{
  _dynamicVars = new Vector (maxKey + 1);
  for (int i = 0; i <= maxKey; ++i)
    _dynamicVars.addElement (null);
}
 
Example 18
Project: myster   File: MML.java   View Source Code Vote up 5 votes
public static void listNodes(Link head, Vector collection) {
    for (Link iterator = head; iterator.next != null; iterator = iterator.next)
        collection.addElement(iterator.next.value);
}
 
Example 19
Project: routerapp   File: ComponentProperties.java   View Source Code Vote up 5 votes
public Vector getAllProperties()
{
    Vector values = new Vector();
    for(Iterator i = properties.values().iterator(); i.hasNext(); values.addElement(i.next())) { }
    return values;
}
 
Example 20
Project: AntIDE   File: BreakpointManager.java   View Source Code Vote up 5 votes
RemoteField findMatchingMethod(RemoteClass clazz, String methodName,
                               String argSpec) throws Exception {
  if ( (argSpec.length() > 0) &&
       (!argSpec.startsWith("(") || !argSpec.endsWith(")")) ) {
    //out.println("Invalid method specification: '" + methodName + argSpec + "'");
    JOptionPane.showMessageDialog(null, "Invalid method specification: '" + methodName + argSpec + "'", "Breakpoint Error", JOptionPane.ERROR_MESSAGE);
    return null;
  }

  // Parse the argument string once before looping below.
  StringTokenizer tokens = new StringTokenizer(argSpec, "(,)");
  Vector argTypeNames = new Vector();
  String name = null;
  try {
    while (tokens.hasMoreTokens()) {
      name = tokens.nextToken();
      name = normalizeArgTypeName(name);
      argTypeNames.addElement(name);
    }
  } catch (IllegalArgumentException e) {
    JOptionPane.showMessageDialog(null, "Invalid Argument Type: '" + name + "'", "Breakpoint Error", JOptionPane.ERROR_MESSAGE);
    //out.println("Invalid Argument Type: '" + name + "'");
    return null;
  }

  // Check each method in the class for matches
  RemoteField methods[] = clazz.getMethods();
  RemoteField firstMatch = null;  // first method with matching name
  RemoteField exactMatch = null;  // (only) method with same name & sig
  int matchCount = 0;             // > 1 implies overload
  for (int i = 0; i < methods.length; i++) {
    RemoteField candidate = methods[i];

    if (candidate.getName().equals(methodName)) {
      matchCount++;

      // Remember the first match in case it is the only one
      if (matchCount == 1) {
        firstMatch = candidate;
      }

      // If argument types were specified, check against candidate
      if (! argSpec.equals("")
              && compareArgTypes(candidate, argTypeNames) == true) {
        exactMatch = candidate;
        break;
      }
    }
  }

  // Determine method for breakpoint
  RemoteField method = null;
  if (exactMatch != null) {
    // Name and signature match
    method = exactMatch;
  } else if (argSpec.equals("") && (matchCount > 0)) {
    // At least one name matched and no arg types were specified
    if (matchCount == 1) {
      method = firstMatch;       // Only one match; safe to use it
    } else {
      // Method is overloaded, but no arg types were specified
      //out.println(clazz.getName() + "." + methodName +
        //          " is overloaded, use one of the following:");
      String temp = "";
      for (int i = 0; i < methods.length; i++) {
        if (methodName.equals(methods[i].getName())) {
          //out.println("  " + methods[i].getTypedName());
          temp += "  " + methods[i].getTypedName();
        }
      }
      JOptionPane.showMessageDialog(null, clazz.getName() + "." + methodName + " is overloaded, use one of the following:" + "\r\n" + temp
                                    , "FindMatchingMethod Error", JOptionPane.ERROR_MESSAGE);
    }
  } else {
    // No match with unspecified args or no exact match with specified args
    //out.println("Class " + clazz.getName() + " doesn't have a method " + methodName + argSpec);
      JOptionPane.showMessageDialog(null, "Class " + clazz.getName() + " doesn't have a method " + methodName + argSpec
                                    , "FindMatchingMethod Error", JOptionPane.ERROR_MESSAGE);
  }
  return method;
}