List of usage examples for com.google.common.base Predicates not
public static <T> Predicate<T> not(Predicate<T> predicate)
From source file:forge.learnedai.AiBlockController.java
/** * <p>/* w ww. ja v a 2 s. c om*/ * makeGangBlocks. * </p> * * @param combat a {@link forge.game.combat.Combat} object. */ private void makeGangBlocks(final Combat combat) { List<Card> currentAttackers = CardLists.filter(attackersLeft, Predicates.not(rampagesOrNeedsManyToBlock)); List<Card> blockers; // Try to block an attacker without first strike with a gang of first strikers for (final Card attacker : attackersLeft) { if (!ComputerUtilCombat.dealsFirstStrikeDamage(attacker, false, combat)) { blockers = getPossibleBlockers(combat, attacker, blockersLeft, false); final List<Card> firstStrikeBlockers = new ArrayList<>(); final List<Card> blockGang = new ArrayList<>(); for (Card blocker : blockers) { if (blocker.hasFirstStrike() || blocker.hasDoubleStrike()) { firstStrikeBlockers.add(blocker); } } if (firstStrikeBlockers.size() > 1) { CardLists.sortByPowerDesc(firstStrikeBlockers); for (final Card blocker : firstStrikeBlockers) { final int damageNeeded = ComputerUtilCombat.getDamageToKill(attacker) + ComputerUtilCombat .predictToughnessBonusOfAttacker(attacker, blocker, combat, false); // if the total damage of the blockgang was not enough // without but is enough with this blocker finish the // blockgang if (ComputerUtilCombat.totalFirstStrikeDamageOfBlockers(attacker, blockGang) < damageNeeded || CombatUtil.needsBlockers(attacker) > blockGang.size()) { blockGang.add(blocker); if (ComputerUtilCombat.totalFirstStrikeDamageOfBlockers(attacker, blockGang) >= damageNeeded) { currentAttackers.remove(attacker); for (final Card b : blockGang) { if (CombatUtil.canBlock(attacker, blocker, combat)) { combat.addBlocker(attacker, b); } } } } } } } } attackersLeft = (new ArrayList<>(currentAttackers)); currentAttackers = new ArrayList<>(attackersLeft); // Try to block an attacker with two blockers of which only one will die for (final Card attacker : attackersLeft) { blockers = getPossibleBlockers(combat, attacker, blockersLeft, false); List<Card> usableBlockers; final List<Card> blockGang = new ArrayList<>(); int absorbedDamage; // The amount of damage needed to kill the first blocker int currentValue; // The value of the creatures in the blockgang // AI can't handle good triple blocks yet if (CombatUtil.needsBlockers(attacker) > 2) { continue; } // Try to add blockers that could be destroyed, but are worth less than the attacker // Don't use blockers without First Strike or Double Strike if attacker has it usableBlockers = CardLists.filter(blockers, new Predicate<Card>() { @Override public boolean apply(final Card c) { if (ComputerUtilCombat.dealsFirstStrikeDamage(attacker, false, combat) && !ComputerUtilCombat.dealsFirstStrikeDamage(c, false, combat)) { return false; } return lifeInDanger || ComputerUtilCard.evaluateCreature(c) + diff < ComputerUtilCard .evaluateCreature(attacker); } }); if (usableBlockers.size() < 2) { return; } final Card leader = ComputerUtilCard.getBestCreatureAI(usableBlockers); blockGang.add(leader); usableBlockers.remove(leader); absorbedDamage = ComputerUtilCombat.getEnoughDamageToKill(leader, attacker.getNetCombatDamage(), attacker, true); currentValue = ComputerUtilCard.evaluateCreature(leader); for (final Card blocker : usableBlockers) { // Add an additional blocker if the current blockers are not // enough and the new one would deal the remaining damage final int currentDamage = ComputerUtilCombat.totalDamageOfBlockers(attacker, blockGang); final int additionalDamage = ComputerUtilCombat.dealsDamageAsBlocker(attacker, blocker); final int absorbedDamage2 = ComputerUtilCombat.getEnoughDamageToKill(blocker, attacker.getNetCombatDamage(), attacker, true); final int addedValue = ComputerUtilCard.evaluateCreature(blocker); final int damageNeeded = ComputerUtilCombat.getDamageToKill(attacker) + ComputerUtilCombat.predictToughnessBonusOfAttacker(attacker, blocker, combat, false); if ((damageNeeded > currentDamage || CombatUtil.needsBlockers(attacker) > blockGang.size()) && !(damageNeeded > currentDamage + additionalDamage) // The attacker will be killed && (absorbedDamage2 + absorbedDamage > attacker.getNetCombatDamage() // only one blocker can be killed || currentValue + addedValue - 50 <= ComputerUtilCard.evaluateCreature(attacker) // or attacker is worth more || (lifeInDanger && ComputerUtilCombat.lifeInDanger(ai, combat))) // or life is in danger && CombatUtil.canBlock(attacker, blocker, combat)) { // this is needed for attackers that can't be blocked by // more than 1 currentAttackers.remove(attacker); combat.addBlocker(attacker, blocker); if (CombatUtil.canBlock(attacker, leader, combat)) { combat.addBlocker(attacker, leader); } break; } } } attackersLeft = (new ArrayList<>(currentAttackers)); }
From source file:forge.ai.AiBlockController.java
/** * <p>/*from w w w .ja v a 2s . c om*/ * makeGangBlocks. * </p> * * @param combat a {@link forge.game.combat.Combat} object. */ private void makeGangBlocks(final Combat combat) { List<Card> currentAttackers = CardLists.filter(attackersLeft, Predicates.not(rampagesOrNeedsManyToBlock)); List<Card> blockers; // Try to block an attacker without first strike with a gang of first strikers for (final Card attacker : attackersLeft) { if (!ComputerUtilCombat.dealsFirstStrikeDamage(attacker, false, combat)) { blockers = getPossibleBlockers(combat, attacker, blockersLeft, false); final List<Card> firstStrikeBlockers = new ArrayList<>(); final List<Card> blockGang = new ArrayList<>(); for (Card blocker : blockers) { if (ComputerUtilCombat.canDestroyBlockerBeforeFirstStrike(blocker, attacker, false)) { continue; } if (blocker.hasFirstStrike() || blocker.hasDoubleStrike()) { firstStrikeBlockers.add(blocker); } } if (firstStrikeBlockers.size() > 1) { CardLists.sortByPowerDesc(firstStrikeBlockers); for (final Card blocker : firstStrikeBlockers) { final int damageNeeded = ComputerUtilCombat.getDamageToKill(attacker) + ComputerUtilCombat .predictToughnessBonusOfAttacker(attacker, blocker, combat, false); // if the total damage of the blockgang was not enough // without but is enough with this blocker finish the // blockgang if (ComputerUtilCombat.totalFirstStrikeDamageOfBlockers(attacker, blockGang) < damageNeeded || CombatUtil.needsBlockers(attacker) > blockGang.size()) { blockGang.add(blocker); if (ComputerUtilCombat.totalFirstStrikeDamageOfBlockers(attacker, blockGang) >= damageNeeded) { currentAttackers.remove(attacker); for (final Card b : blockGang) { if (CombatUtil.canBlock(attacker, blocker, combat)) { combat.addBlocker(attacker, b); } } } } } } } } attackersLeft = (new ArrayList<>(currentAttackers)); currentAttackers = new ArrayList<>(attackersLeft); // Try to block an attacker with two blockers of which only one will die for (final Card attacker : attackersLeft) { blockers = getPossibleBlockers(combat, attacker, blockersLeft, false); List<Card> usableBlockers; final List<Card> blockGang = new ArrayList<>(); int absorbedDamage; // The amount of damage needed to kill the first blocker int currentValue; // The value of the creatures in the blockgang // AI can't handle good triple blocks yet if (CombatUtil.needsBlockers(attacker) > 2) { continue; } // Try to add blockers that could be destroyed, but are worth less than the attacker // Don't use blockers without First Strike or Double Strike if attacker has it usableBlockers = CardLists.filter(blockers, new Predicate<Card>() { @Override public boolean apply(final Card c) { if (ComputerUtilCombat.dealsFirstStrikeDamage(attacker, false, combat) && !ComputerUtilCombat.dealsFirstStrikeDamage(c, false, combat)) { return false; } return lifeInDanger || ComputerUtilCard.evaluateCreature(c) + diff < ComputerUtilCard .evaluateCreature(attacker); } }); if (usableBlockers.size() < 2) { return; } final Card leader = ComputerUtilCard.getBestCreatureAI(usableBlockers); blockGang.add(leader); usableBlockers.remove(leader); absorbedDamage = ComputerUtilCombat.getEnoughDamageToKill(leader, attacker.getNetCombatDamage(), attacker, true); currentValue = ComputerUtilCard.evaluateCreature(leader); for (final Card blocker : usableBlockers) { // Add an additional blocker if the current blockers are not // enough and the new one would deal the remaining damage final int currentDamage = ComputerUtilCombat.totalDamageOfBlockers(attacker, blockGang); final int additionalDamage = ComputerUtilCombat.dealsDamageAsBlocker(attacker, blocker); final int absorbedDamage2 = ComputerUtilCombat.getEnoughDamageToKill(blocker, attacker.getNetCombatDamage(), attacker, true); final int addedValue = ComputerUtilCard.evaluateCreature(blocker); final int damageNeeded = ComputerUtilCombat.getDamageToKill(attacker) + ComputerUtilCombat.predictToughnessBonusOfAttacker(attacker, blocker, combat, false); if ((damageNeeded > currentDamage || CombatUtil.needsBlockers(attacker) > blockGang.size()) && !(damageNeeded > currentDamage + additionalDamage) // The attacker will be killed && (absorbedDamage2 + absorbedDamage > attacker.getNetCombatDamage() // only one blocker can be killed || currentValue + addedValue - 50 <= ComputerUtilCard.evaluateCreature(attacker) // or attacker is worth more || (lifeInDanger && ComputerUtilCombat.lifeInDanger(ai, combat))) // or life is in danger && CombatUtil.canBlock(attacker, blocker, combat)) { // this is needed for attackers that can't be blocked by // more than 1 currentAttackers.remove(attacker); combat.addBlocker(attacker, blocker); if (CombatUtil.canBlock(attacker, leader, combat)) { combat.addBlocker(attacker, leader); } break; } } } attackersLeft = (new ArrayList<>(currentAttackers)); }
From source file:edu.udo.scaffoldhunter.model.dataimport.Importer.java
private List<PropertyDefinition> saveDatasetAndPropertyDefinitions(Dataset dataset, Map<String, PropertyDefinition> propDefs) { for (ImportJob j : importProcess.getJobs()) { for (Map.Entry<String, SourcePropertyMapping> e : j.getPropertyMappings().entrySet()) { if (e.getValue().getPropertyDefiniton() != null) { PropertyDefinition propDef = e.getValue().getPropertyDefiniton(); // find unique key if key is not set if (propDef.getKey() == null || propDef.getKey().isEmpty()) { String newKey; for (int i = 0;; i++) { newKey = propDef.getTitle().toUpperCase() + i; /* * prevents key collision with scaffold properties * and calculated properties *///from w w w .j a v a2 s .co m if (newKey.startsWith(ScaffoldTreeGenerator.SCAFFOLD_PROPERTY_KEY_PREFIX) || newKey.startsWith(Calculator.CALC_PLUGINS_PROPERTY_KEY_PREFIX)) { newKey = "_" + newKey; } if (!propDefs.containsKey(newKey)) break; } propDef.setKey(newKey); } else { /* * prevents key collision with scaffold properties and * calculated properties */ if (propDef.getKey().startsWith(ScaffoldTreeGenerator.SCAFFOLD_PROPERTY_KEY_PREFIX) || propDef.getKey().startsWith(Calculator.CALC_PLUGINS_PROPERTY_KEY_PREFIX)) { propDef.setKey("_" + propDef.getKey()); } } propDef.setDataset(dataset); propDefs.put(propDef.getKey(), propDef); } } } if (importProcess.getDataset() != null) { Predicate<PropertyDefinition> notOld = Predicates.and(Predicates.notNull(), Predicates.not(Predicates.in(importProcess.getDataset().getPropertyDefinitions().values()))); newPropDefs = Lists.newArrayList(Iterables.filter(propDefs.values(), notOld)); } else { newPropDefs = Lists.newArrayList(propDefs.values()); } dataset.setPropertyDefinitions(propDefs); DBExceptionHandler.callDBManager(db, new VoidUnaryDBFunction<Dataset>(dataset) { @Override public void call(Dataset arg) throws DatabaseException { db.saveOrUpdate(newDataset); db.saveAllAsNew(newPropDefs); } }); return newPropDefs; }
From source file:com.palantir.atlasdb.transaction.impl.SerializableTransaction.java
private void verifyRows(Transaction ro) { for (String table : rowsRead.keySet()) { final ConcurrentNavigableMap<Cell, byte[]> readsForTable = getReadsForTable(table); Multimap<ColumnSelection, byte[]> map = Multimaps.newSortedSetMultimap( Maps.<ColumnSelection, Collection<byte[]>>newHashMap(), new Supplier<SortedSet<byte[]>>() { @Override/*from w w w .ja va2 s . c om*/ public TreeSet<byte[]> get() { return Sets.newTreeSet(UnsignedBytes.lexicographicalComparator()); } }); for (RowRead r : rowsRead.get(table)) { map.putAll(r.cols, r.rows); } for (final ColumnSelection cols : map.keySet()) { for (List<byte[]> batch : Iterables.partition(map.get(cols), 1000)) { SortedMap<byte[], RowResult<byte[]>> currentRows = ro.getRows(table, batch, cols); for (byte[] row : batch) { RowResult<byte[]> currentRow = currentRows.get(row); Map<Cell, byte[]> orignalReads = readsForTable .tailMap(Cells.createSmallestCellForRow(row), true) .headMap(Cells.createLargestCellForRow(row), true); // We want to filter out all our reads to just the set that matches our column selection. orignalReads = Maps.filterKeys(orignalReads, new Predicate<Cell>() { @Override public boolean apply(Cell input) { return cols.contains(input.getColumnName()); } }); if (writesByTable.get(table) != null) { // We don't want to verify any reads that we wrote to cause we will just read our own values. // NB: We filter our write set out here because our normal SI checking handles this case to ensure the value hasn't changed. orignalReads = Maps.filterKeys(orignalReads, Predicates.not(Predicates.in(writesByTable.get(table).keySet()))); } if (currentRow == null && orignalReads.isEmpty()) { continue; } if (currentRow == null) { throw TransactionSerializableConflictException.create(table, getTimestamp(), System.currentTimeMillis() - timeCreated); } Map<Cell, byte[]> currentCells = Maps2.fromEntries(currentRow.getCells()); if (writesByTable.get(table) != null) { // We don't want to verify any reads that we wrote to cause we will just read our own values. // NB: We filter our write set out here because our normal SI checking handles this case to ensure the value hasn't changed. currentCells = Maps.filterKeys(currentCells, Predicates.not(Predicates.in(writesByTable.get(table).keySet()))); } if (!areMapsEqual(orignalReads, currentCells)) { throw TransactionSerializableConflictException.create(table, getTimestamp(), System.currentTimeMillis() - timeCreated); } } } } } }
From source file:co.cask.cdap.internal.app.runtime.distributed.AbstractProgramTwillRunnable.java
/** * Creates program options. It contains program and user arguments as passed form the distributed program runner. * Extra program arguments are inserted based on the environment information (e.g. host, instance id). Also all * configs available through the TwillRunnable configs are also available through program arguments. *//*from w w w. j a va2 s . com*/ private ProgramOptions createProgramOptions(CommandLine cmdLine, TwillContext context, Map<String, String> configs) { ProgramOptions original = GSON.fromJson(cmdLine.getOptionValue(RunnableOptions.PROGRAM_OPTIONS), ProgramOptions.class); // Overwrite them with environmental information Map<String, String> arguments = Maps.newHashMap(original.getArguments().asMap()); arguments.put(ProgramOptionConstants.INSTANCE_ID, Integer.toString(context.getInstanceId())); arguments.put(ProgramOptionConstants.INSTANCES, Integer.toString(context.getInstanceCount())); arguments.put(ProgramOptionConstants.RUN_ID, original.getArguments().getOption(ProgramOptionConstants.RUN_ID)); arguments.put(ProgramOptionConstants.TWILL_RUN_ID, context.getApplicationRunId().getId()); arguments.put(ProgramOptionConstants.HOST, context.getHost().getCanonicalHostName()); arguments .putAll(Maps.filterKeys(configs, Predicates.not(Predicates.in(ImmutableSet.of("hConf", "cConf"))))); return new SimpleProgramOptions(context.getSpecification().getName(), new BasicArguments(arguments), original.getUserArguments(), original.isDebug()); }
From source file:com.sri.ai.praise.lbp.core.ProductFactor.java
@SuppressWarnings("unchecked") private static void assertIsLegalUnionDomain(Expression unionDomain) { Predicate<Expression> isLegalPredicate = Predicates.and(new Sets.IsNonEmptyUniSet(), Predicates.not(new Sets.IsSingletonExtensionalSet()), // nested union and conditional arguments are // allowed. As this algorithm is recursive // these will be checked on a nested call. Predicates.not(new IsApplicationOf(FunctorConstants.UNION)), Predicates.not(new IsApplicationOf(FunctorConstants.IF_THEN_ELSE))); if (Util.thereExists(unionDomain.getArguments(), isLegalPredicate)) { // the reason for this check is that we are not // trying to determine the intersection of these // sets, which we would need to do if they are // non-empty unisets and non-singleton sets. throw new IllegalArgumentException( "If ProductFactor receives a union of sets of factors, it must be on multisets or singleton unisets, or empty sets only, but got " + unionDomain);/* ww w . j a v a2 s . c o m*/ } }
From source file:org.jetbrains.jet.lang.resolve.lazy.LazyClassDescriptor.java
private static JetClassLikeInfo noEnumEntries(JetClassLikeInfo classLikeInfo) { return new FilteringClassLikeInfo(classLikeInfo, Predicates.not(ONLY_ENUM_ENTRIES)); }
From source file:com.palantir.ptoss.cinch.core.BindingContext.java
private Map<String, ObjectFieldMethod> indexBindableMethods() throws IllegalArgumentException { // Get all fields marked @Bindable List<Field> bindables = getAnnotatedFields(Bindable.class); if (Iterables.any(bindables, Predicates.not(Reflections.IS_FIELD_FINAL))) { throw new BindingException("all @Bindables have to be final"); }/*ww w . j a v a 2s. c om*/ // Add all BindableModels bindables.addAll(getBindableModelFields()); // Index those methods. List<ObjectFieldMethod> methods = getParameterlessMethodsOnFieldTypes(object, bindables); // Add methods for classes marked @Bindable if (Reflections.isClassAnnotatedForClassHierarchy(object, Bindable.class)) { methods.addAll(Reflections.getParameterlessMethodsForClassHierarchy(object)); } return indexMethods(methods); }
From source file:org.immutables.value.processor.meta.ValueType.java
public List<ValueAttribute> getConstructorExcluded() { if (constructorExcluded == null) { constructorExcluded = FluentIterable.from(getSettableAttributes()) .filter(Predicates.not(Predicates.in(getConstructorArguments()))).toList(); }//from w ww . ja v a 2 s .c o m return constructorExcluded; }
From source file:com.google.devtools.build.lib.rules.objc.CompilationAttributes.java
/** * Returns the exec paths of all header search paths that should be added to this target and * dependers on this target, obtained from the {@code includes} attribute. *///from w w w.j av a2 s. com public NestedSet<PathFragment> headerSearchPaths(PathFragment genfilesFragment) { NestedSetBuilder<PathFragment> paths = NestedSetBuilder.stableOrder(); if (packageFragment.isPresent()) { List<PathFragment> rootFragments = ImmutableList.of(packageFragment.get(), genfilesFragment.getRelative(packageFragment.get())); Iterable<PathFragment> relativeIncludes = Iterables.filter(includes(), Predicates.not(PathFragment.IS_ABSOLUTE)); for (PathFragment include : relativeIncludes) { for (PathFragment rootFragment : rootFragments) { paths.add(rootFragment.getRelative(include).normalize()); } } } return paths.build(); }