Java Code Examples for java.util.ArrayList#removeIf()

The following examples show how to use java.util.ArrayList#removeIf() . 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: Monitor.java    From bender with Apache License 2.0 6 votes vote down vote up
public void writeStats() {

    for (Reporter reporter : statsReporters) {
      List<StatFilter> filters = reporter.getStatFilters();
      ArrayList<Stat> stats = getStats();

      for (StatFilter filter : filters) {
        Predicate<Stat> statPredicate = StatFilter.isMatch(filter);
        stats.removeIf(statPredicate);
      }

      /*
       * Catch anything a reporter may throw to prevent function failures.
       */
      try {
        reporter.write(stats, invokeTime, tags);
      } catch (Exception e) {
        logger.warn("reporter threw an error while writing stats", e);
      }
    }

    clearStats();
  }
 
Example 2
Source File: PlanAnalyzer.java    From systemds with Apache License 2.0 6 votes vote down vote up
private static ArrayList<Long> getMaterializationPoints(HashSet<Long> roots, 
		HashSet<Long> partition, CPlanMemoTable memo) 
{
	//collect materialization points bottom-up
	ArrayList<Long> ret = new ArrayList<>();
	HashSet<Long> visited = new HashSet<>();
	for( Long hopID : roots )
		rCollectMaterializationPoints(memo.getHopRefs().get(hopID), 
				visited, partition, roots, ret);
	
	//remove special-case materialization points
	//(root nodes w/ multiple consumers, tsmm input if consumed in partition)
	ret.removeIf(hopID -> roots.contains(hopID)
		|| HopRewriteUtils.isTsmmInput(memo.getHopRefs().get(hopID)));
	
	if( LOG.isTraceEnabled() ) {
		LOG.trace("Partition materialization points: "
			+ Arrays.toString(ret.toArray(new Long[0])));
	}
	
	return ret;
}
 
Example 3
Source File: KhaosDatabase.java    From gsc-core with GNU Lesser General Public License v3.0 6 votes vote down vote up
public boolean remove(Sha256Hash hash) {
    KhaosBlock block = this.hashKblkMap.get(hash);
    // Sha256Hash parentHash = Sha256Hash.ZERO_HASH;
    if (block != null) {
        long num = block.num;
        // parentHash = block.getParentHash();
        ArrayList<KhaosBlock> listBlk = numKblkMap.get(num);
        if (listBlk != null) {
            listBlk.removeIf(b -> b.id.equals(hash));
        }

        if (CollectionUtils.isEmpty(listBlk)) {
            numKblkMap.remove(num);
        }

        this.hashKblkMap.remove(hash);
        return true;
    }
    return false;
}
 
Example 4
Source File: PlanAnalyzer.java    From systemds with Apache License 2.0 6 votes vote down vote up
private static ArrayList<Long> getMaterializationPoints(HashSet<Long> roots, 
		HashSet<Long> partition, CPlanMemoTable memo) 
{
	//collect materialization points bottom-up
	ArrayList<Long> ret = new ArrayList<>();
	HashSet<Long> visited = new HashSet<>();
	for( Long hopID : roots )
		rCollectMaterializationPoints(memo.getHopRefs().get(hopID), 
				visited, partition, roots, ret);
	
	//remove special-case materialization points
	//(root nodes w/ multiple consumers, tsmm input if consumed in partition)
	ret.removeIf(hopID -> roots.contains(hopID)
		|| HopRewriteUtils.isTsmmInput(memo.getHopRefs().get(hopID)));
	
	if( LOG.isTraceEnabled() ) {
		LOG.trace("Partition materialization points: "
			+ Arrays.toString(ret.toArray(new Long[0])));
	}
	
	return ret;
}
 
