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

The following are Jave code examples for showing how to use removeAllElements() of the java.util.Vector class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: OpenJSharp   File: IDLGenerator.java   View Source Code Vote up 6 votes
/**
 * 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 2
Project: biosses   File: WordVectorConstructor.java   View Source Code Vote up 6 votes
public double getSimilarity(String sentence1, String sentence2) throws SLIB_Exception, IOException {
    String[] sentence1_split = sentence1.split("\\s+");
    String[] sentence2_split = sentence2.split("\\s+");

    Vector<Double> avgVec1 = new Vector<Double>();
    Vector<Double> avgVec2 = new Vector<Double>();

    Vector<Double> vector1 = new Vector<Double>();
    Vector<Double> vector2 = new Vector<Double>();

    int count1=0, count2=0;
    for(String s1: sentence1_split){
        if(wordvector.containsKey(s1)){
            vector1 = wordvector.get(s1);
        }
        else vector1.removeAllElements();
    }

    CosineSimilarity similarityMeasure = new CosineSimilarity(vector1, vector2);
    double similarityScore = similarityMeasure.calculateDistanceAmongVectors();
    return similarityScore;

}
 
Example 3
Project: openjdk-jdk10   File: IDLGenerator.java   View Source Code Vote up 6 votes
/**
 * 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 4
Project: ideal   File: VectorTarget4.java   View Source Code Vote up 6 votes
public static void main(String[] args) {
	try {
		Vector v = new Vector();
		v.removeAllElements();
		v.firstElement();
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example 5
Project: OpenDiabetes   File: TestBench.java   View Source Code Vote up 5 votes
void oneRound(String url, String user,
              String password) throws InterruptedException, SQLException {

    Vector      vClient  = new Vector();
    Thread      Client   = null;
    Enumeration e        = null;
    Connection  guardian = null;

    //
    start_time = System.currentTimeMillis();

    for (int i = 0; i < n_clients; i++) {
        if (useStoredProcedure) {
            Client = new ClientThreadProcedure(
                n_txn_per_client, url, user, password,
                Connection.TRANSACTION_READ_COMMITTED);
        } else {
            Client =
                new ClientThread(n_txn_per_client, url, user, password,
                                 Connection.TRANSACTION_READ_COMMITTED);
        }

        Client.start();
        vClient.addElement(Client);
    }

    /*
     ** Barrier to complete this test session
     */
    e = vClient.elements();

    while (e.hasMoreElements()) {
        Client = (Thread) e.nextElement();

        Client.join();
    }

    vClient.removeAllElements();
    reportDone();

    guardian = connect(url, user, password);

    if (count_results) {
        checkSums(guardian);
    }

    connectClose(guardian);
}
 
Example 6
Project: OpenDiabetes   File: JDBCBench.java   View Source Code Vote up 5 votes
void oneRound(String url, String user, String password,
              boolean transactions,
              boolean prepared) throws InterruptedException, SQLException {

    Vector      vClient  = new Vector();
    Thread      Client   = null;
    Enumeration e        = null;
    Connection  guardian = null;

    //
    this.transactions  = transactions;
    this.prepared_stmt = prepared;
    start_time         = System.currentTimeMillis();

    for (int i = 0; i < n_clients; i++) {
        Client = new ClientThread(n_txn_per_client, url, user, password,
                                  Connection.TRANSACTION_READ_COMMITTED);

        Client.start();
        vClient.addElement(Client);
    }

    /*
     ** Barrier to complete this test session
     */
    e = vClient.elements();

    while (e.hasMoreElements()) {
        Client = (Thread) e.nextElement();

        Client.join();
    }

    vClient.removeAllElements();
    reportDone();

    guardian = connect(url, user, password);

    checkSums(guardian);
    connectClose(guardian);
}
 
Example 7
Project: QN-ACTR-Release   File: ModelChecker.java   View Source Code Vote up 5 votes
/**
 * Checks that no closed classes may be routed into a Sink. If a problem is found it raises
 * to "true" the corresponding position inside the errors array.
 */
