Java Code Examples for java.util.Vector#removeElementAt()

The following examples show how to use java.util.Vector#removeElementAt() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DocumentImpl.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Introduced in DOM Level 2. <p> Deregister an event listener previously
 * registered with this Node.  A listener must be independently removed
 * from the Capturing and Bubbling roles. Redundant removals (of listeners
 * not currently registered for this role) are ignored.
 * @param node node to remove listener from
 * @param type Event name (NOT event group!) to listen for.
 * @param listener Who gets called when event is dispatched
 * @param useCapture True iff listener is registered on
 *  capturing phase rather than at-target or bubbling
 */
protected void removeEventListener(NodeImpl node, String type,
                                   EventListener listener,
                                   boolean useCapture)
{
    // If this couldn't be a valid listener registration, ignore request
    if (type == null || type.equals("") || listener == null)
        return;
    Vector nodeListeners = getEventListeners(node);
    if (nodeListeners == null)
        return;

    // Note that addListener has previously ensured that
    // each listener may be registered only once per type per phase.
    // count-down is OK for deletions!
    for (int i = nodeListeners.size() - 1; i >= 0; --i) {
        LEntry le = (LEntry) nodeListeners.elementAt(i);
        if (le.useCapture == useCapture && le.listener == listener &&
            le.type.equals(type)) {
            nodeListeners.removeElementAt(i);
            // Storage management: Discard empty listener lists
            if (nodeListeners.size() == 0)
                setEventListeners(node, null);

            // Remove active listener
            LCount lc = LCount.lookup(type);
            if (useCapture) {
                --lc.captures;
                --lc.total;
            }
            else {
                --lc.bubbles;
                --lc.total;
            }

            break;  // Found it; no need to loop farther.
        }
    }
}
 
Example 2
Source File: StringContent.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Resets the location for all the UndoPosRef instances
 * in <code>positions</code>.
 * <p>
 * This is meant for internal usage, and is generally not of interest
 * to subclasses.
 *
 * @param positions the positions of the instances
 */
protected void updateUndoPositions(Vector positions) {
    for(int counter = positions.size() - 1; counter >= 0; counter--) {
        UndoPosRef ref = (UndoPosRef)positions.elementAt(counter);
        // Check if the Position is still valid.
        if(ref.rec.unused) {
            positions.removeElementAt(counter);
        }
        else
            ref.resetLocation();
    }
}
 
Example 3
Source File: StringContent.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Resets the location for all the UndoPosRef instances
 * in <code>positions</code>.
 * <p>
 * This is meant for internal usage, and is generally not of interest
 * to subclasses.
 *
 * @param positions the positions of the instances
 */
protected void updateUndoPositions(Vector positions) {
    for(int counter = positions.size() - 1; counter >= 0; counter--) {
        UndoPosRef ref = (UndoPosRef)positions.elementAt(counter);
        // Check if the Position is still valid.
        if(ref.rec.unused) {
            positions.removeElementAt(counter);
        }
        else
            ref.resetLocation();
    }
}
 
Example 4
Source File: ListActionsActivity.java    From WhereYouGo with GNU General Public License v3.0 5 votes vote down vote up
public static Vector<Object> getValidActions(Thing thing) {
    Vector<Object> newActions = new Vector<>();
    for (int i = 0; i < thing.actions.size(); i++)
        newActions.add(thing.actions.get(i));

    for (int i = 0; i < newActions.size(); i++) {
        Action a = (Action) newActions.elementAt(i);
        if (!a.isEnabled() || !a.getActor().visibleToPlayer()) {
            newActions.removeElementAt(i--);
        }
    }
    return newActions;
}
 
Example 5
Source File: IDLGenerator.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Strip Java #pragma prefix and/or -pkgPrefix prefix package names from
 * given IDLEntity ct.
 * Strip any package prefix which may have been added by comparing with
 * repository id. For example in Java package fake.omega:
 *   repid = IDL:phoney.pfix/omega/Juliet:1.0 gives { "omega" }
 * @param ct CompoundType containing given IDLEntity.
 * @param vec Returned Vector of stripped IDL module names.
 */