Example 5
Source File: ItemDataLoader.java    From Universal-FE-Randomizer with MIT License 6 votes vote down vote up
private GBAFEItemData[] usableWeaponsForCharacter(GBAFECharacterData character, Boolean ranged, Boolean melee, boolean isEnemy) {
	ArrayList<GBAFEItemData> items = new ArrayList<GBAFEItemData>();
	
	if (character.getSwordRank() > 0) { items.addAll(Arrays.asList(itemsOfTypeAndBelowRankValue(WeaponType.SWORD, character.getSwordRank(), ranged, melee))); }
	if (character.getLanceRank() > 0) { items.addAll(Arrays.asList(itemsOfTypeAndBelowRankValue(WeaponType.LANCE, character.getLanceRank(), ranged, melee))); }
	if (character.getAxeRank() > 0) { items.addAll(Arrays.asList(itemsOfTypeAndBelowRankValue(WeaponType.AXE, character.getAxeRank(), ranged, melee))); }
	if (character.getBowRank() > 0) { items.addAll(Arrays.asList(itemsOfTypeAndBelowRankValue(WeaponType.BOW, character.getBowRank(), ranged, melee))); }
	if (character.getAnimaRank() > 0) { items.addAll(Arrays.asList(itemsOfTypeAndBelowRankValue(WeaponType.ANIMA, character.getAnimaRank(), ranged, melee))); }
	if (character.getLightRank() > 0) { items.addAll(Arrays.asList(itemsOfTypeAndBelowRankValue(WeaponType.LIGHT, character.getLightRank(), ranged, melee))); }
	if (character.getDarkRank() > 0) { items.addAll(Arrays.asList(itemsOfTypeAndBelowRankValue(WeaponType.DARK, character.getDarkRank(), ranged, melee))); }
	if (character.getStaffRank() > 0) { items.addAll(Arrays.asList(itemsOfTypeAndBelowRankValue(WeaponType.STAFF, character.getStaffRank(), ranged, melee))); }
	
	Set<GBAFEItem> prfs = provider.prfWeaponsForClassID(character.getClassID());
	items.addAll(Arrays.asList(feItemsFromItemSet(prfs)));
	
	if (isEnemy) {
		items.removeIf(item -> provider.playerOnlyWeapons().contains(provider.itemWithID(item.getID())));
	}
	
	return items.toArray(new GBAFEItemData[items.size()]);
}
 
Example 6
Source File: ActivitySelectorPanel.java    From Explvs-AIO with MIT License 5 votes vote down vote up
/**
 * Filter out any invalid activities for the given panel class
 *
 * @param panel To populate activities for
 * @return Valid activities for this panel
 */
private ActivityType[] getValidActivitiesForPanel(TaskPanel panel) {
    ArrayList<ActivityType> allOptions = new ArrayList<>(Arrays.asList(ActivityType.values()));

    if (panel instanceof LevelTaskPanel || panel instanceof ResourceTaskPanel) {
        allOptions.removeIf(type -> type == ActivityType.MONEY_MAKING);
    }

    return allOptions.toArray(new ActivityType[allOptions.size()]);
}
 
Example 7
Source File: ClaferModelContentProvider.java    From CogniCrypt with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Object[] getChildren(final Object inputElement) {
	if (inputElement instanceof ClaferFeature) {
		final ClaferFeature inputFeature = (ClaferFeature) inputElement;
		final ArrayList<ClaferProperty> filteredProperties = (ArrayList<ClaferProperty>) inputFeature.getFeatureProperties().clone();

		if (this.propertyFilter != null) {
			filteredProperties.removeIf(this.propertyFilter.negate());
		}

		return filteredProperties.toArray();
	}
	return null;
}
 
Example 8
Source File: SessionStore.java    From FirefoxReality with Mozilla Public License 2.0 5 votes vote down vote up
public ArrayList<Session> getSortedSessions(boolean aPrivateMode) {
    ArrayList<Session> result = new ArrayList<>(mSessions);
    result.removeIf(session -> session.isPrivateMode() != aPrivateMode);
    result.sort((o1, o2) -> {
        if (o2.getLastUse() < o1.getLastUse()) {
            return -1;
        }
        return o2.getLastUse() == o1.getLastUse() ? 0 : 1;
    });
    return result;
}
 
