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

The following examples show how to use java.util.Vector#removeAllElements() . 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: MoodleRestGroup.java    From MoodleRest with GNU General Public License v2.0 5 votes vote down vote up
public MoodleGroup[] __getGroupsById(String url, String token, Long[] groupids) throws MoodleRestGroupException, UnsupportedEncodingException, MoodleRestException {
    Vector v=new Vector();
    MoodleGroup group;
    StringBuilder data=new StringBuilder();
    String functionCall=MoodleCallRestWebService.isLegacy()?MoodleServices.MOODLE_GROUP_GET_GROUPS.toString():MoodleServices.CORE_GROUP_GET_GROUPS.toString();
    data.append(URLEncoder.encode("wstoken", MoodleServices.ENCODING.toString())).append("=").append(URLEncoder.encode(token, MoodleServices.ENCODING.toString()));
    data.append("&").append(URLEncoder.encode("wsfunction", MoodleServices.ENCODING.toString())).append("=").append(URLEncoder.encode(functionCall, MoodleServices.ENCODING.toString()));
    for (int i=0;i<groupids.length;i++) {
        if (groupids[i]<1) throw new MoodleRestGroupException(); data.append("&").append(URLEncoder.encode("groupids["+i+"]", MoodleServices.ENCODING.toString())).append("=").append(groupids[i]);
    }
    data.trimToSize();
    NodeList elements=(new MoodleCallRestWebService()).__call(url,data.toString());
    group=null;
    for (int j=0;j<elements.getLength();j++) {
        String content=elements.item(j).getTextContent();
        String nodeName=elements.item(j).getParentNode().getAttributes().getNamedItem("name").getNodeValue();
        if (nodeName.equals("id")) {
            if (group==null)
                group=new MoodleGroup(Long.parseLong(content));
            else {
                v.add(group);
                group=new MoodleGroup(Long.parseLong(content));
            }
        }
        if (group==null)
          throw new MoodleRestGroupException();
        group.setMoodleGroupField(nodeName, content);
    }
    if (group!=null)
        v.add(group);
    MoodleGroup[] groups=new MoodleGroup[v.size()];
    for (int i=0;i<v.size();i++) {
        groups[i]=(MoodleGroup)v.get(i);
    }
    v.removeAllElements();
    return groups;
}
 
Example 2
Source File: VectorTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
public void testRemoveAllDuringIteration() {
    Vector<String> vector = new Vector<>();
    vector.add("food");
    Iterator<String> vectorIterator = vector.iterator();
    vectorIterator.next();
    vector.removeAllElements();
    assertFalse(vectorIterator.hasNext());
}
 
Example 3
Source File: IDLGenerator.java    From openjdk-jdk8u-backup 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 4
Source File: MoodleRestGroup.java    From MoodleRest with GNU General Public License v2.0 5 votes vote down vote up
public MoodleGroup[] __getGroupsFromCourseId(String url, String token, Long id) throws MoodleRestGroupException, UnsupportedEncodingException, MoodleRestException {
    Vector v=new Vector();
    MoodleGroup group=null;
    StringBuilder data=new StringBuilder();
    String functionCall=MoodleCallRestWebService.isLegacy()?MoodleServices.MOODLE_GROUP_GET_COURSE_GROUPS.toString():MoodleServices.CORE_GROUP_GET_COURSE_GROUPS.toString();
    data.append(URLEncoder.encode("wstoken", MoodleServices.ENCODING.toString())).append("=").append(URLEncoder.encode(token, MoodleServices.ENCODING.toString()));
    data.append("&").append(URLEncoder.encode("wsfunction", MoodleServices.ENCODING.toString())).append("=").append(URLEncoder.encode(functionCall, MoodleServices.ENCODING.toString()));
    if (id<1) throw new MoodleRestGroupException(); else  data.append("&").append(URLEncoder.encode("courseid", MoodleServices.ENCODING.toString())).append("=").append(id);
    NodeList elements=(new MoodleCallRestWebService()).__call(url,data.toString());
    for (int j=0;j<elements.getLength();j++) {
        String content=elements.item(j).getTextContent();
        String nodeName=elements.item(j).getParentNode().getAttributes().getNamedItem("name").getNodeValue();
        if (nodeName.equals("id")) {
            if (group==null)
                group=new MoodleGroup(Long.parseLong(content));
            else  {
                v.add(group);
                group=new MoodleGroup(Long.parseLong(content));
            }
        }
        if (group==null)
          throw new MoodleRestGroupException();
        group.setMoodleGroupField(nodeName, content);
    }
    if (group!=null)
        v.add(group);
    MoodleGroup[] groups=new MoodleGroup[v.size()];
    for (int i=0;i<v.size();i++) {
        groups[i]=(MoodleGroup)v.get(i);
    }
    v.removeAllElements();
    return groups;
}
 
