Java Code Examples for java.util.LinkedList#removeAll()

The following examples show how to use java.util.LinkedList#removeAll() . 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: StgSimulationTool.java    From workcraft with MIT License 6 votes vote down vote up
private void initialiseStateMap() {
    final Stg stg = getUnderlyingStg();
    final HashMap<String, SignalData> newStateMap = new HashMap<>();
    final LinkedList<String> allSignals = new LinkedList<>();
    for (final Signal.Type type: Signal.Type.values()) {
        final Set<String> typedSignals = stg.getSignalReferences(type);
        allSignals.addAll(typedSignals);
        for (final String signal: typedSignals) {
            final SignalData signalData = new SignalData(signal, type);
            signalData.copy(signalDataMap.get(signal));
            signalData.visible = type != Signal.Type.INTERNAL;
            newStateMap.put(signal, signalData);
        }
    }
    signalDataMap = newStateMap;
    // Preserve "old" and append "new" items of allSignals to signals list.
    signals.retainAll(allSignals);
    allSignals.removeAll(signals);
    signals.addAll(allSignals);
    updateSignalState();
}
 
Example 2
Source File: SPADEQuery.java    From SPADE with GNU General Public License v3.0 6 votes vote down vote up
public <T> Set<T> getAllResultsOfExactType(Class<T> clazz){
	Set<T> results = new HashSet<T>();

	Set<SPADEQuery> marked = new HashSet<SPADEQuery>();
	
	LinkedList<SPADEQuery> currentSet = new LinkedList<SPADEQuery>();
	currentSet.add(this);
	while(!currentSet.isEmpty()){
		SPADEQuery current = currentSet.poll();
		marked.add(current);
		if(current.getResult() != null){
			if(clazz.equals(current.getResult().getClass())){
				results.add((T)(current.getResult()));
			}
		}
		currentSet.addAll(current.getRemoteSubqueries());
		currentSet.removeAll(marked);
	}

	return results;
}
 
Example 3
Source File: TileManager.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
private void cleanup() {
	// start with all rendered tiles...
	LinkedList<Tile> condemned = new LinkedList<Tile>( alreadyRendered );
	// now remove all those that were just qualified
	condemned.removeAll( scheduledToRender );
	// for whatever's left, destroy and remove from list
	for ( Tile m : condemned ) {
		m.destroy();
		alreadyRendered.remove( m );
	}
	// hide all other groups
	for ( ScalingLayout tileGroup : tileGroups.values() ) {
		if ( currentTileGroup == tileGroup ) {
			continue;
		}
		tileGroup.setVisibility( View.GONE );
	}
}
 
Example 4
Source File: Heap.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void restoreFromBundle( Bundle bundle ) {
	pos = bundle.getInt( POS );
	seen = bundle.getBoolean( SEEN );
	type = Type.valueOf( bundle.getString( TYPE ) );
	items = new LinkedList( bundle.getCollection( ITEMS ) );
	items.removeAll(Collections.singleton(null));
	
	//remove any document pages that either don't exist anymore or that the player already has
	for (Item item : items.toArray(new Item[0])){
		if (item instanceof DocumentPage
				&& ( !((DocumentPage) item).document().pages().contains(((DocumentPage) item).page())
				||    ((DocumentPage) item).document().hasPage(((DocumentPage) item).page()))){
			items.remove(item);
		}
	}
	
	haunted = bundle.getBoolean( HAUNTED );
	
}
 
Example 5
Source File: RecentlyUsedCache.java    From rebuild with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 获取最近使用
 * 
 * @param user
 * @param entity
 * @param type
 * @param limit
 * @return
 */
public ID[] gets(ID user, String entity, String type, int limit) {
	if (!isEnabled()) {
		return ID.EMPTY_ID_ARRAY;
	}
	
	final String key = formatKey(user, entity, type);
	@SuppressWarnings("unchecked")
	LinkedList<ID> exists = (LinkedList<ID>) getx(key);
	if (exists == null) {
		return ID.EMPTY_ID_ARRAY;
	}

	Set<ID> missed = new HashSet<>();
	List<ID> data = new ArrayList<>();
	for (int i = 0; i < limit && i < exists.size(); i++) {
		final ID raw = exists.get(i);
		if (!(raw.getEntityCode() == EntityHelper.ClassificationData || Application.getSecurityManager().allowRead(user, raw))) {
			continue;
		}
		
		try {
			String label = FieldValueWrapper.getLabel(raw);
			ID clone = ID.valueOf(raw.toLiteral());
			clone.setLabel(label);
			data.add(clone);
		} catch (NoRecordFoundException ex) {
			missed.add(raw);
		}
	}
	
	if (!missed.isEmpty()) {
		exists.removeAll(missed);
		putx(key, exists);
	}
	
	return data.toArray(new ID[0]);
}
 