Example 9
Source File: ActivitySelectorPanel.java    From Explvs-AIO with MIT License 5 votes vote down vote up
/**
 * Filter out any invalid activities for the given panel class
 *
 * @param panel To populate activities for
 * @return Valid activities for this panel
 */
private ActivityType[] getValidActivitiesForPanel(TaskPanel panel) {
    ArrayList<ActivityType> allOptions = new ArrayList<>(Arrays.asList(ActivityType.values()));

    if (panel instanceof LevelTaskPanel || panel instanceof ResourceTaskPanel) {
        allOptions.removeIf(type -> type == ActivityType.MONEY_MAKING);
    }

    return allOptions.toArray(new ActivityType[allOptions.size()]);
}
 
Example 10
Source File: TriggerHandler.java    From freeacs with MIT License 5 votes vote down vote up
private List<Trigger> createFilteredList(Trigger selectedTrigger) {
  ArrayList<Trigger> allTriggersList =
      new ArrayList<>(Arrays.asList(getUnittype().getTriggers().getTriggers()));
  allTriggersList.removeIf(trigger -> trigger.getTriggerType() == Trigger.TRIGGER_TYPE_BASIC);
  if (selectedTrigger == null) {
    return allTriggersList;
  }
  allTriggersList.remove(selectedTrigger);
  allTriggersList.removeAll(selectedTrigger.getAllChildren());
  return allTriggersList;
}
 
Example 11
Source File: ArrangeAssociations.java    From txtUML with Eclipse Public License 1.0 5 votes vote down vote up
private List<LineAssociation> processStatements(List<LineAssociation> links, List<Statement> stats,
		Set<RectangleObject> objs) throws ConversionException, InternalException {
	if (stats != null && stats.size() != 0) {
		// Set priority
		HashMap<String, Integer> priorityMap = setPriorityMap(stats);

		// Order based on priority
		links.sort((a1, a2) -> {
			if (priorityMap.containsKey(a1.getId())) {
				if (priorityMap.containsKey(a2.getId())) {
					return -1 * Integer.compare(priorityMap.get(a1.getId()), priorityMap.get(a2.getId()));
				} else
					return -1;
			} else {
				if (priorityMap.containsKey(a2.getId()))
					return 1;
				else
					return 0;
			}
		});

		ArrayList<Statement> priorityless = new ArrayList<Statement>(stats);
		priorityless.removeIf(s -> s.getType().equals(StatementType.priority));

		// Set starts/ends for statemented assocs
		setPossibles(links, priorityless, objs);
	}

	return links;
}
 
Example 12
Source File: GainRandomNewClarityAction.java    From jorbs-spire-mod with MIT License 5 votes vote down vote up
public void update() {
    ArrayList<AbstractMemory> candidates = MemoryUtils.allPossibleMemories(null);
    candidates.removeIf(memory -> !clarityFilter.test(memory));
    candidates.removeIf(memory -> MemoryManager.forPlayer(target).hasClarity(memory.ID));

    if (!candidates.isEmpty()) {
        int randomIndex = AbstractDungeon.cardRandomRng.random(0, candidates.size() - 1);
        String chosenMemoryID = candidates.get(randomIndex).ID;
        AbstractDungeon.actionManager.addToTop(new GainSpecificClarityAction(target, chosenMemoryID));
    }

    isDone = true;
}
 
Example 13
Source File: SlaveSelectionManager.java    From drftpd with GNU General Public License v2.0 5 votes vote down vote up
public RemoteSlave getASlaveForJobUpload(FileHandle file, Collection<RemoteSlave> destinationSlaves, RemoteSlave sourceSlave)
        throws NoAvailableSlaveException, FileNotFoundException {

    ArrayList<RemoteSlave> slaves = new ArrayList<>(destinationSlaves);
    slaves.removeAll(file.getAvailableSlaves()); // a slave cannot have the same file twice ;P

    // slave is not online, cannot send a file to it.
    slaves.removeIf(remoteSlave -> !remoteSlave.isAvailable());

    if (slaves.isEmpty()) {
        throw new NoAvailableSlaveException();
    }

    return process("jobup", new ScoreChart(slaves), null, Transfer.TRANSFER_SENDING_DOWNLOAD, file, sourceSlave);
}
 