protected void stripJavaPackage(
                                CompoundType ct,
                                Vector vec ) {
    vec.removeAllElements();
    if ( ! ct.isIDLEntity() ) return;

    String repID = ct.getRepositoryID().substring( 4 );
    StringTokenizer rept = new StringTokenizer( repID,"/" );
    if ( rept.countTokens() < 2 ) return;

    while ( rept.hasMoreTokens() )
        vec.addElement( rept.nextToken() );
    vec.removeElementAt( vec.size() - 1 );

    String pName = ct.getPackageName();         //start from Java package names
    if ( pName == null ) return;
    Vector pVec = new Vector();
    StringTokenizer pt = new StringTokenizer( pName,"." );
    while ( pt.hasMoreTokens() ) pVec.addElement( pt.nextToken() );

    int i1 = vec.size() - 1;
    int i2 = pVec.size() - 1;
    while ( i1 >= 0 && i2 >= 0 ) {                      //go R->L till mismatch
        String rep = (String)( vec.elementAt( i1 ) );
        String pkg = (String)( pVec.elementAt( i2 ) );
        if ( ! pkg.equals( rep ) ) break;
        i1--; i2--;
    }
    for ( int i3 = 0; i3 <= i1; i3++ )
        vec.removeElementAt( 0 );                                  //strip prefix
}
 
Example 6
Source File: List.java    From pluotsorbet with GNU General Public License v2.0 5 votes vote down vote up
private boolean testList(Enumeration e, String[] expected) {
	Vector found = new Vector(expected.length);
	
	while(e.hasMoreElements()) {
		String next = (String)e.nextElement();
		if (found.contains(next)) {
			assertTrueWithLog("list() returned duplicate strings: " + next, false);
			return false;
		}
		found.addElement(next);
	}
		
	for(int i=0; i<expected.length; i++) {
		int idx = found.indexOf(expected[i]);
		if (idx==-1) {
			assertTrueWithLog("list() did not return " + expected[i], false);
			return false;
		} else {
			found.removeElementAt(idx);
		}
	}
		
	if(found.size()>0) {
		String unexpected = (String)found.elementAt(0);
		assertTrueWithLog("list() returned unexpected strings " + unexpected, false);
		return false;
	}
	
	return true;
}
 
Example 7
Source File: TermTable.java    From LogicNG with Apache License 2.0 5 votes vote down vote up
/**
 * Deletes a column at a given index.
 * @param colIndex the index
 */
private void deleteColumn(final int colIndex) {
  this.columnHeaders.removeElementAt(colIndex);
  this.matrixColumns.removeElementAt(colIndex);
  for (final Vector<Boolean> line : this.matrixLines)
    line.removeElementAt(colIndex);
}
 
Example 8
Source File: BackTracker.java    From unitime with Apache License 2.0 5 votes vote down vote up
public static void markForBack(HttpServletRequest request, String uri, String title, boolean back, boolean clear) {
	synchronized (request.getSession()) {
		Vector backList = getBackList(request.getSession());
		if (clear) backList.clear();
		if (back) {
			if (uri==null && request.getAttribute("javax.servlet.forward.request_uri")==null) return;
			Object titleObj = (title==null?request.getAttribute("title"):title);
			String requestURI = (String)request.getAttribute("javax.servlet.forward.request_uri");
			String queryString = (String)request.getAttribute("javax.servlet.forward.query_string");
			if (queryString!=null && queryString.length()>0)
				requestURI += "?"+queryString;
			if (uri!=null)
				requestURI = uri;
			if (!backList.isEmpty()) {
				int found = -1;
				for (int idx = 0; idx<backList.size(); idx++) {
					String[] lastBack = (String[])backList.elementAt(idx);
					if (lastBack[0].equals(requestURI)) {
						found = idx; break;
					}
				}
				while (found>=0 && backList.size()>found)
					backList.removeElementAt(backList.size()-1);
			}
			backList.addElement(new String[]{requestURI,(titleObj==null?null:titleObj.toString())});
			//System.out.println("ADD BACK:"+requestURI+" ("+titleObj+")");
		}
	}
}
 
Example 9
Source File: RMIGenerator.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Compute the exceptions which need to be caught and rethrown in a
 * stub method before wrapping Exceptions in UnexpectedExceptions,
 * given the exceptions declared in the throws clause of the method.
 * Returns a Vector containing ClassDefinition objects for each
 * exception to catch.  Each exception is guaranteed to be unique,
 * i.e. not a subclass of any of the other exceptions in the Vector,
 * so the catch blocks for these exceptions may be generated in any
 * order relative to each other.
 *
 * RemoteException and RuntimeException are each automatically placed
 * in the returned Vector (if none of their superclasses are already
 * present), since those exceptions should always be directly rethrown
 * by a stub method.
 *
 * The returned Vector will be empty if java.lang.Exception or one
 * of its superclasses is in the throws clause of the method, indicating
 * that no exceptions need to be caught.
 */