Example 6
Source File: InviteSender.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * @param properties Map<String, String>
 */
protected void checkProperties(Map<String, String> properties)
{
    Set<String> keys = properties.keySet();
    if (!keys.containsAll(getRequiredProperties()))
    {
        LinkedList<String> missingProperties = new LinkedList<String>(getRequiredProperties());
        missingProperties.removeAll(keys);
        throw new InvitationException("The following mandatory properties are missing:\n" + missingProperties);
    }
}
 
Example 7
Source File: UserAgentFileParser.java    From browscap-java with MIT License 5 votes vote down vote up
Rule createRule(final String pattern, final Capabilities capabilities) {

        final List<String> parts = getParts(pattern);
        if (parts.isEmpty()) {
            throw new IllegalStateException();
        }

        final String first = parts.get(0);
        if (parts.size() == 1) {
            if ("*".equals(first)) {
                return getWildCardRule();
            }
            return new Rule(getLiteral(first), null, null, pattern, capabilities);
        }

        final LinkedList<String> suffixes = new LinkedList<>(parts);

        Literal prefix = null;
        if (!"*".equals(first)) {
            prefix = getLiteral(first);
            suffixes.remove(0);
        }

        final String last = parts.get(parts.size() - 1);
        Literal postfix = null;
        if (!"*".equals(last)) {
            postfix = getLiteral(last);
            suffixes.removeLast();
        }
        suffixes.removeAll(singleton("*"));
        final Literal[] suffixArray = new Literal[suffixes.size()];
        for (int i = 0; i < suffixArray.length; i++) {
            suffixArray[i] = getLiteral(suffixes.get(i));
        }

        return new Rule(prefix, suffixArray, postfix, pattern, capabilities);
    }
 
Example 8
Source File: TungstenAggregate.java    From indexr with Apache License 2.0 5 votes vote down vote up
@Override
public Set<Attribute> producedAttributes() {
    LinkedList<NamedExpression> resultExpressionsCopy = new LinkedList<>(resultExpressions);
    resultExpressionsCopy.removeAll(groupingExpressions);
    return concatToSet(aggregateAttributes,
            mapToList(resultExpressionsCopy, NamedExpression::toAttribute),
            aggregateBufferAttributes);
}
 
Example 9
Source File: CompositeNegotiator.java    From irc-api with Apache License 2.0 5 votes vote down vote up
/**
 * Extract capabilities unsupported by the IRC server.
 *
 * @param capLs the CAP LS server response
 * @return Returns the capabilities that are not supported by the IRC
 * server.
 */
private List<Capability> unsupportedCapabilities(final LinkedList<Cap> capLs)
{
	// find all supported capabilities
	final LinkedList<Capability> found = new LinkedList<Capability>();
	for (Capability request : this.capabilities)
	{
		for (Cap available : capLs)
		{
			if (request.getId().equals(available.id))
			{
				if (request.enable() == available.isEnabled() || !available.isMandatory())
				{
					// Only if wishes match server expectations, will we
					// consider it found. So if we wish to disable a feature
					// and it is mandatory, then we consider it unsupported.
					found.add(request);
				}
				// in any case we found the capability, so stop looking for it
				break;
			}
		}
	}
	// compute unsupported capabilities
	final LinkedList<Capability> unsupported = new LinkedList<Capability>(this.capabilities);
	unsupported.removeAll(found);
	if (LOG.isTraceEnabled())
	{
		LOG.trace("Supported capabilities: {}", repr(found));
	}
	if (LOG.isDebugEnabled())
	{
		LOG.debug("Unsupported capabilities: {}", repr(unsupported));
	}
	return unsupported;
}
 
Example 10
Source File: CompositeNegotiator.java    From irc-api with Apache License 2.0 5 votes vote down vote up
/**
 * Extract capabilities to request.
 *
 * @param unsupported list of unsupported capabilities that should not be
 * requested
 * @return Returns list of capabilities that must be requested.
 */
