java.util.Vector#removeElementAt ( )源码实例Demo

下面列出了java.util.Vector#removeElementAt ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: openjdk-8   文件: DocumentImpl.java
/**
 * 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.
        }
    }
}
 
源代码2 项目: jdk1.8-source-analysis   文件: StringContent.java
/**
 * 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();
    }
}
 
源代码3 项目: openjdk-8-source   文件: StringContent.java
/**
 * 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();
    }
}
 
源代码4 项目: WhereYouGo   文件: ListActionsActivity.java
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;
}
 
源代码5 项目: openjdk-8   文件: IDLGenerator.java
/**
 * 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
}
 
源代码6 项目: pluotsorbet   文件: List.java
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;
}
 
源代码7 项目: unitime   文件: BackTracker.java
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+")");
		}
	}
}
 
源代码8 项目: LogicNG   文件: TermTable.java
/**
 * 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);
}
 
源代码9 项目: jdk1.8-source-analysis   文件: Whitespace.java
/**
 * 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;
}
 
源代码10 项目: mars-sim   文件: Farming.java
/**
	* 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));
	   }
	}
 
源代码11 项目: jmg   文件: Phrase.java
/**
       * Deletes the last note in the phrase
 */
   public void removeLastNote() {
    Vector vct = (Vector)this.noteList;
    vct.removeElementAt(vct.size()-1);
}
 
源代码12 项目: openjdk-8   文件: RMIGenerator.java
/**
 * 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;
}
 
源代码13 项目: TencentKona-8   文件: RMIGenerator.java
/**
 * 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;
}
 
源代码14 项目: TencentKona-8   文件: Whitespace.java
/**
 * 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;
}
 
源代码15 项目: openjdk-jdk8u   文件: Whitespace.java
/**
 * 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;
}
 
源代码16 项目: openjdk-jdk8u   文件: RMIGenerator.java
/**
 * 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;
}
 
源代码17 项目: jdk8u60   文件: Whitespace.java
/**
 * 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;
}
 
源代码18 项目: openjdk-jdk8u-backup   文件: RMIGenerator.java
/**
 * 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;
}
 
源代码19 项目: hottub   文件: Whitespace.java
/**
 * 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;
}
 
源代码20 项目: jdk8u-jdk   文件: RMIGenerator.java
/**
 * 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;
}