private void checkForRoutingError() {
	//vector collecting all the station keys where routing problems occour
	// for this close class
	Vector<Object> problemsPerClass = new Vector<Object>(0, 1);
	Vector<Object> closedClassKeys = class_def.getClosedClassKeys();
	Vector<Object> startingPoints = new Vector<Object>(0, 1);
	//get the vector of the possible starting points
	Vector<Object> noSourceSink = station_def.getStationKeysNoSourceSink();
	for (int i = 0; i < closedClassKeys.size(); i++) {
		//remove all elements from the problemsPerClass vector
		problemsPerClass.removeAllElements();
		//create the vector containing the already visited station keys
		Vector<Object> alreadyVisited = new Vector<Object>(0, 1);
		//get the class at i
		Object thisClassKey = closedClassKeys.get(i);
		//checks for each possible starting point if there are preloaded jobs for the class i.
		//In that case put it into the startingPoints vector
		for (int j = 0; j < noSourceSink.size(); j++) {
			Object thisElementKey = noSourceSink.get(j);
			int preloadedJobs = simulation_def.getPreloadedJobs(thisElementKey, thisClassKey).intValue();
			if (preloadedJobs > 0) {
				startingPoints.add(thisElementKey);
			}
		}
		//start the explore algorithm for each of the station containing some preloaded jobs for class i
		for (int j = 0; j < startingPoints.size(); j++) {
			//get the element at j
			Object thisStartingPoint = startingPoints.get(j);
			//if this possible starting point has not been visited yet
			if (!alreadyVisited.contains(thisStartingPoint)) {
				alreadyVisited.add(thisStartingPoint);
				Vector<Object> problemsForThisStartingPoint = exploreForRoutingProblems(thisClassKey, thisStartingPoint, alreadyVisited);
				for (int k = 0; k < problemsForThisStartingPoint.size(); k++) {
					problemsPerClass.add(problemsForThisStartingPoint.get(k));
				}
			}
		}
		if (!problemsPerClass.isEmpty()) {
			routingErrors.put(thisClassKey, (Vector<Object>) problemsPerClass.clone());
			errors[ROUTING_ERROR] = true;
		}
	}
}
 
Example 8
Project: QN-ACTR-Release   File: ModelChecker.java   View Source Code Vote up 5 votes
/**
 * Checks that no closed classes may be routed into a station whose forward station(s) are
 * all sink. If a problem is found it raises to "true" the corresponding position inside
 * the errors array.
 */
private void checkForAllForwardStationsAreSinkError() {
	//vector collecting all the station keys where errors occour
	// for this close class
	Vector<Object> problemsPerClass = new Vector<Object>(0, 1);
	Vector<Object> closedClassKeys = class_def.getClosedClassKeys();
	Vector<Object> startingPoints = new Vector<Object>(0, 1);
	//get the vector of the possible starting points
	Vector<Object> noSourceSink = station_def.getStationKeysNoSourceSink();
	for (int i = 0; i < closedClassKeys.size(); i++) {
		//remove all elements from the problemsPerClass vector
		problemsPerClass.removeAllElements();
		//create the vector containing the already visited station keys
		Vector<Object> alreadyVisited = new Vector<Object>(0, 1);
		//get the class at i
		Object thisClassKey = closedClassKeys.get(i);
		//checks for each possible starting point if there are preloaded jobs for the class i.
		//In that case put it into the startingPoints vector
		for (int j = 0; j < noSourceSink.size(); j++) {
			Object thisElementKey = noSourceSink.get(j);
			int preloadedJobs = simulation_def.getPreloadedJobs(thisElementKey, thisClassKey).intValue();
			if (preloadedJobs > 0) {
				startingPoints.add(thisElementKey);
			}
		}
		//start the explore algorithm for each of the station containing some preloaded jobs for class i
		for (int j = 0; j < startingPoints.size(); j++) {
			//get the element at j
			Object thisStartingPoint = startingPoints.get(j);
			//if this possible starting point has not been visited yet
			if (!alreadyVisited.contains(thisStartingPoint)) {
				alreadyVisited.add(thisStartingPoint);
				Vector<Object> problemsForThisStartingPoint = this.exploreForAllForwardStationAreSink(thisClassKey, thisStartingPoint,
						alreadyVisited);
				for (int k = 0; k < problemsForThisStartingPoint.size(); k++) {
					problemsPerClass.add(problemsForThisStartingPoint.get(k));
				}
			}
		}
		if (!problemsPerClass.isEmpty()) {
			allForwardStationsAreSinkErrors.put(thisClassKey, (Vector<Object>) problemsPerClass.clone());
			errors[ALL_FORWARD_STATION_ARE_SINK_ERROR] = true;
		}
	}
}
 