private Vector<ClassDefinition> computeUniqueCatchList(ClassDeclaration[] exceptions) {
    Vector<ClassDefinition> uniqueList = new Vector<>();       // unique exceptions to catch

    uniqueList.addElement(defRuntimeException);
    uniqueList.addElement(defRemoteException);

    /* For each exception declared by the stub method's throws clause: */
nextException:
    for (int i = 0; i < exceptions.length; i++) {
        ClassDeclaration decl = exceptions[i];
        try {
            if (defException.subClassOf(env, decl)) {
                /*
                 * (If java.lang.Exception (or a superclass) was declared
                 * in the throws clause of this stub method, then we don't
                 * have to bother catching anything; clear the list and
                 * return.)
                 */
                uniqueList.clear();
                break;
            } else if (!defException.superClassOf(env, decl)) {
                /*
                 * Ignore other Throwables that do not extend Exception,
                 * since they do not need to be caught anyway.
                 */
                continue;
            }
            /*
             * Compare this exception against the current list of
             * exceptions that need to be caught:
             */
            for (int j = 0; j < uniqueList.size();) {
                ClassDefinition def = uniqueList.elementAt(j);
                if (def.superClassOf(env, decl)) {
                    /*
                     * If a superclass of this exception is already on
                     * the list to catch, then ignore and continue;
                     */
                    continue nextException;
                } else if (def.subClassOf(env, decl)) {
                    /*
                     * If a subclass of this exception is on the list
                     * to catch, then remove it.
                     */
                    uniqueList.removeElementAt(j);
                } else {
                    j++;    // else continue comparing
                }
            }
            /* This exception is unique: add it to the list to catch. */
            uniqueList.addElement(decl.getClassDefinition(env));
        } catch (ClassNotFound e) {
            env.error(0, "class.not.found", e.name, decl.getName());
            /*
             * REMIND: We do not exit from this exceptional condition,
             * generating questionable code and likely letting the
             * compiler report a resulting error later.
             */
        }
    }
    return uniqueList;
}
 
Example 10
Source File: Whitespace.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Orders a set or rules by priority, removes redundant rules and rules
 * that are shadowed by stronger, contradicting rules.
 */
private static int prioritizeRules(Vector rules) {
    WhitespaceRule currentRule;
    int defaultAction = PRESERVE_SPACE;

    // Sort all rules with regard to priority
    quicksort(rules, 0, rules.size()-1);

    // Check if there are any "xsl:strip-space" elements at all.
    // If there are no xsl:strip elements we can ignore all xsl:preserve
    // elements and signal that all whitespaces should be preserved
    boolean strip = false;
    for (int i = 0; i < rules.size(); i++) {
        currentRule = (WhitespaceRule)rules.elementAt(i);
        if (currentRule.getAction() == STRIP_SPACE) {
            strip = true;
        }
    }
    // Return with default action: PRESERVE_SPACE
    if (!strip) {
        rules.removeAllElements();
        return PRESERVE_SPACE;
    }

    // Remove all rules that are contradicted by rules with higher priority
    for (int idx = 0; idx < rules.size(); ) {
        currentRule = (WhitespaceRule)rules.elementAt(idx);

        // Remove this single rule if it has no purpose
        if (findContradictingRule(rules,currentRule) != null) {
            rules.remove(idx);
        }
        else {
            // Remove all following rules if this one overrides all
            if (currentRule.getStrength() == RULE_ALL) {
                defaultAction = currentRule.getAction();
                for (int i = idx; i < rules.size(); i++) {
                    rules.removeElementAt(i);
                }
            }
            // Skip to next rule (there might not be any)...
            idx++;
        }
    }

    // The rules vector could be empty if first rule has strength RULE_ALL
    if (rules.size() == 0) {
        return defaultAction;
    }

    // Now work backwards and strip away all rules that have the same
    // action as the default rule (no reason the check them at the end).
    do {
        currentRule = (WhitespaceRule)rules.lastElement();
        if (currentRule.getAction() == defaultAction) {
            rules.removeElementAt(rules.size() - 1);
        }
        else {
            break;
        }
    } while (rules.size() > 0);

    // Signal that whitespace detection predicate must be used.
    return defaultAction;
}
 
Example 11
Source File: RMIGenerator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Compute the exceptions which need to be caught and rethrown in a
 * stub method before wrapping Exceptions in UnexpectedExceptions,
 * given the exceptions declared in the throws clause of the method.
 * Returns a Vector containing ClassDefinition objects for each
 * exception to catch.  Each exception is guaranteed to be unique,
 * i.e. not a subclass of any of the other exceptions in the Vector,
 * so the catch blocks for these exceptions may be generated in any
 * order relative to each other.
 *
 * RemoteException and RuntimeException are each automatically placed
 * in the returned Vector (if none of their superclasses are already
 * present), since those exceptions should always be directly rethrown
 * by a stub method.
 *
 * The returned Vector will be empty if java.lang.Exception or one
 * of its superclasses is in the throws clause of the method, indicating
 * that no exceptions need to be caught.
 */
