Java Code Examples for java.util.ArrayList.removeAll()

The following are Jave code examples for showing how to use removeAll() of the java.util.ArrayList 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: fitnotifications   File: AppSelectionDbHelper.java   View Source Code Vote up 7 votes
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    Log.d("DB_UPGRADE", "Updating " + AppChoiceTable.NAME + " table to version " +
                        newVersion + " from version " + oldVersion);
    Cursor cursor = db.query(AppChoiceTable.NAME, null, null, null, null, null, null);
    ArrayList<String> existentColumns = new ArrayList<>(Arrays.asList(cursor.getColumnNames()));
    cursor.close();
    ArrayList<String> missingColumns = AppChoiceTable.Cols.NAME_LIST;
    missingColumns.removeAll(existentColumns);

    try {
        for (String columnName : missingColumns) {
            Log.d("DB_UPGRADE", "Adding column " + columnName + " to table using: " +
                    mDbAlterCommands.get(columnName));
            db.execSQL(mDbAlterCommands.get(columnName));
        }
    } catch (Exception e) {
        Log.e("DB_UPGRADE", "Failed to upgrade DB: " + e.getMessage());
        Toast.makeText(mContext, "App update has an issue! Please send logs to developer!", Toast.LENGTH_LONG).show();
    }
}
 
Example 2
Project: litiengine   File: GeometricUtilities.java   View Source Code Vote up 6 votes
/**
 * Gets the intersection points.
 *
 * @param line
 *          the line
 * @param rectangle
 *          the rectangle
 * @return the intersection points
 */
public static List<Point2D> getIntersectionPoints(final Line2D line, final Rectangle2D rectangle) {
  final ArrayList<Point2D> intersectionPoints = new ArrayList<>();
  final Line2D[] lines = getLines(rectangle);
  final Line2D topLine = lines[0];
  final Line2D bottomLine = lines[1];
  final Line2D leftLine = lines[2];
  final Line2D rightLine = lines[3];

  // Top line
  final Point2D p1 = getIntersectionPoint(line, topLine);
  if (p1 != null && contains(rectangle, p1)) {
    intersectionPoints.add(p1);
  }

  // Bottom line
  final Point2D p2 = getIntersectionPoint(line, bottomLine);
  if (p2 != null && contains(rectangle, p2) && !intersectionPoints.contains(p2)) {
    intersectionPoints.add(p2);
  }

  // Left side...
  final Point2D p3 = getIntersectionPoint(line, leftLine);
  if (p3 != null && !p3.equals(p1) && !p3.equals(p2) && contains(rectangle, p3) && !intersectionPoints.contains(p3)) {
    intersectionPoints.add(p3);
  }

  // Right side
  final Point2D p4 = getIntersectionPoint(line, rightLine);
  if (p4 != null && !p4.equals(p1) && !p4.equals(p2) && contains(rectangle, p4) && !intersectionPoints.contains(p4)) {
    intersectionPoints.add(p4);
  }

  intersectionPoints.removeAll(Collections.singleton(null));
  return intersectionPoints;
}
 
Example 3
Project: ObsidianSuite   File: JsonConverter.java   View Source Code Vote up 6 votes
private void preProcess()
{
    ArrayList<Box> boxes = model.model.getElements();
    HashSet<Box> subBoxes = Sets.newHashSet();
    for (Box box : boxes)
    {
        if (subBoxes.contains(box)) continue;
        Rotation rotation = box.getRotation();
        for (Box box1 : boxes)
        {
            if (box == box1 || subBoxes.contains(box1)) continue;
            Rotation rotation1 = box.getRotation();

            boolean sameRot = rotation == null && rotation1 == null;
            if (!sameRot) sameRot = rotation != null && rotation.equals(rotation1);
            if (sameRot && isSubBox(box, box1))
            {
                subBoxes.add(box1);
            }
        }
    }
    boxes.removeAll(subBoxes);
}
 
Example 4
Project: openjdk-jdk10   File: LinearScanAssignLocationsPhase.java   View Source Code Vote up 6 votes
private void assignLocations(ArrayList<LIRInstruction> instructions) {
    int numInst = instructions.size();
    boolean hasDead = false;

    for (int j = 0; j < numInst; j++) {
        final LIRInstruction op = instructions.get(j);
        if (op == null) {
            /*
             * this can happen when spill-moves are removed in eliminateSpillMoves
             */
            hasDead = true;
        } else if (assignLocations(op)) {
            instructions.set(j, null);
            hasDead = true;
        }
    }

    if (hasDead) {
        // Remove null values from the list.
        instructions.removeAll(Collections.singleton(null));
    }
}
 