private List<Capability> requestedCapabilities(final List<Capability> unsupported)
{
	final LinkedList<Capability> requests = new LinkedList<Capability>(this.capabilities);
	requests.removeAll(unsupported);
	if (LOG.isDebugEnabled())
	{
		LOG.debug("Requesting capabilities: {}", repr(requests));
	}
	return requests;
}
 
Example 11
Source File: CompositeNegotiator.java    From irc-api with Apache License 2.0 5 votes vote down vote up
/**
 * Get the currently conversing capability, either one that continues a
 * conversation or one that just now starts a conversation.
 *
 * @return Returns the instance of the conversing capability or
 * <tt>null</tt> if no capability is left to start/continue a conversation.
 */
private Capability conversingCapability()
{
	LinkedList<Capability> caps = new LinkedList<Capability>(this.acknowledged);
	caps.removeAll(this.conversed);
	if (caps.isEmpty()) {
		return null;
	}
	return caps.getFirst();
}
 
Example 12
Source File: StatementGroupOptimizer.java    From CostFed with GNU Affero General Public License v3.0 4 votes vote down vote up
protected void meetNJoin(NJoin node) {
	
	LinkedList<TupleExpr> newArgs = new LinkedList<TupleExpr>();
	
	LinkedList<TupleExpr> argsCopy = new LinkedList<TupleExpr>(node.getArgs());
	while (!argsCopy.isEmpty()) {
		
		TupleExpr t = argsCopy.removeFirst();
		
		/*
		 * If one of the join arguments cannot produce results,
		 * the whole join expression does not produce results.
		 * => replace with empty join and return
		 */
		if (t instanceof EmptyResult) {				
			node.replaceWith(new EmptyNJoin(node, queryInfo));
			return;
		}
		
		/*
		 * for exclusive statements find those belonging to the 
		 * same source (if any) and form exclusive group
		 */
		else if (t instanceof ExclusiveStatement) {
			ExclusiveStatement current = (ExclusiveStatement)t;
			
			List<ExclusiveStatement> l = null;
			for (TupleExpr te : argsCopy) {
				/* in the remaining join args find exclusive statements
				 * having the same source, and add to a list which is
				 * later used to form an exclusive group
				 */
				if (te instanceof ExclusiveStatement) {
					ExclusiveStatement check = (ExclusiveStatement)te;
					if (check.getOwner().equals(current.getOwner())) {
						if (l == null) {
							l = new ArrayList<ExclusiveStatement>();
							l.add(current);
						}
						l.add(check);
					}							
				}						
			}
			
			
			// check if we can construct a group, otherwise add directly
			if (l != null) {
				argsCopy.add(current); // will be removed in one row if pass checking
				checkExclusiveGroup(l);
				argsCopy.removeAll(l);
				newArgs.add(new ExclusiveGroup(l, current.getOwner(), queryInfo));
			} else {
				newArgs.add(current);
			}
		}
		
		/*
		 * statement yields true in any case, not needed for join
		 */
		else if (t instanceof TrueStatementPattern) {
			if (log.isDebugEnabled())
				log.debug("Statement " + QueryStringUtil.toString((StatementPattern)t) + " yields results for at least one provided source, prune it.");
		}
		
		else
			newArgs.add(t);
	}
	
	// if the join args could be reduced to just one, e.g. OwnedGroup
	// we can safely replace the join node
	if (newArgs.size() == 1) {
		log.debug("Join arguments could be reduced to a single argument, replacing join node.");
		node.replaceWith( newArgs.get(0) );
		return;
	}
	
	// in rare cases the join args can be reduced to 0, e.g. if all statements are 
	// TrueStatementPatterns. We can safely replace the join node in such case
	if (newArgs.isEmpty()) {
		log.debug("Join could be pruned as all join statements evaluate to true, replacing join with true node.");
		node.replaceWith( new TrueStatementPattern( new StatementPattern()));
		return;
	}
	
	List<TupleExpr> optimized = newArgs;
	
	// optimize the join order
	optimizeJoinOrder(node, optimized);
}
 