Example 5
Source File: MoodleRestGroup.java    From MoodleRest with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>Method to return the details of groups within a Moodle course from the course id.</p>
 * 
 * @param id long
 * @return groups MoodleGroup[]
 * @throws MoodleRestGroupException
 * @throws UnsupportedEncodingException
 * @throws MoodleRestException
 */
public static MoodleGroup[] getGroupsFromCourseId(Long id) throws MoodleRestGroupException, UnsupportedEncodingException, MoodleRestException {
    Vector v=new Vector();
    MoodleGroup group=null;
    StringBuilder data=new StringBuilder();
    String functionCall=MoodleCallRestWebService.isLegacy()?MoodleServices.MOODLE_GROUP_GET_COURSE_GROUPS.toString():MoodleServices.CORE_GROUP_GET_COURSE_GROUPS.toString();
    if (MoodleCallRestWebService.getAuth()==null)
        throw new MoodleRestGroupException();
    else
        data.append(MoodleCallRestWebService.getAuth());
    data.append("&").append(URLEncoder.encode("wsfunction", MoodleServices.ENCODING.toString())).append("=").append(URLEncoder.encode(functionCall, MoodleServices.ENCODING.toString()));
    if (id<1) throw new MoodleRestGroupException(); else  data.append("&").append(URLEncoder.encode("courseid", MoodleServices.ENCODING.toString())).append("=").append(id);
    NodeList elements=MoodleCallRestWebService.call(data.toString());
    for (int j=0;j<elements.getLength();j++) {
        String content=elements.item(j).getTextContent();
        String nodeName=elements.item(j).getParentNode().getAttributes().getNamedItem("name").getNodeValue();
        if (nodeName.equals("id")) {
            if (group==null)
                group=new MoodleGroup(Long.parseLong(content));
            else  {
                v.add(group);
                group=new MoodleGroup(Long.parseLong(content));
            }
        }
        if (group==null)
          throw new MoodleRestGroupException();
        group.setMoodleGroupField(nodeName, content);
    }
    if (group!=null)
        v.add(group);
    MoodleGroup[] groups=new MoodleGroup[v.size()];
    for (int i=0;i<v.size();i++) {
        groups[i]=(MoodleGroup)v.get(i);
    }
    v.removeAllElements();
    return groups;
}
 
Example 6
Source File: XPath.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 7
Source File: ASFBay.java    From megamek with GNU General Public License v2.0 5 votes vote down vote up
public Vector<Integer> initializeRecoverySlots() {

        Vector<Integer> slots = new Vector<Integer>();
        	// We have to account for changes in the number of doors, so remove all slots first.
        	slots.removeAllElements();
        	//now add 2 slots back on for each functional door.
        for (int i = 0; i < currentdoors; i++) {
            slots.add(0);
            slots.add(0);
        }
        recoverySlots = slots;
        return slots;
    }
 
