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

The following are Jave code examples for showing how to use removeElementAt() 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: myster   File: MysterMenuBar.java   View Source Code Vote up 7 votes
private static boolean removeMenuItem(Vector vector, String menuItem) { //ugh...
    getFactory(); //assert menu bar stuff is loaded.

    for (int i = 0; i < vector.size(); i++) {
        MysterMenuItemFactory item = (MysterMenuItemFactory) (vector.elementAt(i));
        if (item.getName().equalsIgnoreCase(menuItem)) {
            vector.removeElementAt(i);
            while ((vector.size() > 0)
                    && (((MysterMenuItemFactory) (vector.elementAt(vector.size() - 1)))
                            .getName().equals("-"))) {
                vector.removeElementAt(vector.size() - 1);
            }

            updateMenuBars();

            return true;
        }
    }

    return false;
}
 
Example 2
Project: jmt   File: Util2d.java   View Source Code Vote up 7 votes
/**
 * La funzione elimina i punti dominati dal vettore passato
 * @param vertices      è un vettore di NewPoint
 * @return              un vettore di NewPoint contenente i vertici non dominati
 */
public Vector<newPoint> DomRemove2D(Vector<newPoint> vertices) {
	//Vector out = vertices;

	for (int i = 0; i < vertices.size(); i++) {
		boolean t = false;
		double x1 = vertices.get(i).getX();
		double y1 = vertices.get(i).getY();
		for (int j = 0; j < vertices.size(); j++) {

			double x2 = vertices.get(j).getX();
			double y2 = vertices.get(j).getY();
			if (x1 < x2 && y1 < y2) {
				t = true;
				break;
			}
		}
		if (t == true) {
			vertices.removeElementAt(i);
			// necessario x non saltare il punto successivo dato il ridimens. del vettore
			i--;
		}
	}
	return vertices;
}
 
Example 3
Project: jmt   File: Util2d.java   View Source Code Vote up 7 votes
public Vector<newPoint> RemoveCollinear(Vector<newPoint> vertices) {
	Vector<newPoint> out = new Vector<newPoint>(vertices);
	int ilast = vertices.size() - 1;
	newPoint first = out.get(0);
	// Attenzione qui sotto out.get(0) -> out.get(1) ??
	newPoint second = out.get(1);
	newPoint last = out.lastElement();
	newPoint prelast = out.get(ilast - 1);

	if (last.x == prelast.x && last.y == 0) {
		out.remove(out.lastElement());
	}

	if (first.y == second.y && first.x == 0) {
		out.removeElementAt(0);
	}

	return out;
}
 
Example 4
Project: QN-ACTR-Release   File: Beta3D.java   View Source Code Vote up 7 votes
/**
 * Cancella il settore dove saturano 2 stazioni che unirebbe due settori complanari in cui saturano
 * 3 stazioni
 *
 * @param s3d
 * @return
 */
public Vector<Object> DeleteFake(Vector<Object> s3d) {
	for (int i = 0; i < s3d.size(); i++) {

		if (Math.abs(((Sector3D) s3d.get(i)).getBeta(0, 0) - ((Sector3D) s3d.get(i)).getBeta(1, 0)) < EPSYLON
				&& Math.abs(((Sector3D) s3d.get(i)).getBeta(0, 1) - ((Sector3D) s3d.get(i)).getBeta(1, 1)) < EPSYLON
				&& Math.abs(((Sector3D) s3d.get(i)).getBeta(0, 2) - ((Sector3D) s3d.get(i)).getBeta(1, 2)) < EPSYLON
				&& Math.abs(((Sector3D) s3d.get(i)).getBeta(2, 0) - ((Sector3D) s3d.get(i)).getBeta(3, 0)) < EPSYLON
				&& Math.abs(((Sector3D) s3d.get(i)).getBeta(2, 1) - ((Sector3D) s3d.get(i)).getBeta(3, 1)) < EPSYLON
				&& Math.abs(((Sector3D) s3d.get(i)).getBeta(2, 2) - ((Sector3D) s3d.get(i)).getBeta(3, 2)) < EPSYLON) {
			s3d.removeElementAt(i);
			i--;
		}
	}
	return s3d;
}
 
