List of usage examples for java.util Optional ifPresent
public void ifPresent(Consumer<? super T> action)
From source file:org.codice.ddf.itests.common.cometd.CometDClient.java
/** * Un-subscribes from a channel. Un-subscribing from the same channel multiple has no effect. * * @param channel channel name//from ww w. j a v a 2 s .co m */ public void unsubscribe(String channel) { verifyConnected(); Optional<MessageListener> optionalMessageListener = messageListeners.stream() .filter(l -> l.getChannel().equals(channel)).findFirst(); optionalMessageListener.ifPresent((messageListener) -> { bayeuxClient.getChannel(channel).unsubscribe(messageListener); messageListeners.remove(messageListener); }); }
From source file:org.dita.dost.module.BranchFilterModule.java
static URI generateCopyTo(final URI href, final Branch filter) { final StringBuilder buf = new StringBuilder(href.toString()); final Optional<String> suffix = filter.resourceSuffix; suffix.ifPresent(s -> { final int sep = buf.lastIndexOf(URI_SEPARATOR); final int i = buf.lastIndexOf("."); if (i != -1 && (sep == -1 || i > sep)) { buf.insert(i, s);//from w w w. j av a2 s . c om } else { buf.append(s); } }); final Optional<String> prefix = filter.resourcePrefix; prefix.ifPresent(s -> { final int i = buf.lastIndexOf(URI_SEPARATOR); if (i != -1) { buf.insert(i + 1, s); } else { buf.insert(0, s); } }); return toURI(buf.toString()); }
From source file:org.haiku.haikudepotserver.pkg.PkgScreenshotServiceImpl.java
@Override public void deleteScreenshot(ObjectContext context, PkgScreenshot screenshot) { Pkg pkg = screenshot.getPkg();/* w w w . jav a 2 s . c om*/ String screenshotHashSha256 = screenshot.getHashSha256(); screenshot.setPkg(null); Optional<PkgScreenshotImage> image = screenshot.tryGetPkgScreenshotImage(); image.ifPresent(context::deleteObjects); context.deleteObjects(screenshot); for (Pkg subordinatePkg : pkgService.findSubordinatePkgsForMainPkg(context, pkg.getName())) { if (subordinatePkg.getName().endsWith(PkgService.SUFFIX_PKG_X86)) { List<PkgScreenshot> pkgScreenshotsToDelete = subordinatePkg.getPkgScreenshots().stream() .filter(ps -> ps.getHashSha256().equals(screenshotHashSha256)).collect(Collectors.toList()); for (PkgScreenshot pkgScreenshotToDelete : pkgScreenshotsToDelete) { deleteScreenshot(context, pkgScreenshotToDelete); } LOGGER.info("delete of screenshot was extended [{}] -> [{}]", pkg.getName(), subordinatePkg.getName()); } } }
From source file:org.haiku.haikudepotserver.pkg.PkgServiceImpl.java
/** * <p>For the given architecture and package, re-establish what is the latest package and correct it. * This may be necessary after, for example, adjusting the active flag on a pkg version.</p> * @return the updated latest package version or an empty option if there is none. *///from ww w. j a v a 2s . c om @Override public Optional<PkgVersion> adjustLatest(ObjectContext context, Pkg pkg, Architecture architecture) { Preconditions.checkArgument(null != context, "a context is required"); Preconditions.checkArgument(null != pkg, "the package must be supplied"); Preconditions.checkArgument(null != architecture, "the architecture must be supplied"); List<PkgVersion> pkgVersions = ObjectSelect.query(PkgVersion.class).where(PkgVersion.PKG.eq(pkg)) .and(PkgVersion.ARCHITECTURE.eq(architecture)).select(context); if (!pkgVersions.isEmpty()) { final VersionCoordinatesComparator comparator = new VersionCoordinatesComparator(); Optional<PkgVersion> pkgVersionOptional = pkgVersions.stream().filter(PkgVersion::getActive).sorted( (pv1, pv2) -> comparator.compare(pv2.toVersionCoordinates(), pv1.toVersionCoordinates())) .findFirst(); pkgVersionOptional.ifPresent(pv -> pv.setIsLatest(true)); for (PkgVersion pkgVersion : pkgVersions) { if (pkgVersion.getIsLatest() && (!pkgVersionOptional.isPresent() || !pkgVersion.equals(pkgVersionOptional.get()))) { pkgVersion.setIsLatest(false); } } return pkgVersionOptional; } return Optional.empty(); }
From source file:org.iobserve.analysis.behavior.models.data.BehaviorModelTable.java
@Override public void addInformation(final PayloadAwareEntryCallEvent event) { final String eventSignature = this.getSignatureFromEvent(event); final List<CallInformation> newCallInformations = new ArrayList<>(); try {/*from w w w . j a v a2 s. c o m*/ for (int i = 0; i < event.getParameters().length; i++) { newCallInformations.add(new CallInformation(event.getParameters()[i], String.valueOf( this.parameterValueDoubleMapper.mapValue(event.getParameters()[i], event.getValues()[i])))); } final List<AggregatedCallInformation> aggCallInformations = Arrays .asList(this.signatures.get(eventSignature).getSecond()); for (final CallInformation newCallInformation : newCallInformations) { // add new CallInfromation to the aggregation correctly final Optional<AggregatedCallInformation> match = aggCallInformations.stream() .filter(aggCallInformation -> aggCallInformation.belongsTo(newCallInformation)) .collect(new SingleOrNoneCollector<>()); match.ifPresent(aggCallInformation -> aggCallInformation.addCallInformation(newCallInformation)); } } catch (final IllegalArgumentException e) { BehaviorModelTable.LOGGER.error("Illegal argument exception", e); } }
From source file:org.jbb.members.impl.base.DefaultMemberService.java
@Override @Transactional//from w w w.j a va 2 s . co m public void updateProfile(Long memberId, ProfileDataToChange profileDataToChange) { Optional<DisplayedName> newDisplayedName = profileDataToChange.getDisplayedName(); newDisplayedName.ifPresent(displayedName -> updateDisplayedName(memberId, displayedName)); eventBus.post(new MemberProfileChangedEvent(memberId)); }
From source file:org.jbb.security.impl.lockout.DefaultMemberLockoutService.java
@Override @Transactional// w w w.j av a 2 s . co m public void releaseMemberLock(Long memberId) { Validate.notNull(memberId, MEMBER_VALIDATION_MESSAGE); log.debug("Clean all data from repositories {} and {} for member {}", MemberLockRepository.class.getName(), FailedSignInAttemptRepository.class.getName(), memberId); Optional<MemberLockEntity> userLockEntity = lockRepository.findByMemberIdAndActiveTrue(memberId); userLockEntity.ifPresent(entity -> { entity.setActive(false); entity.setDeactivationDate(LocalDateTime.now()); lockRepository.saveAndFlush(entity); log.debug("Account lock for member with ID {} is removed", memberId); eventBus.post(new MemberUnlockedEvent(memberId)); }); }
From source file:org.jboss.errai.ui.rebind.TemplatedCodeDecorator.java
/** * Possibly create an inner interface {@link ClientBundle} for the template's HTML or CSS resources. * @param customProvider// w ww .j av a2 s . co m * @param generateCssBundle */ private void generateTemplateResourceInterface(final Decorable decorable, final MetaClass type, final boolean customProvider, final Optional<String> cssPath) { final ClassDefinitionBuilderInterfaces<ClassStructureBuilderAbstractMethodOption> ifaceDef = ClassBuilder .define(getTemplateTypeName(type)).publicScope().interfaceDefinition(); if (!customProvider) { ifaceDef.implementsInterface(Template.class); } if (cssPath.isPresent()) { ifaceDef.implementsInterface(TemplateStyleSheet.class); } final ClassStructureBuilder<ClassStructureBuilderAbstractMethodOption> componentTemplateResource = ifaceDef .implementsInterface(ClientBundle.class).body(); if (!customProvider) { componentTemplateResource.publicMethod(TextResource.class, "getContents").annotatedWith(new Source() { @Override public Class<? extends Annotation> annotationType() { return Source.class; } @Override public String[] value() { return new String[] { getTemplateFileName(type) }; } }).finish(); } cssPath.ifPresent(path -> addCssResourceMethod(componentTemplateResource, path)); decorable.getFactoryMetaClass() .addInnerClass(new InnerClass(componentTemplateResource.getClassDefinition())); getConstructedTemplateTypes(decorable).put(type, componentTemplateResource.getClassDefinition()); }
From source file:org.jboss.prod.jardif.JarDif.java
private Map<Path, Path> common() { Map<Path, Path> resultMap = new HashMap<>(); List<Path> maven = mavenJars().stream().filter(skipNotImportant).map(Paths::get) .collect(Collectors.toList()); List<Path> gradle = gradleJars().stream().filter(skipNotImportant).map(Paths::get) .collect(Collectors.toList()); maven.forEach(m -> {/*from w w w .j a v a 2 s . com*/ Optional<Path> gradlePath = findCorrespondingGradle(gradle, m); gradlePath.ifPresent(p -> { resultMap.put(m, p); gradle.remove(p); }); }); if (!gradle.isEmpty()) { System.err.println("MISSING MAVEN JARS: " + gradle); } List<String> missingMaven = new ArrayList<>(); missingMaven.removeAll(resultMap.keySet()); if (!missingMaven.isEmpty()) { System.err.println("MISSING GRADLE JARS: " + gradle); } return resultMap; }
From source file:org.jboss.set.aphrodite.issue.trackers.bugzilla.IssueWrapper.java
private List<Map<String, Object>> getStageAndStreamsMap(Map<String, FlagStatus> streams, Map<Flag, FlagStatus> stateMap) { List<Map<String, Object>> flags = new ArrayList<>(); for (Map.Entry<String, FlagStatus> stream : streams.entrySet()) { Map<String, Object> flagMap = new HashMap<>(); flagMap.put(FLAG_NAME, stream.getKey()); flagMap.put(FLAG_STATUS, stream.getValue().getSymbol()); flags.add(flagMap);//from ww w . j a va 2 s. co m } for (Map.Entry<Flag, FlagStatus> entry : stateMap.entrySet()) { Map<String, Object> flagMap = new HashMap<>(); Optional<String> bzFlag = getBugzillaFlag(entry.getKey()); bzFlag.ifPresent(flagName -> { flagMap.put(FLAG_NAME, flagName); flagMap.put(FLAG_STATUS, entry.getValue().getSymbol()); flags.add(flagMap); }); } return flags; }