Example 13
Source File: SpellTreeViewModel.java    From pcgen with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public List<TreeViewPath<SuperNode>> getPaths(SuperNode node)
{
	TreeViewPath<SuperNode> path;
	if (node instanceof SpellNode)
	{
		SpellNode pobj = (SpellNode) node;
		LinkedList<Object> pathList = new LinkedList<>();
		switch (this)
		{
			case CLASS_LEVEL_SPELL:
				Collections.addAll(pathList, pobj.getRootNode(), pobj.getSpellcastingClass(),
					pobj.getSpellLevel());
				pathList.removeAll(Collections.singleton(null));
				if (pobj.getSpell() == null)
				{
					pathList.removeLast();
				}
				path = new TreeViewPath<>(pobj, pathList.toArray());
				break;
			case CLASS_LEVEL_SCHOOL_SPELL:
				Collections.addAll(pathList, pobj.getRootNode(), pobj.getSpellcastingClass(),
					pobj.getSpellLevel());
				if (pobj.getSpell() != null)
				{
					pathList.add(pobj.getSpell().getSchool());
				}
				pathList.removeAll(Collections.singleton(null));
				if (pobj.getSpell() == null)
				{
					pathList.removeLast();
				}
				path = new TreeViewPath<>(pobj, pathList.toArray());
				break;
			default:
				throw new InternalError();
		}

	}
	else
	{
		path = new TreeViewPath<>(node);
	}
	return Collections.singletonList(path);
}
 
Example 14
Source File: TakeEvent.java    From BetonQuest with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected Void execute(String playerID) throws QuestRuntimeException {
    Player player = PlayerConverter.getPlayer(playerID);
    for (Item item : questItems) {
        QuestItem questItem = item.getItem();
        VariableNumber amount = item.getAmount();

        // cache the amount
        counter = amount.getInt(playerID);

        // notify the player
        if (notify) {
            Config.sendNotify(playerID, "items_taken",
                    new String[]{
                            (questItem.getName() != null) ? questItem.getName()
                                    : questItem.getMaterial().toString().toLowerCase().replace("_", " "),
                            String.valueOf(counter)},
                    "items_taken,info");
        }

        // Remove Quest items from player's inventory
        player.getInventory().setContents(removeItems(player.getInventory().getContents(), questItem));

        // Remove Quest items from player's armor slots
        if (counter > 0) {
            player.getInventory()
                    .setArmorContents(removeItems(player.getInventory().getArmorContents(), questItem));
        }

        // Remove Quest items from player's backpack
        if (counter > 0) {
            List<ItemStack> backpack = BetonQuest.getInstance().getPlayerData(playerID).getBackpack();
            ItemStack[] array = new ItemStack[]{};
            array = backpack.toArray(array);
            LinkedList<ItemStack> list = new LinkedList<>(Arrays.asList(removeItems(array, questItem)));
            list.removeAll(Collections.singleton(null));
            BetonQuest.getInstance().getPlayerData(playerID).setBackpack(list);
        }
    }
    return null;
}
 
Example 15
Source File: SpellTreeViewModel.java    From pcgen with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public List<TreeViewPath<SuperNode>> getPaths(SuperNode node)
{
	TreeViewPath<SuperNode> path;
	if (node instanceof SpellNode)
	{
		SpellNode pobj = (SpellNode) node;
		LinkedList<Object> pathList = new LinkedList<>();
		switch (this)
		{
			case CLASS_LEVEL_SPELL:
				Collections.addAll(pathList, pobj.getRootNode(), pobj.getSpellcastingClass(),
					pobj.getSpellLevel());
				pathList.removeAll(Collections.singleton(null));
				if (pobj.getSpell() == null)
				{
					pathList.removeLast();
				}
				path = new TreeViewPath<>(pobj, pathList.toArray());
				break;
			case CLASS_LEVEL_SCHOOL_SPELL:
				Collections.addAll(pathList, pobj.getRootNode(), pobj.getSpellcastingClass(),
					pobj.getSpellLevel());
				if (pobj.getSpell() != null)
				{
					pathList.add(pobj.getSpell().getSchool());
				}
				pathList.removeAll(Collections.singleton(null));
				if (pobj.getSpell() == null)
				{
					pathList.removeLast();
				}
				path = new TreeViewPath<>(pobj, pathList.toArray());
				break;
			default:
				throw new InternalError();
		}

	}
	else
	{
		path = new TreeViewPath<>(node);
	}
	return Collections.singletonList(path);
}