Example 5
Project: QN-ACTR-Release   File: Util2d.java   View Source Code Vote up 7 votes
/**
 * La funzione elimina i punti dominati dal vettore passato
 * @param vertices      � un vettore di NewPoint
 * @return              un vettore di NewPoint contenente i vertici non dominati
 */
public Vector<newPoint> DomRemove2D(Vector<newPoint> vertices) {
	//Vector out = vertices;

	for (int i = 0; i < vertices.size(); i++) {
		boolean t = false;
		double x1 = vertices.get(i).getX();
		double y1 = vertices.get(i).getY();
		for (int j = 0; j < vertices.size(); j++) {

			double x2 = vertices.get(j).getX();
			double y2 = vertices.get(j).getY();
			if (x1 < x2 && y1 < y2) {
				t = true;
				break;
			}
		}
		if (t == true) {
			vertices.removeElementAt(i);
			// necessario x non saltare il punto successivo dato il ridimens. del vettore
			i--;
		}
	}
	return vertices;
}
 
Example 6
Project: HtmlNative   File: BasicBlock.java   View Source Code Vote up 7 votes
public static BasicBlock[] findLiveBlocks(BasicBlock[] blocks) {
	// add reachable blocks
	Vector next = new Vector ();
	next.addElement( blocks[0] );
	while ( ! next.isEmpty() ) {
		BasicBlock b = (BasicBlock) next.elementAt(0);
		next.removeElementAt(0);
		if ( ! b.islive ) {
			b.islive = true;
			for ( int i=0, n=b.next!=null? b.next.length: 0; i<n; i++ )
				if ( ! b.next[i].islive )
					next.addElement( b.next[i] );
		}
	}
	
	// create list in natural order
	Vector list = new Vector();
	for ( int i=0; i<blocks.length; i=blocks[i].pc1+1 )
		if ( blocks[i].islive )
			list.addElement(blocks[i]);
	
	// convert to array
	BasicBlock[] array = new BasicBlock[list.size()];
	list.copyInto(array);
	return array;
}
 
Example 7
Project: rapidminer   File: MatrixPropertyTable.java   View Source Code Vote up 6 votes
public void removeColumn(int index) {
	TableColumn column = getColumnModel().getColumn(index);
	int modelIndex = column.getModelIndex();
	Vector modelData = model.getDataVector();
	Vector columnIdentifiers = model.getColumnIdentifiers();

	// remove the column from the table
	removeColumn(column);

	// remove the column header from the table model
	columnIdentifiers.removeElementAt(modelIndex);

	// remove the column data
	for (int i = 0; i < modelData.size(); i++) {
		Vector row = (Vector) modelData.get(i);
		row.removeElementAt(modelIndex);
	}
	model.setDataVector(modelData, columnIdentifiers);

	// correct the model indices in the TableColumn objects
	Enumeration columns = getColumnModel().getColumns();
	while (columns.hasMoreElements()) {
		TableColumn currentColumn = (TableColumn) columns.nextElement();
		if (currentColumn.getModelIndex() >= modelIndex) {
			currentColumn.setModelIndex(currentColumn.getModelIndex() - 1);
		}
	}
}
 
Example 8
Project: jdk8u-jdk   File: StringContent.java   View Source Code Vote up 6 votes
/**
 * Resets the location for all the UndoPosRef instances
 * in <code>positions</code>.
 * <p>
 * This is meant for internal usage, and is generally not of interest
 * to subclasses.
 *
 * @param positions the positions of the instances
 */
protected void updateUndoPositions(Vector positions) {
    for(int counter = positions.size() - 1; counter >= 0; counter--) {
        UndoPosRef ref = (UndoPosRef)positions.elementAt(counter);
        // Check if the Position is still valid.
        if(ref.rec.unused) {
            positions.removeElementAt(counter);
        }
        else
            ref.resetLocation();
    }
}
 
Example 9
Project: QN-ACTR-Release   File: Polygon.java   View Source Code Vote up 6 votes
/**
 * Reverse the order of the vertices that define a contour
 */