private Vector<ClassDefinition> computeUniqueCatchList(ClassDeclaration[] exceptions) {
    Vector<ClassDefinition> uniqueList = new Vector<>();       // unique exceptions to catch

    uniqueList.addElement(defRuntimeException);
    uniqueList.addElement(defRemoteException);

    /* For each exception declared by the stub method's throws clause: */
nextException:
    for (int i = 0; i < exceptions.length; i++) {
        ClassDeclaration decl = exceptions[i];
        try {
            if (defException.subClassOf(env, decl)) {
                /*
                 * (If java.lang.Exception (or a superclass) was declared
                 * in the throws clause of this stub method, then we don't
                 * have to bother catching anything; clear the list and
                 * return.)
                 */
                uniqueList.clear();
                break;
            } else if (!defException.superClassOf(env, decl)) {
                /*
                 * Ignore other Throwables that do not extend Exception,
                 * since they do not need to be caught anyway.
                 */
                continue;
            }
            /*
             * Compare this exception against the current list of
             * exceptions that need to be caught:
             */
            for (int j = 0; j < uniqueList.size();) {
                ClassDefinition def = uniqueList.elementAt(j);
                if (def.superClassOf(env, decl)) {
                    /*
                     * If a superclass of this exception is already on
                     * the list to catch, then ignore and continue;
                     */
                    continue nextException;
                } else if (def.subClassOf(env, decl)) {
                    /*
                     * If a subclass of this exception is on the list
                     * to catch, then remove it.
                     */
                    uniqueList.removeElementAt(j);
                } else {
                    j++;    // else continue comparing
                }
            }
            /* This exception is unique: add it to the list to catch. */
            uniqueList.addElement(decl.getClassDefinition(env));
        } catch (ClassNotFound e) {
            env.error(0, "class.not.found", e.name, decl.getName());
            /*
             * REMIND: We do not exit from this exceptional condition,
             * generating questionable code and likely letting the
             * compiler report a resulting error later.
             */
        }
    }
    return uniqueList;
}
 
Example 12
Source File: Whitespace.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Orders a set or rules by priority, removes redundant rules and rules
 * that are shadowed by stronger, contradicting rules.
 */
private static int prioritizeRules(Vector rules) {
    WhitespaceRule currentRule;
    int defaultAction = PRESERVE_SPACE;

    // Sort all rules with regard to priority
    quicksort(rules, 0, rules.size()-1);

    // Check if there are any "xsl:strip-space" elements at all.
    // If there are no xsl:strip elements we can ignore all xsl:preserve
    // elements and signal that all whitespaces should be preserved
    boolean strip = false;
    for (int i = 0; i < rules.size(); i++) {
        currentRule = (WhitespaceRule)rules.elementAt(i);
        if (currentRule.getAction() == STRIP_SPACE) {
            strip = true;
        }
    }
    // Return with default action: PRESERVE_SPACE
    if (!strip) {
        rules.removeAllElements();
        return PRESERVE_SPACE;
    }

    // Remove all rules that are contradicted by rules with higher priority
    for (int idx = 0; idx < rules.size(); ) {
        currentRule = (WhitespaceRule)rules.elementAt(idx);

        // Remove this single rule if it has no purpose
        if (findContradictingRule(rules,currentRule) != null) {
            rules.remove(idx);
        }
        else {
            // Remove all following rules if this one overrides all
            if (currentRule.getStrength() == RULE_ALL) {
                defaultAction = currentRule.getAction();
                for (int i = idx; i < rules.size(); i++) {
                    rules.removeElementAt(i);
                }
            }
            // Skip to next rule (there might not be any)...
            idx++;
        }
    }

    // The rules vector could be empty if first rule has strength RULE_ALL
    if (rules.size() == 0) {
        return defaultAction;
    }

    // Now work backwards and strip away all rules that have the same
    // action as the default rule (no reason the check them at the end).
    do {
        currentRule = (WhitespaceRule)rules.lastElement();
        if (currentRule.getAction() == defaultAction) {
            rules.removeElementAt(rules.size() - 1);
        }
        else {
            break;
        }
    } while (rules.size() > 0);

    // Signal that whitespace detection predicate must be used.
    return defaultAction;
}
 