Example 9
Project: dev-courses   File: TestBench.java   View Source Code Vote up 5 votes
void oneRound(String url, String user,
              String password) throws InterruptedException, SQLException {

    Vector      vClient  = new Vector();
    Thread      Client   = null;
    Enumeration e        = null;
    Connection  guardian = null;

    //
    start_time = System.currentTimeMillis();

    for (int i = 0; i < n_clients; i++) {
        if (useStoredProcedure) {
            Client = new ClientThreadProcedure(
                n_txn_per_client, url, user, password,
                Connection.TRANSACTION_READ_COMMITTED);
        } else {
            Client =
                new ClientThread(n_txn_per_client, url, user, password,
                                 Connection.TRANSACTION_READ_COMMITTED);
        }

        Client.start();
        vClient.addElement(Client);
    }

    /*
     ** Barrier to complete this test session
     */
    e = vClient.elements();

    while (e.hasMoreElements()) {
        Client = (Thread) e.nextElement();

        Client.join();
    }

    vClient.removeAllElements();
    reportDone();

    guardian = connect(url, user, password);

    if (count_results) {
        checkSums(guardian);
    }

    connectClose(guardian);
}
 
Example 10
Project: dev-courses   File: JDBCBench.java   View Source Code Vote up 5 votes
void oneRound(String url, String user, String password,
              boolean transactions,
              boolean prepared) throws InterruptedException, SQLException {

    Vector      vClient  = new Vector();
    Thread      Client   = null;
    Enumeration e        = null;
    Connection  guardian = null;

    //
    this.transactions  = transactions;
    this.prepared_stmt = prepared;
    start_time         = System.currentTimeMillis();

    for (int i = 0; i < n_clients; i++) {
        Client = new ClientThread(n_txn_per_client, url, user, password,
                                  Connection.TRANSACTION_READ_COMMITTED);

        Client.start();
        vClient.addElement(Client);
    }

    /*
     ** Barrier to complete this test session
     */
    e = vClient.elements();

    while (e.hasMoreElements()) {
        Client = (Thread) e.nextElement();

        Client.join();
    }

    vClient.removeAllElements();
    reportDone();

    guardian = connect(url, user, password);

    checkSums(guardian);
    connectClose(guardian);
}
 
Example 11
Project: OpenJSharp   File: IDLGenerator.java   View Source Code Vote up 5 votes
/**
 * Apply user specified -idlModule translation to package names of given
 * IDLEntity ct. Example:
 *   -idlModule foo.bar real::mod::nesting
 * @param ct CompoundType containing given IDLEntity.
 * @param vec Returned Vector of translated IDL module names.
 * @return boolean true if any translation was done.
 */