public void reverse() {
	/* Add vertices in reverse order */
	Vector<Vertex> vertices = getVertices();
	int size = vertices.size();
	for (int i = 1; i < size; i++) {
		vertices.insertElementAt(vertices.elementAt(i), 0);
		vertices.removeElementAt(i + 1);
	}
}
 
Example 10
Project: OpenJSharp   File: StringContent.java   View Source Code Vote up 6 votes
/**
 * Resets the location for all the UndoPosRef instances
 * in <code>positions</code>.
 * <p>
 * This is meant for internal usage, and is generally not of interest
 * to subclasses.
 *
 * @param positions the positions of the instances
 */
protected void updateUndoPositions(Vector positions) {
    for(int counter = positions.size() - 1; counter >= 0; counter--) {
        UndoPosRef ref = (UndoPosRef)positions.elementAt(counter);
        // Check if the Position is still valid.
        if(ref.rec.unused) {
            positions.removeElementAt(counter);
        }
        else
            ref.resetLocation();
    }
}
 
Example 11
Project: unitimes   File: BackTracker.java   View Source Code Vote up 6 votes
public static void markForBack(HttpServletRequest request, String uri, String title, boolean back, boolean clear) {
	synchronized (request.getSession()) {
		Vector backList = getBackList(request.getSession());
		if (clear) backList.clear();
		if (back) {
			if (uri==null && request.getAttribute("javax.servlet.forward.request_uri")==null) return;
			Object titleObj = (title==null?request.getAttribute("title"):title);
			String requestURI = (String)request.getAttribute("javax.servlet.forward.request_uri");
			String queryString = (String)request.getAttribute("javax.servlet.forward.query_string");
			if (queryString!=null && queryString.length()>0)
				requestURI += "?"+queryString;
			if (uri!=null)
				requestURI = uri;
			if (!backList.isEmpty()) {
				int found = -1;
				for (int idx = 0; idx<backList.size(); idx++) {
					String[] lastBack = (String[])backList.elementAt(idx);
					if (lastBack[0].equals(requestURI)) {
						found = idx; break;
					}
				}
				while (found>=0 && backList.size()>found)
					backList.removeElementAt(backList.size()-1);
			}
			backList.addElement(new String[]{requestURI,(titleObj==null?null:titleObj.toString())});
			//System.out.println("ADD BACK:"+requestURI+" ("+titleObj+")");
		}
	}
}
 
Example 12
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 13
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 14
Project: jmt   File: Beta3D.java   View Source Code Vote up 5 votes
/**
 * Il metodo è usato per unire i settori complanari, quelli cioè dove saturano più di 3 stazioni contemp.
 *
 * @param triangles è un vettore contenente i settori a triangolo dove saturano 3 stazioni contemporaneamente
 * @return un vettore con i settori uniti
 */
public Vector<Object> JoinComplanars(Vector<Object> triangles) {
	Vector<Object> out = new Vector<Object>();
	for (int i = 0; i < triangles.size(); i++) {
		for (int j = i + 1; j < triangles.size(); j++) {
			Vector<BetaVertex> bi = new Vector<BetaVertex>();
			int c = 0;
			for (int h = 0; h < ((Sector3D) triangles.get(i)).CountPoint(); h++) {
				bi.addElement(((Sector3D) triangles.get(i)).getV(h));
			}

			{
				int[] d = { -1, -1 };
				int k = 0;

				Vector<BetaVertex> bj = new Vector<BetaVertex>();
				for (int h = 0; h < ((Sector3D) triangles.get(j)).CountPoint(); h++) {
					bj.addElement(((Sector3D) triangles.get(j)).getV(h));
				}

				for (int a = 0; a < bi.size(); a++) {
					for (int b = 0; b < bj.size(); b++) {
						if (bj.get(b).CircaEquals(bi.get(a))) {
							c++;
							d[k] = a;
							k++;
						}
					}
				}

				//ATTIVARE SOLO PER CONTROLLI
				//System.out.println(c);
				//System.out.println(k);

				if (c > 1) {
					// toglie un triangolo e crea un settore con 4 stazioni
					((Sector3D) triangles.get(i)).setType(((Sector3D) triangles.get(i)).getType() + 1);
					int z = 0;
					if (d[0] != 0 && d[1] != 0) {
						z = 0;
					} else if (d[0] != 1 && d[1] != 1) {
						z = 1;
					} else if (d[0] != 2 && d[1] != 2) {
						z = 2;
					}
					BetaVertex betas = new BetaVertex(((Sector3D) triangles.get(j)).getBetas(z));
					((Sector3D) triangles.get(i)).AddVertex(betas, ((Sector3D) triangles.get(j)).getS(z));
					triangles.removeElementAt(j);
					j--;
				}
			}
		}
	}

	//todo creare un controllo ciclico che crei settori con N stazioni
	out = triangles;
	return out;
}
 