Example 13
Source File: RMIGenerator.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Compute the exceptions which need to be caught and rethrown in a
 * stub method before wrapping Exceptions in UnexpectedExceptions,
 * given the exceptions declared in the throws clause of the method.
 * Returns a Vector containing ClassDefinition objects for each
 * exception to catch.  Each exception is guaranteed to be unique,
 * i.e. not a subclass of any of the other exceptions in the Vector,
 * so the catch blocks for these exceptions may be generated in any
 * order relative to each other.
 *
 * RemoteException and RuntimeException are each automatically placed
 * in the returned Vector (if none of their superclasses are already
 * present), since those exceptions should always be directly rethrown
 * by a stub method.
 *
 * The returned Vector will be empty if java.lang.Exception or one
 * of its superclasses is in the throws clause of the method, indicating
 * that no exceptions need to be caught.
 */
private Vector<ClassDefinition> computeUniqueCatchList(ClassDeclaration[] exceptions) {
    Vector<ClassDefinition> uniqueList = new Vector<>();       // unique exceptions to catch

    uniqueList.addElement(defRuntimeException);
    uniqueList.addElement(defRemoteException);

    /* For each exception declared by the stub method's throws clause: */
nextException:
    for (int i = 0; i < exceptions.length; i++) {
        ClassDeclaration decl = exceptions[i];
        try {
            if (defException.subClassOf(env, decl)) {
                /*
                 * (If java.lang.Exception (or a superclass) was declared
                 * in the throws clause of this stub method, then we don't
                 * have to bother catching anything; clear the list and
                 * return.)
                 */
                uniqueList.clear();
                break;
            } else if (!defException.superClassOf(env, decl)) {
                /*
                 * Ignore other Throwables that do not extend Exception,
                 * since they do not need to be caught anyway.
                 */
                continue;
            }
            /*
             * Compare this exception against the current list of
             * exceptions that need to be caught:
             */
            for (int j = 0; j < uniqueList.size();) {
                ClassDefinition def = uniqueList.elementAt(j);
                if (def.superClassOf(env, decl)) {
                    /*
                     * If a superclass of this exception is already on
                     * the list to catch, then ignore and continue;
                     */
                    continue nextException;
                } else if (def.subClassOf(env, decl)) {
                    /*
                     * If a subclass of this exception is on the list
                     * to catch, then remove it.
                     */
                    uniqueList.removeElementAt(j);
                } else {
                    j++;    // else continue comparing
                }
            }
            /* This exception is unique: add it to the list to catch. */
            uniqueList.addElement(decl.getClassDefinition(env));
        } catch (ClassNotFound e) {
            env.error(0, "class.not.found", e.name, decl.getName());
            /*
             * REMIND: We do not exit from this exceptional condition,
             * generating questionable code and likely letting the
             * compiler report a resulting error later.
             */
        }
    }
    return uniqueList;
}
 
Example 14
Source File: Whitespace.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Orders a set or rules by priority, removes redundant rules and rules
 * that are shadowed by stronger, contradicting rules.
 */
private static int prioritizeRules(Vector rules) {
    WhitespaceRule currentRule;
    int defaultAction = PRESERVE_SPACE;

    // Sort all rules with regard to priority
    quicksort(rules, 0, rules.size()-1);

    // Check if there are any "xsl:strip-space" elements at all.
    // If there are no xsl:strip elements we can ignore all xsl:preserve
    // elements and signal that all whitespaces should be preserved
    boolean strip = false;
    for (int i = 0; i < rules.size(); i++) {
        currentRule = (WhitespaceRule)rules.elementAt(i);
        if (currentRule.getAction() == STRIP_SPACE) {
            strip = true;
        }
    }
    // Return with default action: PRESERVE_SPACE
    if (!strip) {
        rules.removeAllElements();
        return PRESERVE_SPACE;
    }

    // Remove all rules that are contradicted by rules with higher priority
    for (int idx = 0; idx < rules.size(); ) {
        currentRule = (WhitespaceRule)rules.elementAt(idx);

        // Remove this single rule if it has no purpose
        if (findContradictingRule(rules,currentRule) != null) {
            rules.remove(idx);
        }
        else {
            // Remove all following rules if this one overrides all
            if (currentRule.getStrength() == RULE_ALL) {
                defaultAction = currentRule.getAction();
                for (int i = idx; i < rules.size(); i++) {
                    rules.removeElementAt(i);
                }
            }
            // Skip to next rule (there might not be any)...
            idx++;
        }
    }

    // The rules vector could be empty if first rule has strength RULE_ALL
    if (rules.size() == 0) {
        return defaultAction;
    }

    // Now work backwards and strip away all rules that have the same
    // action as the default rule (no reason the check them at the end).
    do {
        currentRule = (WhitespaceRule)rules.lastElement();
        if (currentRule.getAction() == defaultAction) {
            rules.removeElementAt(rules.size() - 1);
        }
        else {
            break;
        }
    } while (rules.size() > 0);

    // Signal that whitespace detection predicate must be used.
    return defaultAction;
}
 