Example 5
Project: VASSAL-src   File: PlayerRoster.java   View Source Code Vote up 6 votes
public Component getControls() {
  ArrayList<String> availableSides = new ArrayList<String>(sides);
  ArrayList<String> alreadyTaken = new ArrayList<String>();

  for (PlayerInfo p : players) {
    alreadyTaken.add(p.side);
  }

  availableSides.removeAll(alreadyTaken);
  availableSides.add(0, translatedObserver);
  sideConfig = new StringEnumConfigurer(null,
    Resources.getString("PlayerRoster.join_game_as"), //$NON-NLS-1$
    availableSides.toArray(new String[availableSides.size()]));
  sideConfig.setValue(translatedObserver);
  return sideConfig.getControls();
}
 
Example 6
Project: Java-Data-Science-Made-Easy   File: SimpleStringCleaning.java   View Source Code Vote up 6 votes
public static void removeStopWordsRemoveAll(String text){
	//******************EXAMPLE WITH REMOVE ALL *******************************************************************************************

	try {
		out.println(text);
		Scanner stopWordList = new Scanner(new File("C://Jenn Personal//Packt Data Science//Chapter 3 Data Cleaning//stopwords.txt"));
		TreeSet<String> stopWords = new TreeSet<String>();
		while(stopWordList.hasNextLine()){
			stopWords.add(stopWordList.nextLine());
		}
		ArrayList<String> dirtyText = new ArrayList<String>(Arrays.asList(text.split(" ")));
		dirtyText.removeAll(stopWords);
		out.println("Clean words: ");
		for(String x : dirtyText){
			out.print(x + " ");
		}
		out.println();
		stopWordList.close();
	} catch (FileNotFoundException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
Example 7
Project: Tarski   File: Type.java   View Source Code Vote up 6 votes
/** Merge "a" into the set of entries.
 *
 * <p>  If {a}+this.entries contain a set of entries X1..Xn, such that
 * <br>   (1) For each X:  X[j]==a[j] for i!=j, and X[i].super==a[i].super
 * <br>   (2) X1[i]..Xn[i] exhaust all the direct subsignatures of an abstract parent sig
 * <br> THEN:
 * <br>   we remove X1..Xn, then return the merged result of X1..Xn
 * <br> ELSE
 * <br>   we change nothing, and simply return null
 *
 * <p><b>Precondition:</b> a[i] is not NONE, and a[i].parent is abstract, and a[i].parent!=UNIV
 */
private static List<PrimSig> fold(ArrayList<List<PrimSig>> entries, List<PrimSig> a, int i) {
    PrimSig parent = a.get(i).parent;
    SafeList<PrimSig> children;
    try { children=parent.children(); } catch(Err ex) { return null; } // Exception only occurs if a[i].parent==UNIV
    List<PrimSig> subs = children.makeCopy();
    ArrayList<List<PrimSig>> toDelete = new ArrayList<List<PrimSig>>();
    for(int bi=entries.size()-1; bi>=0; bi--) {
        List<PrimSig> b=entries.get(bi);
        if (b.size() == a.size()) {
            for(int j=0; ;j++) {
                if (j>=b.size()) {toDelete.add(b); subs.remove(b.get(i)); break;}
                PrimSig bt1=a.get(j), bt2=b.get(j);
                if (i==j && bt2.parent!=parent) break;
                if (i!=j && bt2!=bt1) break;
            }
        }
    }
    subs.remove(a.get(i));
    if (subs.size()!=0) return null;
    entries.removeAll(toDelete);
    entries.remove(a);
    a=new ArrayList<PrimSig>(a);
    a.set(i, parent);
    return a;
}
 
Example 8
Project: Java-for-Data-Science   File: SimpleStringCleaning.java   View Source Code Vote up 6 votes
public static void removeStopWordsRemoveAll(String text){
	//******************EXAMPLE WITH REMOVE ALL *******************************************************************************************

	try {
		out.println(text);
		Scanner stopWordList = new Scanner(new File("C://Jenn Personal//Packt Data Science//Chapter 3 Data Cleaning//stopwords.txt"));
		TreeSet<String> stopWords = new TreeSet<String>();
		while(stopWordList.hasNextLine()){
			stopWords.add(stopWordList.nextLine());
		}
		ArrayList<String> dirtyText = new ArrayList<String>(Arrays.asList(text.split(" ")));
		dirtyText.removeAll(stopWords);
		out.println("Clean words: ");
		for(String x : dirtyText){
			out.print(x + " ");
		}
		out.println();
		stopWordList.close();
	} catch (FileNotFoundException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
Example 9
Project: InstaManager   File: Instaman.java   View Source Code Vote up 5 votes
public ArrayList getFansList(){
    if(followersList==null||followingList==null){
        getFollowingList();
        getFollowersList();
    }
    ArrayList fansList = new ArrayList();
    for (InstagramUserSummary user : users) {
        fansList.add(user.getUsername());
    }
    fansList.removeAll(followingList);
    return fansList;
}
 
Example 10
Project: ditb   File: SortedList.java   View Source Code Vote up 5 votes
@Override
public synchronized boolean removeAll(Collection<?> c) {
  ArrayList<E> newList = new ArrayList<E>(list);
  // Removals in ArrayList won't break sorting
  boolean changed = newList.removeAll(c);
  list = Collections.unmodifiableList(newList);
  return changed;
}
 
Example 11
Project: n4js   File: IssuesProvider.java   View Source Code Vote up 5 votes
/**
 * Why does this method resort to returning via exceptional-control-flow upon detecting a cancellation request?
 * Didn't the validation method already handle it?
 * <p>
 * Upon cancellation, some validators (for example, {@code ManifestAwareResourceValidator}) may decide to stop all
 * work and return only the issues found thus far (or even an empty list of issues). That's a valid realization of
 * the cancellation contract. Thus the {@code validate()} method returned normally. If we were to return those
 * partial results, the caller of this method would proceed to pollute the cache with them. That's prevented by
 * throwing a fabricated {@link OperationCanceledError}
 */
@Override
public List<Issue> get() throws OperationCanceledError {
	operationCanceledManager.checkCanceled(ci);
	List<Issue> issues = rv.validate(r, CheckMode.ALL, ci);
	if (!issues.contains(null)) {
		operationCanceledManager.checkCanceled(ci);
		return issues;
	}
	ArrayList<Issue> result = new ArrayList<>(issues);
	result.removeAll(Collections.singleton(null));
	operationCanceledManager.checkCanceled(ci);
	return result;
}
 
Example 12
Project: openjdk-jdk10   File: TraceLinearScanAssignLocationsPhase.java   View Source Code Vote up 5 votes
@SuppressWarnings("try")
private void assignBlock(AbstractBlockBase<?> block) {
    DebugContext debug = allocator.getDebug();
    try (Indent indent2 = debug.logAndIndent("assign locations in block B%d", block.getId())) {
        ArrayList<LIRInstruction> instructions = allocator.getLIR().getLIRforBlock(block);
        handleBlockBegin(block, instructions);
        int numInst = instructions.size();
        boolean hasDead = false;

        for (int j = 0; j < numInst; j++) {
            final LIRInstruction op = instructions.get(j);
            if (op == null) {
                /*
                 * this can happen when spill-moves are removed in eliminateSpillMoves
                 */
                hasDead = true;
            } else if (assignLocations(op, instructions, j)) {
                hasDead = true;
            }
        }
        handleBlockEnd(block, instructions);

        if (hasDead) {
            // Remove null values from the list.
            instructions.removeAll(Collections.singleton(null));
        }
    }
}
 
Example 13
Project: incubator-netbeans   File: ModuleLayeredFileSystem.java   View Source Code Vote up 5 votes
/** Removes few URLs.
 */
public void removeURLs(Collection<URL> urls) throws Exception {
    if (urls.contains(null)) {
        throw new NullPointerException("urls=" + urls);
    }
    ArrayList<URL> arr = new ArrayList<URL>();
    if (this.prevs != null) {
        arr.addAll(this.prevs);
    }
    arr.removeAll(urls);
    setURLs(arr);
}
 
Example 14
Project: Pogamut3   File: BspListDataStrategy.java   View Source Code Vote up 5 votes
/** Remove data
* 
* See {@link IBspStrategy#removeData(Object, Object)}
*/
  public static <TElement> ArrayList<TElement> removeData_static( ArrayList<TElement> data, ArrayList<TElement> dataToRemove ) {
  	if ( data == null ) {
  		return null;
  	}
  	
  	ArrayList<TElement> pruned = Lists.newArrayList( data );
  	
  	if ( dataToRemove != null ) {
  		pruned.removeAll( dataToRemove );
  	}
  	
  	return pruned;
  }
 
Example 15
Project: VASSAL-src   File: PlayerRoster.java   View Source Code Vote up 5 votes
protected String promptForSide() {
    ArrayList<String> availableSides = new ArrayList<String>(sides);
    ArrayList<String> alreadyTaken = new ArrayList<String>();

    for (PlayerInfo p : players) {
      alreadyTaken.add(p.side);
    }

    availableSides.removeAll(alreadyTaken);
    availableSides.add(0, translatedObserver);

    final GameModule g = GameModule.getGameModule();
    String newSide = (String) JOptionPane.showInputDialog(
      g.getFrame(),
      Resources.getString("PlayerRoster.join_game_as"), //$NON-NLS-1$
      Resources.getString("PlayerRoster.choose_side"), //$NON-NLS-1$
      JOptionPane.QUESTION_MESSAGE,
      null,
      availableSides.toArray(new String[availableSides.size()]),
      translatedObserver
    );

    // OBSERVER must always be stored internally in English.
    if (translatedObserver.equals(newSide)) {
      newSide = OBSERVER;
    }
    return newSide;
/*
    if (newSide != null) {
      final PlayerInfo me = new PlayerInfo(GameModule.getUserId(), GlobalOptions.getInstance().getPlayerId(), newSide);
      final Add a = new Add(this, me.playerId, me.playerName, me.side);
      a.execute();
      g.getServer().sendToOthers(a);
    }
*/
  }
 
Example 16
Project: Java-Data-Science-Made-Easy   File: SimpleStringCleaning.java   View Source Code Vote up 5 votes
public static void removeStopWords(String text){
	//discuss stop words file - how to choose stop words? use whole alphabet as way to handle I'M --> I M

	//****************** SIMPLE EXAMPLE *******************************************************************************************

	try {
		//read in list of stop words
		Scanner readStop = new Scanner(new File("C://Jenn Personal//Packt Data Science//Chapter 3 Data Cleaning//stopwords.txt"));
		//create an ArrayList to hold dirty text - call simpleCleanToArray to perform basic cleaning and put in array first
		ArrayList<String> words = new ArrayList<String>(Arrays.asList(simpleCleanToArray(text)));
		//loop through stop words file and check array for each word
		out.println("Original clean text: " + words.toString());
		ArrayList<String> foundWords = new ArrayList();
		while(readStop.hasNextLine()){
			String stopWord = readStop.nextLine().toLowerCase();
			if(words.contains(stopWord)){
				foundWords.add(stopWord);
			}
		}
		words.removeAll(foundWords);
		out.println("Text without stop words: " + words.toString());
	} catch (FileNotFoundException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

}
 
Example 17
Project: Saber-Bot   File: GuildSettingsManager.java   View Source Code Vote up 4 votes
public ArrayList<String> getRestrictedCommands()
{
    ArrayList<String> commands = new ArrayList<>(Main.getCommandHandler().getCommandNames());
    commands.removeAll(unrestrictedCommands);
    return commands;
}
 
Example 18
Project: Apriori-Frequent-Itemset-generation-and-Association-Rule-Mining   File: RuleGeneration.java   View Source Code Vote up 4 votes
void generateRulesFrom(ArrayList<Integer> fk, ArrayList<ArrayList<Integer>> consequents, int countFk) throws IOException{
	if(consequents.size()==0 || consequents.get(0).size()>=fk.size())return;
	
	ArrayList<ArrayList<Integer>> conseqWithMoreConf = new ArrayList<>();
	for(ArrayList<Integer> conseq : consequents){
		ArrayList<Integer> antec = new ArrayList<>(fk);
		antec.removeAll(conseq);
		int antecCount = freqK.get(antec.size()-1).get(antec);
		int ConseqCount = freqK.get(conseq.size()-1).get(conseq);
		float conf = (float)countFk/antecCount;
		if(conf >= minConf){
			conseqWithMoreConf.add(conseq);
			bw.write(ConvertItemset(antec)+"("+antecCount+") ----> "+ConvertItemset(conseq)+"("+ConseqCount+") conf("+conf+")");
			bw.newLine();
		}
	}
	
	//aprioriGen function
	ArrayList<ArrayList<Integer>> newConsequents = new ArrayList<>();
	for(int i = 0; i < conseqWithMoreConf.size(); i++){
		for(int j = i+1; j < conseqWithMoreConf.size(); j++){
			ArrayList<Integer> i1 = conseqWithMoreConf.get(i);
			ArrayList<Integer> i2 = conseqWithMoreConf.get(j);
			
			int width = i1.size();
			int min = Math.min(i1.get(width-1), i2.get(width-1));
			int max = Math.max(i1.get(width-1), i2.get(width-1));
			
			boolean possible = true;
			ArrayList<Integer> newCons = new ArrayList<>();
			for(int x = 0; x < width-1; x++){
				if(i1.get(x)!=i2.get(x)){
					possible = false;
					break;
				}else	newCons.add(i1.get(x));
			}
			if(possible){
				newCons.add(min);
				newCons.add(max);
				newConsequents.add(newCons);
			}
		}
	}
	generateRulesFrom(fk, newConsequents, countFk);
}
 
Example 19
Project: AI_Project   File: SetSearch.java   View Source Code Vote up 4 votes
/**
    * Perform the set-based search. Takes two sets of Assignments, which it may hybridize to
    * create a new Assignments. On this new child, an Or-Tree is then run to generate a solution.
    *
    * @param a One Assignments parent.
    * @param b The other Assignments parent.
    * @return An Or-Tree, representing a solution that may descend from Assignments a and b.
    */
public OTree DoTheSearchAlready(Assignments a, Assignments b)
{
	ArrayList<SlotItem> evolutionList = new ArrayList<>();
	evolutionList.addAll(department.getAllCourses());

       Assignments child;
	if (department.getPartialAssignments() != null) {
           evolutionList.removeAll(department.getPartialAssignments().getAllCourses());
           child = new Assignments(department.getPartialAssignments());
       }
       else {
           child = new Assignments(department.getTimeTable());
       }

	ArrayList<SlotItem> unassigned = new ArrayList<>();



	while (!evolutionList.isEmpty())
	{
		SlotItem randomItem = evolutionList.remove(new Random().nextInt(evolutionList.size()));

		Assignments firstChoice = ChooseParent(a, b);
		Assignments secondChoice = (firstChoice == a) ? b : a;

		TimeSlot slotA = firstChoice.getTimeSlot(randomItem);
		TimeSlot slotB = secondChoice.getTimeSlot(randomItem);

		ArrayList<Evaluated> result = child.getViableTimeSlots(department.getTimeTable(), randomItem);

		boolean assigned = false;

		for (Evaluated evaluated : result)
		{
			if (evaluated.getTimeSlot().equals(slotA))
			{
				child.addAssignment(slotA, randomItem);
				assigned = true;
				break;
			}
			else if (evaluated.getTimeSlot().equals(slotB))
			{
				child.addAssignment(slotB, randomItem);
				assigned = true;
				break;
			}
		}
		if (!assigned)
		{
			unassigned.add(randomItem);
		}
	}

	OTree childTree = new OTree(department, child, unassigned);
	childTree.genSolution();

	return childTree;
}
 
Example 20
Project: java-chess   File: Board.java   View Source Code Vote up 4 votes
public ArrayList<Move> getMoves(boolean color, boolean checkCheck) {
	ArrayList<Move> moves = new ArrayList<>();
	
	for(int i = 0; i < 8; i++)
		for(int j = 0; j < 8; j++) {
			if(tiles[i][j].isOccupied() && 
					tiles[i][j].getPiece().getColor() == color) {
				moves.addAll(tiles[i][j].getPiece().getMoves(this, i, j));
			}
		}
	
	// check if move is valid (must not be check after move) and throw away erroneous moves
	if(checkCheck) {
		// find king (of correct color)
		int x = -1, y = -1;
		for(int i = 0; i < 8; i++)
			for(int j = 0; j < 8; j++) {
				if(tiles[i][j].isOccupied() && 
						tiles[i][j].getPiece().getColor() == color &&
						tiles[i][j].getPiece().toString().equalsIgnoreCase("K")) {
					x = i; y = j;
				}
			}
		
		ArrayList<Move> removeThese = new ArrayList<Move>();
		for(int i = 0; i < moves.size(); i++) {
			// check a move if after making this move the king can be killed (moving into check)
			ArrayList<Move> checkThis = new ArrayList<Move>(moves.subList(i, i+1));
			ArrayList<Move> opponentMoves = getMovesAfter(!color, checkThis, false);
			
			int xUpdated = x, yUpdated = y;
			if(checkThis.get(0).getX1() == x && checkThis.get(0).getY1() == y) { // get updated king position
				xUpdated = checkThis.get(0).getX2();
				yUpdated = checkThis.get(0).getY2();
			}
			
			// check all opponent moves if they kill king (opponent moves in next round)
			for(int j = 0; j < opponentMoves.size(); j++) {
				if(opponentMoves.get(j).getX2() == xUpdated && opponentMoves.get(j).getY2() == yUpdated)
					removeThese.add(checkThis.get(0));
			}
		}
		
		moves.removeAll(removeThese); // remove invalid moves
	}
	
	return moves;
}