Example 15
Project: Yass   File: YassMIDIConverter.java   View Source Code Vote up 5 votes
/**
 * Description of the Method
 *
 * @param txt1 Description of the Parameter
 * @param txt2 Description of the Parameter
 * @return Description of the Return Value
 */
public String mergeTables(String txt1, String txt2) {
    YassProperties prop = new YassProperties();
    YassRow.setValidTags(prop.getProperty("valid-tags"));
    YassRow.setValidLines(prop.getProperty("valid-lines"));

    YassTable t1 = new YassTable();
    t1.setText(txt1.toString());
    YassTable t2 = new YassTable();
    t2.setText(txt2.toString());

    double gap1 = t1.getGap();
    double gap2 = t2.getGap();

    if (gap2 < gap1) {
        double g = gap1;
        gap1 = gap2;
        gap2 = g;

        YassTable d = t1;
        t1 = t2;
        t2 = d;
    }

    int dbeat = (int) Math.round((gap2 - gap1) * 4 * bpm / (60.0 * 1000.0));

    int n1 = t1.getRowCount();
    YassTableModel tm = (YassTableModel) t1.getModel();
    Vector<YassRow> data = tm.getData();
    data.removeElementAt(n1 - 1);

    int n2 = t2.getRowCount();
    for (int i = 0; i < n2; i++) {
        YassRow r = t2.getRowAt(i);
        if (r.isComment()) {
            continue;
        }
        if (r.isNoteOrPageBreak()) {
            int beat = r.getBeatInt();
            r.setBeat(beat + dbeat);
        }
        data.addElement(r);
    }

    java.util.Collections.sort(data);
    String txt = t1.getPlainText();
    System.out.println(txt);
    return txt;
}
 
Example 16
Project: openjdk-jdk10   File: RMIGenerator.java   View Source Code Vote up 5 votes
/**
 * Compute the exceptions which need to be caught and rethrown in a
 * stub method before wrapping Exceptions in UnexpectedExceptions,
 * given the exceptions declared in the throws clause of the method.
 * Returns a Vector containing ClassDefinition objects for each
 * exception to catch.  Each exception is guaranteed to be unique,
 * i.e. not a subclass of any of the other exceptions in the Vector,
 * so the catch blocks for these exceptions may be generated in any
 * order relative to each other.
 *
 * RemoteException and RuntimeException are each automatically placed
 * in the returned Vector (if none of their superclasses are already
 * present), since those exceptions should always be directly rethrown
 * by a stub method.
 *
 * The returned Vector will be empty if java.lang.Exception or one
 * of its superclasses is in the throws clause of the method, indicating
 * that no exceptions need to be caught.
 */