Example 15
Source File: Whitespace.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Orders a set or rules by priority, removes redundant rules and rules
 * that are shadowed by stronger, contradicting rules.
 */
private static int prioritizeRules(Vector rules) {
    WhitespaceRule currentRule;
    int defaultAction = PRESERVE_SPACE;

    // Sort all rules with regard to priority
    quicksort(rules, 0, rules.size()-1);

    // Check if there are any "xsl:strip-space" elements at all.
    // If there are no xsl:strip elements we can ignore all xsl:preserve
    // elements and signal that all whitespaces should be preserved
    boolean strip = false;
    for (int i = 0; i < rules.size(); i++) {
        currentRule = (WhitespaceRule)rules.elementAt(i);
        if (currentRule.getAction() == STRIP_SPACE) {
            strip = true;
        }
    }
    // Return with default action: PRESERVE_SPACE
    if (!strip) {
        rules.removeAllElements();
        return PRESERVE_SPACE;
    }

    // Remove all rules that are contradicted by rules with higher priority
    for (int idx = 0; idx < rules.size(); ) {
        currentRule = (WhitespaceRule)rules.elementAt(idx);

        // Remove this single rule if it has no purpose
        if (findContradictingRule(rules,currentRule) != null) {
            rules.remove(idx);
        }
        else {
            // Remove all following rules if this one overrides all
            if (currentRule.getStrength() == RULE_ALL) {
                defaultAction = currentRule.getAction();
                for (int i = idx; i < rules.size(); i++) {
                    rules.removeElementAt(i);
                }
            }
            // Skip to next rule (there might not be any)...
            idx++;
        }
    }

    // The rules vector could be empty if first rule has strength RULE_ALL
    if (rules.size() == 0) {
        return defaultAction;
    }

    // Now work backwards and strip away all rules that have the same
    // action as the default rule (no reason the check them at the end).
    do {
        currentRule = (WhitespaceRule)rules.lastElement();
        if (currentRule.getAction() == defaultAction) {
            rules.removeElementAt(rules.size() - 1);
        }
        else {
            break;
        }
    } while (rules.size() > 0);

    // Signal that whitespace detection predicate must be used.
    return defaultAction;
}
 
Example 16
Source File: RMIGenerator.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Compute the exceptions which need to be caught and rethrown in a
 * stub method before wrapping Exceptions in UnexpectedExceptions,
 * given the exceptions declared in the throws clause of the method.
 * Returns a Vector containing ClassDefinition objects for each
 * exception to catch.  Each exception is guaranteed to be unique,
 * i.e. not a subclass of any of the other exceptions in the Vector,
 * so the catch blocks for these exceptions may be generated in any
 * order relative to each other.
 *
 * RemoteException and RuntimeException are each automatically placed
 * in the returned Vector (if none of their superclasses are already
 * present), since those exceptions should always be directly rethrown
 * by a stub method.
 *
 * The returned Vector will be empty if java.lang.Exception or one
 * of its superclasses is in the throws clause of the method, indicating
 * that no exceptions need to be caught.
 */
private Vector<ClassDefinition> computeUniqueCatchList(ClassDeclaration[] exceptions) {
    Vector<ClassDefinition> uniqueList = new Vector<>();       // unique exceptions to catch

    uniqueList.addElement(defRuntimeException);
    uniqueList.addElement(defRemoteException);

    /* For each exception declared by the stub method's throws clause: */
nextException:
    for (int i = 0; i < exceptions.length; i++) {
        ClassDeclaration decl = exceptions[i];
        try {
            if (defException.subClassOf(env, decl)) {
                /*
                 * (If java.lang.Exception (or a superclass) was declared
                 * in the throws clause of this stub method, then we don't
                 * have to bother catching anything; clear the list and
                 * return.)
                 */
                uniqueList.clear();
                break;
            } else if (!defException.superClassOf(env, decl)) {
                /*
                 * Ignore other Throwables that do not extend Exception,
                 * since they do not need to be caught anyway.
                 */
                continue;
            }
            /*
             * Compare this exception against the current list of
             * exceptions that need to be caught:
             */
            for (int j = 0; j < uniqueList.size();) {
                ClassDefinition def = uniqueList.elementAt(j);
                if (def.superClassOf(env, decl)) {
                    /*
                     * If a superclass of this exception is already on
                     * the list to catch, then ignore and continue;
                     */
                    continue nextException;
                } else if (def.subClassOf(env, decl)) {
                    /*
                     * If a subclass of this exception is on the list
                     * to catch, then remove it.
                     */
                    uniqueList.removeElementAt(j);
                } else {
                    j++;    // else continue comparing
                }
            }
            /* This exception is unique: add it to the list to catch. */
            uniqueList.addElement(decl.getClassDefinition(env));
        } catch (ClassNotFound e) {
            env.error(0, "class.not.found", e.name, decl.getName());
            /*
             * REMIND: We do not exit from this exceptional condition,
             * generating questionable code and likely letting the
             * compiler report a resulting error later.
             */
        }
    }
    return uniqueList;
}
 