Example 14
Source File: GroovyReflectionCompletion.java    From beakerx with Apache License 2.0 4 votes vote down vote up
List<String> autocompleteFromObject(List<String> parts) {
		
		List<String> lowPriorityCompletions = Arrays.asList("class","metaClass");

		List<String> filteredCompletions = Arrays.asList("empty");
		
		List<String> iterableOnlyCompletions = Arrays.asList("join(");

	
	
		ArrayList<String> result = new ArrayList<String>();
		
		try {

			String bindingReference = parts.get(0);
			Matcher m = indexedAccessPattern.matcher(bindingReference);
			
			Object value;
			if(m.matches()) {
				List collValue = (List)binding.getVariable(m.group(1));
				value = collValue.get(Integer.parseInt(m.group(2)));
			}
			else
				value = binding.getVariable(bindingReference);

			int i = 1;
			for(; i<parts.size()-1; ++i) {
				String partExpr = parts.get(i);
				
				
				Matcher m2 = indexedAccessPattern.matcher(partExpr);
				if(m2.matches()) {
					value = PropertyUtils.getIndexedProperty(value, partExpr);
				}
				else {
					value = PropertyUtils.getSimpleProperty(value, partExpr);
				}
			
				if(value == null) {
					// We can't complete anything on it
					// TODO: we could complete on the static type one day
					return result;
				}
			}
			
			String completionToken = parts.size() > 1 ? parts.get(parts.size()-1) : "";
			
			List<String> properties = getObjectPropertyNames(value); 
			
			List<String> lowPri = new ArrayList<String>();
		
			properties.forEach((String key) -> {
				if(key.startsWith(completionToken)) {
					if(lowPriorityCompletions.contains(key)) {
						lowPri.add(key);
					}
					else {
						result.add(key);
					}
				}
			});
			
			if(value instanceof Map) {
				Map<String,?> mapValue = (Map<String,?>)value;
				mapValue.keySet().stream()
								 .filter(k -> k.startsWith(completionToken))
								 .forEach(k -> result.add(k));
			}
			
			if(value instanceof Iterable || value instanceof Map) {
				result.addAll(SUPPLEMENTARY_COLLECTION_COMPLETIONS);
				result.addAll(iterableOnlyCompletions);
			}
			
			if(value instanceof String) {
				result.addAll(STRING_COMPLETIONS);
			}
			
//			result.addAll(lowPri);
			
			result.removeIf(v -> !v.startsWith(completionToken));
				
			result.removeAll(filteredCompletions);
			
			// Finally, add method names
			result.addAll(getObjectMethodCompletions(value, completionToken));
	
		} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
			e.printStackTrace();
		}
		return result;
	}
 
Example 15
Source File: LegendaryPatch.java    From jorbs-spire-mod with MIT License 4 votes vote down vote up
private static void removeLegendaryCards(ArrayList<AbstractCard> list) {
    list.removeIf(c -> c.hasTag(LEGENDARY));
}
 
Example 16
Source File: ReplicationThrottleHelper.java    From cruise-control with BSD 2-Clause "Simplified" License 4 votes vote down vote up
static String removeReplicasFromConfig(String throttleConfig, Set<String> replicas) {
  ArrayList<String> throttles = new ArrayList<>(Arrays.asList(throttleConfig.split(",")));
  throttles.removeIf(replicas::contains);
  return String.join(",", throttles);
}
 
Example 17
Source File: FilterRandomCardGenerationPatch.java    From jorbs-spire-mod with MIT License 4 votes vote down vote up
private static void RemovePersistentPositiveEffects(ArrayList<AbstractCard> list) {
    list.removeIf(card -> card.hasTag(PERSISTENT_POSITIVE_EFFECT));
}
 