private Vector<ClassDefinition> computeUniqueCatchList(ClassDeclaration[] exceptions) {
    Vector<ClassDefinition> uniqueList = new Vector<>();       // unique exceptions to catch

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

    /* For each exception declared by the stub method's throws clause: */
nextException:
    for (int i = 0; i < exceptions.length; i++) {
        ClassDeclaration decl = exceptions[i];
        try {
            if (defException.subClassOf(env, decl)) {
                /*
                 * (If java.lang.Exception (or a superclass) was declared
                 * in the throws clause of this stub method, then we don't
                 * have to bother catching anything; clear the list and
                 * return.)
                 */
                uniqueList.clear();
                break;
            } else if (!defException.superClassOf(env, decl)) {
                /*
                 * Ignore other Throwables that do not extend Exception,
                 * since they do not need to be caught anyway.
                 */
                continue;
            }
            /*
             * Compare this exception against the current list of
             * exceptions that need to be caught:
             */
            for (int j = 0; j < uniqueList.size();) {
                ClassDefinition def = uniqueList.elementAt(j);
                if (def.superClassOf(env, decl)) {
                    /*
                     * If a superclass of this exception is already on
                     * the list to catch, then ignore and continue;
                     */
                    continue nextException;
                } else if (def.subClassOf(env, decl)) {
                    /*
                     * If a subclass of this exception is on the list
                     * to catch, then remove it.
                     */
                    uniqueList.removeElementAt(j);
                } else {
                    j++;    // else continue comparing
                }
            }
            /* This exception is unique: add it to the list to catch. */
            uniqueList.addElement(decl.getClassDefinition(env));
        } catch (ClassNotFound e) {
            env.error(0, "class.not.found", e.name, decl.getName());
            /*
             * REMIND: We do not exit from this exceptional condition,
             * generating questionable code and likely letting the
             * compiler report a resulting error later.
             */
        }
    }
    return uniqueList;
}
 
Example 17
Project: QN-ACTR-Release   File: Beta3D.java   View Source Code Vote up 5 votes
/**
 * Il metodo � usato per unire i settori complanari, quelli cio� dove saturano pi� di 3 stazioni contemp.
 *
 * @param triangles � un vettore contenente i settori a triangolo dove saturano 3 stazioni contemporaneamente
 * @return un vettore con i settori uniti
 */
public Vector<Object> JoinComplanars(Vector<Object> triangles) {
	Vector<Object> out = new Vector<Object>();
	for (int i = 0; i < triangles.size(); i++) {
		for (int j = i + 1; j < triangles.size(); j++) {
			Vector<BetaVertex> bi = new Vector<BetaVertex>();
			int c = 0;
			for (int h = 0; h < ((Sector3D) triangles.get(i)).CountPoint(); h++) {
				bi.addElement(((Sector3D) triangles.get(i)).getV(h));
			}

			{
				int[] d = { -1, -1 };
				int k = 0;

				Vector<BetaVertex> bj = new Vector<BetaVertex>();
				for (int h = 0; h < ((Sector3D) triangles.get(j)).CountPoint(); h++) {
					bj.addElement(((Sector3D) triangles.get(j)).getV(h));
				}

				for (int a = 0; a < bi.size(); a++) {
					for (int b = 0; b < bj.size(); b++) {
						if (bj.get(b).CircaEquals(bi.get(a))) {
							c++;
							d[k] = a;
							k++;
						}
					}
				}

				/* ATTIVARE SOLO PER CONTROLLI
				System.out.println(c);
				System.out.println(k);
				*/
				if (c > 1) {
					// toglie un triangolo e crea un settore con 4 stazioni
					((Sector3D) triangles.get(i)).setType(((Sector3D) triangles.get(i)).getType() + 1);
					int z = 0;
					if (d[0] != 0 && d[1] != 0) {
						z = 0;
					} else if (d[0] != 1 && d[1] != 1) {
						z = 1;
					} else if (d[0] != 2 && d[1] != 2) {
						z = 2;
					}
					BetaVertex betas = new BetaVertex(((Sector3D) triangles.get(j)).getBetas(z));
					((Sector3D) triangles.get(i)).AddVertex(betas, ((Sector3D) triangles.get(j)).getS(z));
					triangles.removeElementAt(j);
					j--;

				}
			}
		}
	}

	//todo creare un controllo ciclico che crei settori con N stazioni
	out = triangles;
	return out;
}
 
Example 18
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;
}
 
Example 19
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 20
Project: OpenJSharp   File: RMIGenerator.java   View Source Code Vote up 5 votes
/**
 * 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;
}