Example 17
Source File: RMIGenerator.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Compute the exceptions which need to be caught and rethrown in a
 * stub method before wrapping Exceptions in UnexpectedExceptions,
 * given the exceptions declared in the throws clause of the method.
 * Returns a Vector containing ClassDefinition objects for each
 * exception to catch.  Each exception is guaranteed to be unique,
 * i.e. not a subclass of any of the other exceptions in the Vector,
 * so the catch blocks for these exceptions may be generated in any
 * order relative to each other.
 *
 * RemoteException and RuntimeException are each automatically placed
 * in the returned Vector (if none of their superclasses are already
 * present), since those exceptions should always be directly rethrown
 * by a stub method.
 *
 * The returned Vector will be empty if java.lang.Exception or one
 * of its superclasses is in the throws clause of the method, indicating
 * that no exceptions need to be caught.
 */
private Vector<ClassDefinition> computeUniqueCatchList(ClassDeclaration[] exceptions) {
    Vector<ClassDefinition> uniqueList = new Vector<>();       // unique exceptions to catch

    uniqueList.addElement(defRuntimeException);
    uniqueList.addElement(defRemoteException);

    /* For each exception declared by the stub method's throws clause: */
nextException:
    for (int i = 0; i < exceptions.length; i++) {
        ClassDeclaration decl = exceptions[i];
        try {
            if (defException.subClassOf(env, decl)) {
                /*
                 * (If java.lang.Exception (or a superclass) was declared
                 * in the throws clause of this stub method, then we don't
                 * have to bother catching anything; clear the list and
                 * return.)
                 */
                uniqueList.clear();
                break;
            } else if (!defException.superClassOf(env, decl)) {
                /*
                 * Ignore other Throwables that do not extend Exception,
                 * since they do not need to be caught anyway.
                 */
                continue;
            }
            /*
             * Compare this exception against the current list of
             * exceptions that need to be caught:
             */
            for (int j = 0; j < uniqueList.size();) {
                ClassDefinition def = uniqueList.elementAt(j);
                if (def.superClassOf(env, decl)) {
                    /*
                     * If a superclass of this exception is already on
                     * the list to catch, then ignore and continue;
                     */
                    continue nextException;
                } else if (def.subClassOf(env, decl)) {
                    /*
                     * If a subclass of this exception is on the list
                     * to catch, then remove it.
                     */
                    uniqueList.removeElementAt(j);
                } else {
                    j++;    // else continue comparing
                }
            }
            /* This exception is unique: add it to the list to catch. */
            uniqueList.addElement(decl.getClassDefinition(env));
        } catch (ClassNotFound e) {
            env.error(0, "class.not.found", e.name, decl.getName());
            /*
             * REMIND: We do not exit from this exceptional condition,
             * generating questionable code and likely letting the
             * compiler report a resulting error later.
             */
        }
    }
    return uniqueList;
}
 
Example 18
Source File: Phrase.java    From jmg with GNU General Public License v2.0 4 votes vote down vote up
/**
       * Deletes the last note in the phrase
 */
   public void removeLastNote() {
    Vector vct = (Vector)this.noteList;
    vct.removeElementAt(vct.size()-1);
}
 
