List of usage examples for java.util Set removeIf
default boolean removeIf(Predicate<? super E> filter)
From source file:org.dkpro.core.io.rdf.internal.Rdf2Uima.java
public static FeatureStructure initFS(OntResource aFS, JCas aJCas) { CAS cas = aJCas.getCas();/* www . j a va2 s .co m*/ // Figure out the UIMA type - there can be only one type per FS Set<Resource> types = aFS.listRDFTypes(true).toSet(); types.removeIf(res -> res.getURI().startsWith(RdfCas.NS_RDFCAS)); assert types.size() == 1; Type type = CasUtil.getType(cas, types.iterator().next().getURI().substring(RdfCas.NS_UIMA.length())); FeatureStructure fs; if (type.getName().equals(DocumentMetaData.class.getName())) { // Special handling to avoid ending up with two document annotations in the CAS fs = DocumentMetaData.get(aJCas); } else { fs = cas.createFS(type); } return fs; }
From source file:org.opensingular.flow.core.FlowMap.java
private static boolean removeIfReachesTheEnd(Set<STask<?>> tasks) { return tasks.removeIf((task) -> task.getTransitions().stream() .anyMatch((transition) -> transition.getDestination().isEnd() || !tasks.contains(transition.getDestination()))); }
From source file:org.optaplanner.core.config.domain.ScanAnnotatedClassesConfig.java
private void retainOnlyClassesWithDeclaredAnnotation(Set<Class<?>> classSet, Class<? extends Annotation> annotation) { classSet.removeIf(clazz -> !clazz.isAnnotationPresent(annotation)); }
From source file:squash.booking.lambdas.core.RuleManager.java
private Boolean doesRuleClash(BookingRule newBookingRule, Set<BookingRule> existingBookingRules) throws ParseException { logger.log("Determining if new rule clashes with existing rule."); // Get all existing rules that apply to the same day of the week... DayOfWeek newDay = dayOfWeekFromDate(newBookingRule.getBooking().getDate()); logger.log("New rule applies to day of the week: " + newDay); Set<BookingRule> sameDayRules = new HashSet<>(); for (BookingRule bookingRule : existingBookingRules) { if (dayOfWeekFromDate(bookingRule.getBooking().getDate()).equals(newDay)) { sameDayRules.add(bookingRule); }/* w w w . j av a2 s.com*/ } logger.log(sameDayRules.size() + " existing rules also apply to this day of the week"); // ..and all of those that overlap the same courttimeblock Set<BookingRule> sameDayOverlappingRules = new HashSet<>(); // Get court/time pairs for the new rule Set<ImmutablePair<Integer, Integer>> newBookedCourts = new HashSet<>(); addBookingRuleToSet(newBookingRule, newBookedCourts); for (BookingRule bookingRule : sameDayRules) { // Get court/times booked by existing rules for the same day as the new // rule Set<ImmutablePair<Integer, Integer>> bookedCourts = new HashSet<>(); addBookingRuleToSet(bookingRule, bookedCourts); if (Sets.intersection(newBookedCourts, bookedCourts).size() > 0) { sameDayOverlappingRules.add(bookingRule); } } logger.log(sameDayOverlappingRules.size() + " existing rules also apply to this day of the week and overlap the same Court/Time block"); // Remove any non-recurring rules with a date before the new rule starts - // they cannot possibly clash. Set<BookingRule> activeSameDayOverlappingRules = new HashSet<>(sameDayOverlappingRules); Date newDate = (new SimpleDateFormat("yyyy-MM-dd")).parse(newBookingRule.getBooking().getDate()); for (BookingRule bookingRule : sameDayOverlappingRules) { if ((!bookingRule.getIsRecurring()) && ((new SimpleDateFormat("yyyy-MM-dd")) .parse(bookingRule.getBooking().getDate()).before(newDate))) { logger.log("Removing same-day overlapping rule as it does not clash: " + bookingRule); activeSameDayOverlappingRules.remove(bookingRule); } } // If the new rule is recurring and any non-recurring existing rules are // left, then we have a clash, unless it has a relevant exclusion. N.B. We // need to allow exclusions at rule creation time to support backup/restore // functionality. if (newBookingRule.getIsRecurring()) { if (activeSameDayOverlappingRules.stream().anyMatch(rule -> (!rule.getIsRecurring() && !ArrayUtils.contains(newBookingRule.getDatesToExclude(), rule.getBooking().getDate())))) { // New rule have a relevant exclusion, so we have a clash. logger.log( "Clash as there's an existing clashing non-recurring rule and new rule is recurring without a relevant exclusion"); return true; } } else { // If the new rule is non-recurring and any non-recurring rules remain, // then we have a clash if both have the same date. if (activeSameDayOverlappingRules.stream() .anyMatch(rule -> (rule.getBooking().getDate().equals(newBookingRule.getBooking().getDate())) && (!rule.getIsRecurring()))) { logger.log( "Clash as new rule is non-recurring and there's an existing clashing non-recurring rule"); return true; } } // Finished with non-recurring existing rules - so ditch them. activeSameDayOverlappingRules.removeIf(rule -> !rule.getIsRecurring()); // If new rule is non-recurring, we have a clash if any existing recurring // rules start before it, unless they have a relevant exclusion. if (!newBookingRule.getIsRecurring()) { Date newBookingRuleDate = (new SimpleDateFormat("yyyy-MM-dd")) .parse(newBookingRule.getBooking().getDate()); for (BookingRule bookingRule : activeSameDayOverlappingRules) { if ((new SimpleDateFormat("yyyy-MM-dd")).parse(bookingRule.getBooking().getDate()) .before(newBookingRuleDate)) { // Does this rule have a relevant exclusion? if (ArrayUtils.contains(bookingRule.getDatesToExclude(), newBookingRule.getBooking().getDate())) { logger.log("Recurring rule does not clash as it has a matching rule exclusion: " + bookingRule.toString()); continue; } // We have a clash! logger.log( "Clash as new rule is non-recurring and there's an existing clashing recurring rule"); return true; } } } else { if (activeSameDayOverlappingRules.size() > 0) { // Always clash if both new and existing rules are recurring. logger.log("Clash as new rule is recurring and there's an existing clashing recurring rule"); return true; } } logger.log("No clash!"); return false; }
From source file:sx.blah.discord.api.internal.DispatchHandler.java
private void ready(ReadyResponse ready) { Discord4J.LOGGER.info(LogMarkers.WEBSOCKET, "Connected to Discord Gateway v{}. Receiving {} guilds.", ready.v, ready.guilds.length); ws.state = DiscordWS.State.READY; ws.hasReceivedReady = true; // Websocket received actual ready event if (client.ourUser == null) client.ourUser = DiscordUtils.getUserFromJSON(shard, ready.user); client.getDispatcher().dispatch(new LoginEvent(shard)); new RequestBuilder(client).setAsync(true).doAction(() -> { ws.sessionId = ready.session_id; Set<UnavailableGuildObject> waitingGuilds = ConcurrentHashMap.newKeySet(ready.guilds.length); waitingGuilds.addAll(Arrays.asList(ready.guilds)); final AtomicInteger loadedGuilds = new AtomicInteger(0); client.getDispatcher().waitFor((GuildCreateEvent e) -> { waitingGuilds.removeIf(g -> g.id.equals(e.getGuild().getStringID())); return loadedGuilds.incrementAndGet() >= ready.guilds.length; }, (long) Math.ceil(Math.sqrt(2 * ready.guilds.length)), TimeUnit.SECONDS); waitingGuilds.forEach(guild -> client.getDispatcher() .dispatch(new GuildUnavailableEvent(Long.parseUnsignedLong(guild.id)))); return true; }).andThen(() -> {//from w ww . j a v a 2s . c o m if (this.shard.getInfo()[0] == 0) { // pms are only sent to shard 0 for (ChannelObject pmObj : ready.private_channels) { IPrivateChannel pm = (IPrivateChannel) DiscordUtils.getChannelFromJSON(shard, null, pmObj); shard.privateChannels.put(pm); } } ws.isReady = true; client.getDispatcher().dispatch(new ShardReadyEvent(shard)); // All information for this shard has been received return true; }).execute(); }