protected boolean translateJavaPackage(
                                       CompoundType ct,
                                       Vector vec ) {
    vec.removeAllElements();
    boolean ret = false;
    String fc = null;
    if ( ! ct.isIDLEntity() ) return ret;

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

    if ( imHash.size() > 0 ) {           //any -idlModule translation to apply?
        Enumeration k = imHash.keys();

    nextModule:
        while ( k.hasMoreElements() ) {      //loop thro user-defined -idlModules
            String from = (String)k.nextElement();                  //from String..
            StringTokenizer ft = new StringTokenizer( from,"." );
            int vecLen = vec.size();
            int ifr;
            for ( ifr = 0; ifr < vecLen && ft.hasMoreTokens(); ifr++ )
                if ( ! vec.elementAt(ifr).equals( ft.nextToken() ) )
                    continue nextModule;                                  //..no match

            if ( ft.hasMoreTokens() ) {                          //matched so far..
                fc = ft.nextToken();                         //a 'from' token remains
                if ( ! ct.getName().equals( fc ) ||             //matches class name?
                     ft.hasMoreTokens() )
                    continue nextModule;                                   //..no match
            }

            ret = true;                                             //found a match
            for ( int i4 = 0; i4 < ifr; i4++ )
                vec.removeElementAt( 0 );                     //remove 'from' package

            String to = (String)imHash.get( from );                   //..to String
            StringTokenizer tt = new StringTokenizer( to,IDL_NAME_SEPARATOR );

            int itoco = tt.countTokens();
            int ito = 0;
            if ( fc != null ) itoco--;               //user may have given IDL type
            for ( ito = 0; ito < itoco; ito++ )
                vec.insertElementAt( tt.nextToken(),ito );      //insert 'to' modules
            if ( fc != null ) {
                String tc = tt.nextToken();
                if ( ! ct.getName().equals( tc ) )           //not the IDL type, so..
                    vec.insertElementAt( tc,ito );           //insert final 'to' module
            }
        }
    }
    return ret;
}
 
Example 12
Project: OpenJSharp   File: Whitespace.java   View Source Code Vote up 5 votes
/**
 * 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
Project: OpenJSharp   File: XPath.java   View Source Code Vote up 5 votes
/**
 * Used by the {@link #parseExpression(NamespaceContext)} method
 * to build a {@link LocationPath} object from the accumulated
 * {@link Step}s.
 */
private LocationPath buildLocationPath( Vector stepsVector ) throws XPathException {
    int size = stepsVector.size();
    check(size!=0);
    Step[] steps = new Step[size];
    stepsVector.copyInto(steps);
    stepsVector.removeAllElements();

    return new LocationPath(steps);
}
 
Example 14
Project: tap17-muggl-javaee   File: SimpleConstraintSetOptimizer.java   View Source Code Vote up 5 votes
@SuppressWarnings("unused") 
   public SingleConstraintSet transform(SingleConstraintSet constraintSet) {
// check if any Assignments are already contained or if any Assignments
// can be read of trivially and insert the assignments into the
// remaining constraints
Vector<Assignment> assignments = new Vector<Assignment>();
Vector<SingleConstraint> checkedConstraints = new Vector<SingleConstraint>();
Vector<SingleConstraint> uncheckedConstraints = new Vector<SingleConstraint>();
for (int i = 0; i < constraintSet.getConstraintCount(); i++)
    uncheckedConstraints.add(constraintSet.getConstraint(i));
while (!uncheckedConstraints.isEmpty()){
    SingleConstraint constraint = uncheckedConstraints.remove(0);
    if (constraint instanceof Assignment){
	assignments.add((Assignment)constraint);
	uncheckedConstraints.addAll(checkedConstraints);
	checkedConstraints.removeAllElements();
    } else{
	for (int assignmentIdx = 0; assignmentIdx < assignments.size(); assignmentIdx++)
	    constraint = constraint.insert(assignments.get(assignmentIdx));
	Solution solution = null; //constraint.getUniqueSolution();
	if (solution != null){
	    if (solution == Solution.NOSOLUTION)
		return new SingleConstraintSet(BooleanConstant.FALSE);
	    for (Variable variable: solution.variables()){
		Constant value = solution.getValue(variable);
		Assignment assignment = new Assignment(variable, value);
		constraint = constraint.insert(assignment);
		assignments.add(assignment);
	    }
	    uncheckedConstraints.addAll(checkedConstraints);
	    checkedConstraints.removeAllElements();
	}
	combineConditions(checkedConstraints, uncheckedConstraints, assignments, constraint);
    }
}

SingleConstraintSet result = new SingleConstraintSet();
for (int i = 0; i < checkedConstraints.size(); i++)
    result.add(checkedConstraints.get(i));
for (int i = 0; i < assignments.size(); i++)
    result.add(assignments.get(i));
return result;
   }
 