Example 19
Source File: Farming.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
/**
	* Simulate life in the pond, using the values indicated in the
	* documentation.
	* @param fish
	*   Vector of fish
	* @param weeds
	*   Vector of weeds
	* @param time
	**/
	public void simulatePond(Vector<Herbivore> fish, Vector<Plant> weeds, double time) {
	   int i;
	   int manyIterations;
	   int index;
	   Herbivore nextFish;
	   Plant nextWeed;
	
	   int numFish = fish.size();
	   int numWeeds = weeds.size();
	   // Have randomly selected fish nibble on randomly selected plants
	   nibbleIterationCache += AVERAGE_NIBBLES * time * numFish;
	   
	   if (nibbleIterationCache > numFish) {
		   manyIterations = (int)nibbleIterationCache;
		   if (manyIterations > numFish * 3)
			   manyIterations = numFish * 3;
		   if (manyIterations < numFish)
			   manyIterations = numFish;
		   if (manyIterations > numWeeds)
			   manyIterations = numWeeds;
		   nibbleIterationCache = nibbleIterationCache - manyIterations;
//		   System.out.println("time: " + Math.round(time*100.0)/100.0 
//				   + "   nibbleIterationCache : " + Math.round(nibbleIterationCache*100.0)/100.0
//				   + "   manyIterations : " + Math.round(manyIterations*100.0)/100.0
//				   );
		   for (i = 0; i < manyIterations; i++) {
			   index = RandomUtil.getRandomInt(numFish-1);// (int) (RandomUtil.getRandomDouble(1.0) * fish.size()); //
			   nextFish = fish.elementAt(index);
			   index = RandomUtil.getRandomInt(numWeeds-1);// (int) (RandomUtil.getRandomDouble(1.0) * weeds.size()); //
			   nextWeed = weeds.elementAt(index);
			   nextFish.nibble(nextWeed);
		   } 
		   
		   // Simulate the fish
		   i = 0;
		   while (i < fish.size()) {
		      nextFish = fish.elementAt(i);
		      nextFish.growPerFrame();
		      if (nextFish.isAlive())
		         i++;
		      else
		         fish.removeElementAt(i);
		   }
		
		   // Simulate the weeds
		   for (i = 0; i < weeds.size(); i++) {
		      nextWeed = weeds.elementAt(i);
		      nextWeed.growPerFrame();
		   }
	   }
	
	   // Create some new fish, according to the BIRTH_RATE constant
	   birthIterationCache += BIRTH_RATE * time * fish.size() * (1 + .01 * RandomUtil.getRandomInt(-10, 10));
	   if (birthIterationCache > 1) {
		   manyIterations = (int)birthIterationCache;
		   birthIterationCache = birthIterationCache - manyIterations;
		   for (i = 0; i < manyIterations; i++)
		       fish.addElement(new Herbivore(FISH_SIZE, 0, FISH_SIZE * FRACTION));
	   }
	}
 
Example 20
Source File: Whitespace.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * Orders a set or rules by priority, removes redundant rules and rules
 * that are shadowed by stronger, contradicting rules.
 */
private static int prioritizeRules(Vector rules) {
    WhitespaceRule currentRule;
    int defaultAction = PRESERVE_SPACE;

    // Sort all rules with regard to priority
    quicksort(rules, 0, rules.size()-1);

    // Check if there are any "xsl:strip-space" elements at all.
    // If there are no xsl:strip elements we can ignore all xsl:preserve
    // elements and signal that all whitespaces should be preserved
    boolean strip = false;
    for (int i = 0; i < rules.size(); i++) {
        currentRule = (WhitespaceRule)rules.elementAt(i);
        if (currentRule.getAction() == STRIP_SPACE) {
            strip = true;
        }
    }
    // Return with default action: PRESERVE_SPACE
    if (!strip) {
        rules.removeAllElements();
        return PRESERVE_SPACE;
    }

    // Remove all rules that are contradicted by rules with higher priority
    for (int idx = 0; idx < rules.size(); ) {
        currentRule = (WhitespaceRule)rules.elementAt(idx);

        // Remove this single rule if it has no purpose
        if (findContradictingRule(rules,currentRule) != null) {
            rules.remove(idx);
        }
        else {
            // Remove all following rules if this one overrides all
            if (currentRule.getStrength() == RULE_ALL) {
                defaultAction = currentRule.getAction();
                for (int i = idx; i < rules.size(); i++) {
                    rules.removeElementAt(i);
                }
            }
            // Skip to next rule (there might not be any)...
            idx++;
        }
    }

    // The rules vector could be empty if first rule has strength RULE_ALL
    if (rules.size() == 0) {
        return defaultAction;
    }

    // Now work backwards and strip away all rules that have the same
    // action as the default rule (no reason the check them at the end).
    do {
        currentRule = (WhitespaceRule)rules.lastElement();
        if (currentRule.getAction() == defaultAction) {
            rules.removeElementAt(rules.size() - 1);
        }
        else {
            break;
        }
    } while (rules.size() > 0);

    // Signal that whitespace detection predicate must be used.
    return defaultAction;
}