use of java.util.Objects in project cas by apereo.
the class SamlRegisteredServiceMetadataResolverCacheLoader method load.
@Override
@Synchronized
@SneakyThrows
public ChainingMetadataResolver load(final SamlRegisteredService service) {
final ChainingMetadataResolver metadataResolver = new ChainingMetadataResolver();
final List<MetadataResolver> metadataResolvers = new ArrayList<>();
final Collection<SamlRegisteredServiceMetadataResolver> availableResolvers = this.metadataResolutionPlan.getRegisteredMetadataResolvers();
availableResolvers.stream().filter(Objects::nonNull).filter(r -> r.supports(service)).map(r -> r.resolve(service)).forEach(metadataResolvers::addAll);
if (metadataResolvers.isEmpty()) {
throw new SamlException("No metadata resolvers could be configured for service " + service.getName() + " with metadata location " + service.getMetadataLocation());
}
metadataResolver.setId(ChainingMetadataResolver.class.getCanonicalName());
metadataResolver.setResolvers(metadataResolvers);
metadataResolver.initialize();
LOGGER.debug("Metadata resolvers active for this request are [{}]", metadataResolver);
return metadataResolver;
}
use of java.util.Objects in project cas by apereo.
the class CasServerProfileRegistrar method locateSubtypesByReflection.
private Object locateSubtypesByReflection(final Function<Class, Object> mapper, final Collector collector, final Class parentType, final Predicate filter, final String packageNamespace) {
final Reflections reflections = new Reflections(new ConfigurationBuilder().setUrls(ClasspathHelper.forPackage(packageNamespace)).setScanners(new SubTypesScanner(false)));
final Set<Class<?>> subTypes = (Set) reflections.getSubTypesOf(parentType);
return subTypes.stream().filter(c -> !Modifier.isInterface(c.getModifiers()) && !Modifier.isAbstract(c.getModifiers()) && filter.test(c)).map(mapper).filter(Objects::nonNull).collect(collector);
}
use of java.util.Objects in project MantaroBot by Mantaro.
the class MantaroShard method updateStatus.
/**
* Updates Mantaro's "splash".
* Splashes are random gags like "now seen in theaters!" that show on Mantaro's status.
* This has been on Mantaro since 2016, so it's part of its "personality" as a bot.
*/
public void updateStatus() {
Runnable changeStatus = () -> {
// insert $CURRENT_YEAR meme here
if (DateUtils.isSameDay(christmas, Calendar.getInstance())) {
getJDA().getPresence().setGame(Game.playing(String.format("%shelp | %s | [%d]", config().get().prefix[0], "Merry Christmas!", getId())));
return;
} else if (DateUtils.isSameDay(newYear, Calendar.getInstance())) {
getJDA().getPresence().setGame(Game.playing(String.format("%shelp | %s | [%d]", config().get().prefix[0], "Happy New Year!", getId())));
return;
}
AtomicInteger users = new AtomicInteger(0), guilds = new AtomicInteger(0);
if (MantaroBot.getInstance() != null) {
Arrays.stream(MantaroBot.getInstance().getShardedMantaro().getShards()).filter(Objects::nonNull).map(MantaroShard::getJDA).forEach(jda -> {
users.addAndGet((int) jda.getUserCache().size());
guilds.addAndGet((int) jda.getGuildCache().size());
});
}
String newStatus = new JSONObject(Utils.wgetResty(config.apiTwoUrl + "/mantaroapi/splashes/random", null)).getString("splash").replace("%ramgb%", String.valueOf(((long) (Runtime.getRuntime().maxMemory() * 1.2D)) >> 30L)).replace("%usercount%", users.toString()).replace("%guildcount%", guilds.toString()).replace("%shardcount%", String.valueOf(getTotalShards())).replace("%prettyusercount%", pretty(users.get())).replace("%prettyguildcount%", pretty(guilds.get()));
getJDA().getPresence().setGame(Game.playing(String.format("%shelp | %s | [%d]", config().get().prefix[0], newStatus, getId())));
log.debug("Changed status to: " + newStatus);
};
changeStatus.run();
Async.task("Splash Thread", changeStatus, 10, TimeUnit.MINUTES);
}
use of java.util.Objects in project cas by apereo.
the class BaseResourceU2FDeviceRepository method getRegisteredDevices.
@Override
public Collection<DeviceRegistration> getRegisteredDevices(final String username) {
try {
final Map<String, List<U2FDeviceRegistration>> devices = readDevicesFromResource();
if (!devices.isEmpty()) {
final List<U2FDeviceRegistration> devs = devices.get(MAP_KEY_SERVICES);
final LocalDate expirationDate = LocalDate.now().minus(this.expirationTime, DateTimeUtils.toChronoUnit(this.expirationTimeUnit));
LOGGER.debug("Filtering devices for [{}] based on device expiration date [{}]", username, expirationDate);
final List<U2FDeviceRegistration> list = devs.stream().filter(d -> d.getUsername().equals(username) && (d.getCreatedDate().isAfter(expirationDate))).collect(Collectors.toList());
LOGGER.debug("There are [{}] device(s) remaining in repository for [{}]", list.size(), username);
return list.stream().map(r -> {
try {
return DeviceRegistration.fromJson(r.getRecord());
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
}
return null;
}).filter(Objects::nonNull).collect(Collectors.toList());
}
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
}
return new ArrayList<>(0);
}
use of java.util.Objects in project AgriCraft by AgriCraft.
the class MutateStrategy method executeStrategy.
@Override
public Optional<AgriSeed> executeStrategy(IAgriCrop crop, Random rand) {
// Validate the parameters.
Objects.requireNonNull(crop, "You cannot execute a mutation on a null crop!");
Objects.requireNonNull(rand, "The random passed to a mutation strategy should not be null!");
// Fetch all neighboring crop instances.
final List<IAgriCrop> neighbors = WorldHelper.getTileNeighbors(crop.getCropWorld(), crop.getCropPos(), IAgriCrop.class);
// Determine all possible parents.
final List<IAgriPlant> parents = neighbors.stream().filter(IAgriCrop::isMature).map(IAgriCrop::getSeed).filter(Objects::nonNull).map(AgriSeed::getPlant).collect(Collectors.toList());
// If we have less than two parents, might as well as abort.
if (parents.size() < 2) {
return Optional.empty();
}
// Determine the list of possible cross-over mutations.
final List<IAgriMutation> mutations = AgriApi.getMutationRegistry().stream().filter(m -> m.areParentsIn(parents)).filter(m -> crop.isFertile(m.getChild())).collect(Collectors.toList());
// If we didn't find any valid mutations, might as well as abort.
if (mutations.isEmpty()) {
return Optional.empty();
}
// Choose a random index in the list.
final int index = rand.nextInt(mutations.size());
// Fetch the chosen mutation from the list.
final IAgriMutation mutation = mutations.get(index);
// Determine if we should actually go through with this.
if (mutation.getChance() <= rand.nextDouble()) {
return Optional.empty();
}
// Calculate the stat associated with the new plant.
Optional<IAgriStat> stat = AgriApi.getStatCalculatorRegistry().valueOf(mutation.getChild()).map(c -> c.calculateMutationStats(mutation, neighbors));
// Return the mutation result.
return stat.map(s -> new AgriSeed(mutation.getChild(), s));
}
Aggregations