Example 15
Project: Yass   File: YassSheet.java   View Source Code Vote up 5 votes
/**
 * Description of the Method
 */
public void init() {
    firePropertyChange("play", null, "stop");

    int maxwait = 10;
    while (isRefreshing() && maxwait-- > 0) {
        try {
            Thread.currentThread();
            Thread.sleep(100);
        } catch (Exception ignored) {
        }
    }

    int[] minmax = getHeightRange();
    minHeight = minmax[0];
    maxHeight = minmax[1];

    Enumeration<YassTable> et = tables.elements();
    for (Enumeration<Vector<YassRectangle>> e = rects.elements(); e
            .hasMoreElements() && et.hasMoreElements(); ) {
        Vector<YassRectangle> r = e.nextElement();
        YassTable t = et.nextElement();

        // System.out.println("Sheet-Init start singleton");
        // synchronized (YassSingleton.getInstance()) {
        r.removeAllElements();
        int n = t.getRowCount();
        for (int i = 0; i < n; i++) {
            r.addElement(new YassRectangle());
        }
        // }
        // System.out.println("Sheet-Init finish singleton");
    }

    if (isValid()) {
        updateHeight();
        update();
        repaint();
    }
}
 
Example 16
Project: openjdk-jdk10   File: IDLGenerator.java   View Source Code Vote up 5 votes
/**
 * Apply user specified -idlModule translation to package names of given
 * IDLEntity ct. Example:
 *   -idlModule foo.bar real::mod::nesting
 * @param ct CompoundType containing given IDLEntity.
 * @param vec Returned Vector of translated IDL module names.
 * @return boolean true if any translation was done.
 */
protected boolean translateJavaPackage(
                                       CompoundType ct,
                                       Vector vec ) {
    vec.removeAllElements();
    boolean ret = false;
    String fc = null;
    if ( ! ct.isIDLEntity() ) return ret;

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

    if ( imHash.size() > 0 ) {           //any -idlModule translation to apply?
        Enumeration k = imHash.keys();

    nextModule:
        while ( k.hasMoreElements() ) {      //loop thro user-defined -idlModules
            String from = (String)k.nextElement();                  //from String..
            StringTokenizer ft = new StringTokenizer( from,"." );
            int vecLen = vec.size();
            int ifr;
            for ( ifr = 0; ifr < vecLen && ft.hasMoreTokens(); ifr++ )
                if ( ! vec.elementAt(ifr).equals( ft.nextToken() ) )
                    continue nextModule;                                  //..no match

            if ( ft.hasMoreTokens() ) {                          //matched so far..
                fc = ft.nextToken();                         //a 'from' token remains
                if ( ! ct.getName().equals( fc ) ||             //matches class name?
                     ft.hasMoreTokens() )
                    continue nextModule;                                   //..no match
            }

            ret = true;                                             //found a match
            for ( int i4 = 0; i4 < ifr; i4++ )
                vec.removeElementAt( 0 );                     //remove 'from' package

            String to = (String)imHash.get( from );                   //..to String
            StringTokenizer tt = new StringTokenizer( to,IDL_NAME_SEPARATOR );

            int itoco = tt.countTokens();
            int ito = 0;
            if ( fc != null ) itoco--;               //user may have given IDL type
            for ( ito = 0; ito < itoco; ito++ )
                vec.insertElementAt( tt.nextToken(),ito );      //insert 'to' modules
            if ( fc != null ) {
                String tc = tt.nextToken();
                if ( ! ct.getName().equals( tc ) )           //not the IDL type, so..
                    vec.insertElementAt( tc,ito );           //insert final 'to' module
            }
        }
    }
    return ret;
}
 
Example 17
Project: openjdk-jdk10   File: Whitespace.java   View Source Code Vote up 5 votes
/**
 * 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;
}