Example 8
Source File: IDLGenerator.java    From hottub 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 9
Source File: TimoutNotificator.java    From personaldnsfilter with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void run() {		
	Vector toListeners = new Vector();
	boolean exitThread = false;
	while (!exitThread) {			
		synchronized (this) {				
			toListeners.removeAllElements();
			curTime = System.currentTimeMillis();
			try {
				wait(1000);			
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			curTime = curTime+1000;
			if (!stopped) { 
				
				TimeoutListener[] allListeners = (TimeoutListener[]) listeners.toArray(new TimeoutListener[0]);
				for (int i = 0; i < allListeners.length; i++) {
					long tOut = allListeners[i].getTimoutTime();
					if (curTime > tOut) {
						listeners.remove(allListeners[i]);
						toListeners.add(allListeners[i]);
					}
				}
			}
			exitThread = listeners.isEmpty() || stopped;
			if (exitThread)
				threadAvailable = false;
		}
		TimeoutListener[] allToListeners = (TimeoutListener[]) toListeners.toArray(new TimeoutListener[0]);
		for (int i = 0; i < allToListeners.length; i++) {
			allToListeners[i].timeoutNotification();
		}
	}		
	
}
 
Example 10
Source File: XPath.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 11
Source File: SmallCraftBay.java    From megamek with GNU General Public License v2.0 5 votes vote down vote up
public Vector<Integer> initializeRecoverySlots() {

        Vector<Integer> slots = new Vector<Integer>();
        // We have to account for changes in the number of doors, so remove all slots first.
    	slots.removeAllElements();
    	//now add 2 slots back on for each functional door.
        for (int i = 0; i < currentdoors; i++) {
            slots.add(0);
            slots.add(0);
        }
        recoverySlots = slots;
        return slots;
    }
 
Example 12
Source File: MoodleRestGroup.java    From MoodleRest with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>Method to retrieve details of the memberships of a number of Moodle groups.</p>
 * 
 * @param groupids long[]
 * @return groupUsers MoodleGroupUser[]
 * @throws MoodleRestGroupException
 * @throws UnsupportedEncodingException
 * @throws MoodleRestException
 */
public static MoodleGroupUser[] getMembersFromGroupIds(Long[] groupids) throws MoodleRestGroupException, UnsupportedEncodingException, MoodleRestException {
    Vector v=new Vector();
    MoodleGroupUser user;
    StringBuilder data=new StringBuilder();
    String functionCall=MoodleCallRestWebService.isLegacy()?MoodleServices.MOODLE_GROUP_GET_GROUPMEMBERS.toString():MoodleServices.CORE_GROUP_GET_GROUP_MEMBERS.toString();
    if (MoodleCallRestWebService.getAuth()==null)
        throw new MoodleRestGroupException();
    else
        data.append(MoodleCallRestWebService.getAuth());
    data.append("&").append(URLEncoder.encode("wsfunction", MoodleServices.ENCODING.toString())).append("=").append(URLEncoder.encode(functionCall, MoodleServices.ENCODING.toString()));
    for (int i=0;i<groupids.length;i++) {
        if (groupids[i]<1) throw new MoodleRestGroupException(); data.append("&").append(URLEncoder.encode("groupids["+i+"]", MoodleServices.ENCODING.toString())).append("=").append(groupids[i]);
    }
    data.trimToSize();
    NodeList elements=MoodleCallRestWebService.call(data.toString());
    user=null;
    for (int j=0;j<elements.getLength();j+=2) {
        String content1=elements.item(j).getTextContent();
        String content2=elements.item(j+1).getTextContent();
        user=new MoodleGroupUser(Long.parseLong(content1),Long.parseLong(content2));
        v.add(user);
    }
    if (user!=null)
        v.add(user);
    MoodleGroupUser[] users=new MoodleGroupUser[v.size()];
    for (int i=0;i<v.size();i++) {
        users[i]=(MoodleGroupUser)v.get(i);
    }
    v.removeAllElements();
    return users;
}
 
Example 13
Source File: XPath.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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
Source File: VectorTest.java    From SPDS with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void test6() {
    Vector v = new Vector();
    v.add(new Object());
    mustBeInAcceptingState(v);
    if (staticallyUnknown()) {
        v.removeAllElements();
        v.firstElement();
        mustBeInErrorState(v);
    }
    mayBeInErrorState(v);
}
 
Example 15
Source File: IDLGenerator.java    From TencentKona-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 16
Source File: MoodleRestGroup.java    From MoodleRest with GNU General Public License v2.0 5 votes vote down vote up
public static MoodleGroupGroupings[] getGroupGroupingsFromCourseId(Long[] ids) throws MoodleRestGroupException, UnsupportedEncodingException, MoodleRestException, MoodleGroupGroupingsException {
    if (MoodleCallRestWebService.isLegacy()) throw new MoodleRestGroupException(MoodleRestException.NO_LEGACY);
    Vector v=new Vector();
    MoodleGroupGroupings group=null;
    StringBuilder data=new StringBuilder();
    String functionCall=MoodleServices.CORE_GROUP_GET_GROUPINGS.toString();
    if (MoodleCallRestWebService.getAuth()==null)
        throw new MoodleRestGroupException();
    else
        data.append(MoodleCallRestWebService.getAuth());
    data.append("&").append(URLEncoder.encode("wsfunction", MoodleServices.ENCODING.toString())).append("=").append(URLEncoder.encode(functionCall, MoodleServices.ENCODING.toString()));
    for (int i=0; i<ids.length;i++)
      if (ids[i]<1 || ids[i]==null) throw new MoodleRestGroupException(); else  data.append("&").append(URLEncoder.encode("groupingids["+i+"]", MoodleServices.ENCODING.toString())).append("=").append(ids[i]);
    NodeList elements=MoodleCallRestWebService.call(data.toString());
    for (int j=0;j<elements.getLength();j++) {
        String content=elements.item(j).getTextContent();
        String nodeName=elements.item(j).getParentNode().getAttributes().getNamedItem("name").getNodeValue();
        if (nodeName.equals("id")) {
            if (group==null)
                group=new MoodleGroupGroupings(Long.parseLong(content));
            else  {
                v.add(group);
                group=new MoodleGroupGroupings(Long.parseLong(content));
            }
        }
        if (group==null)
          throw new MoodleRestGroupException();
        group.setMoodleGroupGroupingsField(nodeName, content);
    }
    if (group!=null)
        v.add(group);
    MoodleGroupGroupings[] groups=new MoodleGroupGroupings[v.size()];
    for (int i=0;i<v.size();i++) {
        groups[i]=(MoodleGroupGroupings)v.get(i);
    }
    v.removeAllElements();
    return groups;
}
 
Example 17
Source File: Whitespace.java    From JDKSourceCode1.8 with MIT License 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 18
Source File: IDLGenerator.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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 19
Source File: Cromosoma.java    From KEEL with GNU General Public License v3.0 4 votes vote down vote up
/**
	 * Evaluates a chromosome
	 *
	 * @param datos Reference to the training set
	 * @param nominal  Reference to the training set (nominal valued)	 
	 * @param missing  Reference to the training set (null values)	 	 
	 * @param clases Output attribute of each instance
         * @param database Hyper database
         * @param distans distances between elements
	 * @param alfa Alpha value of the fitness function
	 * @param nClases Number of classes of the problem
         * @param beta Beta value of the fitness function
	 */
  public void evalua (double datos[][], int nominal[][], boolean missing[][], int clases[], Hyper database[], double distans[][],double alfa, int nClases, double beta) {

    int i, j;
    int aciertos = 0;
    double M, T, s;
    int vecinoCercano;
    double dist, minDist;
    double minVolume, volume;
	int dimensions, pos;
	int cover = 0;
	Vector <Integer> cand_rules = new Vector <Integer> ();
    
    M = (double)datos.length;
    T = (double)database.length;
    s = (double)genesActivos();
    
    for (i=0; i<datos.length; i++) {
    	vecinoCercano = -1;
    	minDist = Double.POSITIVE_INFINITY;
		cand_rules.removeAllElements();
		for (j=0; j<database.length; j++) {
			if (cuerpo[j]) { //It is in S
                            if(distans[j][i]>0)
                                dist=distans[j][i];
                            else{
				dist = EHS_CHC.distancia(database[j],datos[i], nominal[i], missing[i]);
                                distans[j][i]=dist;
                            }    
				if (dist > 0) {
					if (dist < minDist) {
						minDist = dist;
						vecinoCercano = j;
					}
				} else {
					dimensions = database[j].dimensions();
					if (dimensions > 0) {
						minDist = 0;
						cand_rules.add(j);
					}
				}
			}
		}
		if (minDist > 0) {
			if (vecinoCercano >= 0) {
				if (clases[i] == database[vecinoCercano].clase)
					aciertos++;
			}			
		} else {
			minVolume = database[cand_rules.elementAt(0)].volume();
			pos = 0;
			for (j=1; j<cand_rules.size(); j++) {
				volume = database[cand_rules.elementAt(j)].volume();
				if (volume < minVolume) {
					pos = j;
					minVolume = volume;
				}
			}
			if (clases[i] == database[cand_rules.elementAt(pos)].clase)
				aciertos++;
			cover++;
		}
    }    	

    calidad = ((double)(aciertos)/M)*alfa*100.0;
    calidad += ((1.0 - alfa) * 100.0 * (T - s) / T);
    calidad = calidad*beta;
    calidad += (1.0 - beta) * 100.0 * ((double)(cover)/M);
    cruzado = false;
}
 
Example 20
Source File: Whitespace.java    From openjdk-jdk9 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;
}