List of usage examples for com.google.common.base Predicates and
public static <T> Predicate<T> and(Predicate<? super T> first, Predicate<? super T> second)
From source file:forge.quest.QuestUtilCards.java
/** * Generate boosters in shop.//from ww w . j a v a 2 s . c om * * @param count * the count */ private void generateBoostersInShop(final int count) { for (int i = 0; i < count; i++) { final int rollD100 = MyRandom.getRandom().nextInt(100); Predicate<CardEdition> filter = rollD100 < 40 ? this.filterT2booster : (rollD100 < 75 ? this.filterExtButT2 : this.filterNotExt); if (qc.getFormat() != null) { filter = Predicates.and(CardEdition.Predicates.CAN_MAKE_BOOSTER, isLegalInQuestFormat(qc.getFormat())); } Iterable<CardEdition> rightEditions = Iterables.filter(FModel.getMagicDb().getEditions(), filter); if (!rightEditions.iterator().hasNext()) { continue; } this.qa.getShopList().add(BoosterPack.FN_FROM_SET.apply(Aggregates.random(rightEditions))); } if (qpref.getPrefInt(QPref.SPECIAL_BOOSTERS) == 1) { for (String color : SealedProduct.specialSets) { for (int i = 0; i < count; i++) { this.qa.getShopList().add(new BoosterPack(color, getColoredBoosterTemplate(color))); } } } }
From source file:com.github.rinde.dynurg.Generator.java
static ScenarioGenerator createGenerator(long scenarioLength, long urgency, TimeSeriesGenerator tsg, LocationGenerator lg) {/*w w w . j av a 2s. com*/ return ScenarioGenerator.builder() // global .timeUnit(SI.MILLI(SI.SECOND)).scenarioLength(scenarioLength).tickSize(TICK_SIZE) .speedUnit(NonSI.KILOMETERS_PER_HOUR).distanceUnit(SI.KILOMETER) .stopCondition(Predicates.and(StopConditions.VEHICLES_DONE_AND_BACK_AT_DEPOT, StopConditions.TIME_OUT_EVENT)) // parcels .parcels(Parcels.builder() .announceTimes(TimeSeries.filter(tsg, TimeSeries.numEventsPredicate(NUM_ORDERS))) .pickupDurations(constant(PICKUP_DURATION)).deliveryDurations(constant(DELIVERY_DURATION)) .neededCapacities(constant(0)).locations(lg) .timeWindows(new CustomTimeWindowGenerator(urgency) // TimeWindows.builder() // .pickupUrgency(constant(urgency)) // // .pickupTimeWindowLength(StochasticSuppliers.uniformLong(5 // // * 60 * 1000L,)) // .deliveryOpening(constant(0L)) // .minDeliveryLength(constant(10 * 60 * 1000L)) // .deliveryLengthFactor(constant(3d)) // .build() ).build()) // vehicles .vehicles(Vehicles.builder().capacities(constant(1)).centeredStartPositions() .creationTimes(constant(-1L)).numberOfVehicles(constant(NUM_VEHICLES)) .speeds(constant(VEHICLE_SPEED_KMH)).timeWindowsAsScenario().build()) // depots .depots(Depots.singleCenteredDepot()) // models .addModel(Models.roadModel(VEHICLE_SPEED_KMH, true)) .addModel(Models.pdpModel(TimeWindowPolicies.TARDY_ALLOWED)).build(); }
From source file:com.eucalyptus.bootstrap.Hosts.java
private static boolean eucalyptusStoppedLocally() { return !Iterables.isEmpty(ServiceConfigurations.filter(Eucalyptus.class, Predicates.and(ServiceConfigurations.filterHostLocal(), State.STOPPED))); }
From source file:forge.quest.QuestUtilCards.java
/** * Generate precons in shop./*from w w w.j ava2 s . c o m*/ * * @param count * the count */ private void generateTournamentsInShop(final int count) { Predicate<CardEdition> formatFilter = CardEdition.Predicates.HAS_TOURNAMENT_PACK; if (qc.getFormat() != null) { formatFilter = Predicates.and(formatFilter, isLegalInQuestFormat(qc.getFormat())); } Iterable<CardEdition> rightEditions = Iterables.filter(FModel.getMagicDb().getEditions(), formatFilter); this.qa.getShopList().addAllFlat( Aggregates.random(Iterables.transform(rightEditions, TournamentPack.FN_FROM_SET), count)); }
From source file:clocker.docker.entity.DockerInfrastructureImpl.java
/** * De-register our {@link DockerLocation} and its children. *//*from w w w .ja v a2 s .c o m*/ @Override public void stop() { sensors().set(SERVICE_UP, Boolean.FALSE); ServiceStateLogic.setExpectedState(this, Lifecycle.STOPPING); Duration timeout = config().get(SHUTDOWN_TIMEOUT); deleteLocation(); // Shutdown the Registry if configured if (config().get(DOCKER_SHOULD_START_REGISTRY)) { Entity registry = sensors().get(DOCKER_IMAGE_REGISTRY); DockerUtils.stop(this, registry, Duration.THIRTY_SECONDS); } // Find all applications and stop, blocking for up to five minutes until ended try { Iterable<Entity> entities = Iterables.filter(getManagementContext().getEntityManager().getEntities(), Predicates.and(DockerUtils.sameInfrastructure(this), Predicates.not(EntityPredicates.applicationIdEqualTo(getApplicationId())))); Set<Application> applications = ImmutableSet .copyOf(Iterables.transform(entities, new Function<Entity, Application>() { @Override public Application apply(Entity input) { return input.getApplication(); } })); LOG.debug("Stopping applications: {}", Iterables.toString(applications)); Entities.invokeEffectorList(this, applications, Startable.STOP).get(timeout); } catch (Exception e) { LOG.warn("Error stopping applications", e); } // Stop all Docker hosts in parallel try { DynamicCluster hosts = getDockerHostCluster(); LOG.debug("Stopping hosts: {}", Iterables.toString(hosts.getMembers())); Entities.invokeEffectorList(this, hosts.getMembers(), Startable.STOP).get(timeout); } catch (Exception e) { LOG.warn("Error stopping hosts", e); } ServiceStateLogic.setExpectedState(this, Lifecycle.STOPPED); }
From source file:forge.quest.QuestUtilCards.java
/** * Generate precons in shop./*from www .j a v a 2s .c om*/ * * @param count * the count */ private void generateFatPacksInShop(final int count) { Predicate<CardEdition> formatFilter = CardEdition.Predicates.HAS_FAT_PACK; if (qc.getFormat() != null) { formatFilter = Predicates.and(formatFilter, isLegalInQuestFormat(qc.getFormat())); } Iterable<CardEdition> rightEditions = Iterables.filter(FModel.getMagicDb().getEditions(), formatFilter); this.qa.getShopList() .addAllFlat(Aggregates.random(Iterables.transform(rightEditions, FatPack.FN_FROM_SET), count)); }
From source file:forge.quest.QuestUtilCards.java
private void generateBoosterBoxesInShop(final int count) { if (count == 0) { return;//from w w w . j a va 2s. c o m } Predicate<CardEdition> formatFilter = CardEdition.Predicates.HAS_BOOSTER_BOX; if (qc.getFormat() != null) { formatFilter = Predicates.and(formatFilter, isLegalInQuestFormat(qc.getFormat())); } Iterable<CardEdition> rightEditions = Iterables.filter(FModel.getMagicDb().getEditions(), formatFilter); List<CardEdition> editions = new ArrayList<>(); for (CardEdition e : rightEditions) { editions.add(e); } Collections.shuffle(editions); int numberOfBoxes = Math.min(Math.max(count / 2, 1), editions.size()); if (numberOfBoxes == 0) { return; } editions = editions.subList(0, numberOfBoxes); List<BoosterBox> output = new ArrayList<>(); for (CardEdition e : editions) { output.add(BoosterBox.FN_FROM_SET.apply(e)); } this.qa.getShopList().addAllFlat(output); }
From source file:com.eucalyptus.images.Emis.java
private static <T extends ImageInfo> T resolveDiskImage(final String imageId, final Function<String, T> resolver) throws IllegalMetadataAccessException { final T img = resolver.apply(imageId); if (Contexts.exists()) { final Predicate<T> filter = Predicates.and(Images.FilterPermissions.INSTANCE, RestrictedTypes.filterPrivilegedWithoutOwner()); if (filter.apply(img)) { if (!Images.FilterImageStates.INSTANCE.apply(img)) throw Exceptions.toUndeclared(new EucalyptusCloudException("Image state is not available")); return img; } else {/* w ww. j a v a2 s . c om*/ throw new IllegalMetadataAccessException(imageId + ": permission denied."); } } else { return img; } }
From source file:com.eucalyptus.autoscaling.AutoScalingService.java
public DescribePoliciesResponseType describePolicies(final DescribePoliciesType request) throws EucalyptusCloudException { final DescribePoliciesResponseType reply = request.getReply(); //TODO: MaxRecords / NextToken support for DescribePolicies final Context ctx = Contexts.lookup(); final boolean showAll = request.policyNames().remove("verbose"); final OwnerFullName ownerFullName = ctx.hasAdministrativePrivileges() && showAll ? null : ctx.getUserFullName().asAccountFullName(); try {/* w w w .j a va 2 s . c o m*/ final Predicate<ScalingPolicy> requestedAndAccessible = Predicates.and( AutoScalingMetadatas.filterPrivilegesByIdOrArn(ScalingPolicy.class, request.policyNames()), AutoScalingResourceName.isResourceName().apply(request.getAutoScalingGroupName()) ? AutoScalingMetadatas.filterByProperty( AutoScalingResourceName .parse(request.getAutoScalingGroupName(), autoScalingGroup).getUuid(), ScalingPolicies.toGroupUuid()) : AutoScalingMetadatas.filterByProperty(request.getAutoScalingGroupName(), ScalingPolicies.toGroupName())); final List<ScalingPolicyType> results = reply.getDescribePoliciesResult().getScalingPolicies() .getMember(); results.addAll(scalingPolicies.list(ownerFullName, requestedAndAccessible, TypeMappers.lookup(ScalingPolicy.class, ScalingPolicyType.class))); final List<String> scalingPolicyArns = Lists.transform(results, ScalingPolicyType.policyArn()); final Map<String, Collection<String>> policyArnToAlarmArns = activityManager .getAlarmsForPolicies(ctx.getUserFullName(), scalingPolicyArns); for (final ScalingPolicyType scalingPolicyType : results) { final Collection<String> alarmArns = policyArnToAlarmArns.get(scalingPolicyType.getPolicyARN()); if (alarmArns != null && !alarmArns.isEmpty()) { scalingPolicyType.setAlarms(new Alarms(alarmArns)); } } } catch (Exception e) { handleException(e); } return reply; }
From source file:org.spongepowered.common.mixin.core.world.extent.MixinExtentViewTransform.java
@Override public Collection<TileEntity> getTileEntities(Predicate<TileEntity> filter) { // Order matters! Bounds filter before the argument filter so it doesn't see out of bounds entities return this.extent .getTileEntities(Predicates.and(new TileEntityInBounds(this.blockMin, this.blockMax), filter)); }