Example 18
Source File: ProductLookupDescriptor.java    From metasfresh-webui-api-legacy with GNU General Public License v3.0 4 votes vote down vote up
private static List<ProductWithATP> createProductWithATPs(
		@NonNull final LookupValue productLookupValue,
		@NonNull final ImmutableList<Group> atpGroups,
		final boolean displayATPOnlyIfPositive)
{
	final ArrayList<ProductWithATP> result = new ArrayList<>();

	ProductWithATP productWithATP_ALL = null;
	ProductWithATP productWithATP_OTHERS = null;
	for (final Group atpGroup : atpGroups)
	{
		final ProductWithATP productWithATP = ProductWithATP.builder()
				.productId(productLookupValue.getIdAs(ProductId::ofRepoId))
				.productDisplayName(productLookupValue.getDisplayNameTrl())
				// .displayQtyAndAttributes(displayATP)
				.qtyATP(atpGroup.getQty())
				.attributesType(atpGroup.getType())
				.attributes(atpGroup.getAttributes())
				.build();

		result.add(productWithATP);

		if (productWithATP.getAttributesType() == Group.Type.ALL_STORAGE_KEYS)
		{
			productWithATP_ALL = productWithATP;
		}
		else if (productWithATP.getAttributesType() == Group.Type.OTHER_STORAGE_KEYS)
		{
			productWithATP_OTHERS = productWithATP;
		}
	}

	//
	// If OTHERS has the same Qty as ALL, remove OTHERS because it's pointless
	if (productWithATP_ALL != null
			&& productWithATP_OTHERS != null
			&& Objects.equals(productWithATP_OTHERS.getQtyATP(), productWithATP_ALL.getQtyATP()))
	{
		result.remove(productWithATP_OTHERS);
		productWithATP_OTHERS = null;
	}

	//
	// Remove non-positive quantities if asked
	if (displayATPOnlyIfPositive)
	{
		result.removeIf(productWithATP -> productWithATP.getQtyATP().signum() <= 0);
	}

	//
	// Make sure we have at least one entry for each product
	if (result.isEmpty())
	{
		result.add(ProductWithATP.builder()
				.productId(productLookupValue.getIdAs(ProductId::ofRepoId))
				.productDisplayName(productLookupValue.getDisplayNameTrl())
				.qtyATP(null)
				.build());
	}

	return result;
}
 
Example 19
Source File: SelectAllOnTypeHandler.java    From gef with Eclipse Public License 2.0 3 votes vote down vote up
/**
 * Returns a list containing the {@link IContentPart}s that should be
 * selected by this action handler at the point of time this method is
 * called.
 * <p>
 * Per default, all active and selectable parts within the content-part-map
 * of the current viewer are returned.
 *
 * @return A list containing the {@link IContentPart}s that should be
 *         selected by this action handler at the point of time this method
 *         is called.
 */
protected List<? extends IContentPart<? extends Node>> getSelectableContentParts() {
	if (getHost().getViewer() == null) {
		return Collections.emptyList();
	}
	ArrayList<IContentPart<? extends Node>> parts = new ArrayList<>(
			getHost().getViewer().getContentPartMap().values());
	parts.removeIf(p -> !p.isSelectable());
	return parts;
}
 
Example 20
Source File: SelectAllAction.java    From gef with Eclipse Public License 2.0 3 votes vote down vote up
/**
 * Returns a list containing the {@link IContentPart}s that should be
 * selected by this action handler at the point of time this method is
 * called.
 * <p>
 * Per default, all active and selectable parts within the content-part-map
 * of the current viewer are returned.
 *
 * @return A list containing the {@link IContentPart}s that should be
 *         selected by this action handler at the point of time this method
 *         is called.
 */
protected List<? extends IContentPart<? extends Node>> getSelectableContentParts() {
	if (getViewer() == null) {
		return Collections.emptyList();
	}
	ArrayList<IContentPart<? extends Node>> parts = new ArrayList<>(
			getViewer().getContentPartMap().values());
	parts.removeIf(p -> !p.isSelectable());
	return parts;
}