List of usage examples for com.google.common.base Optional isPresent
public abstract boolean isPresent();
From source file:org.eclipse.buildship.core.workspace.internal.JavaSourceSettingsUpdater.java
public static void update(IJavaProject project, OmniJavaSourceSettings sourceSettings, IProgressMonitor monitor) throws CoreException { SubMonitor progress = SubMonitor.convert(monitor, 1); String sourceVersion = sourceSettings.getSourceLanguageLevel().getName(); String targetVersion = sourceSettings.getTargetBytecodeLevel().getName(); File vmLocation = sourceSettings.getTargetRuntime().getHomeDirectory(); IVMInstall vm = EclipseVmUtil.findOrRegisterStandardVM(targetVersion, vmLocation); Optional<IExecutionEnvironment> executionEnvironment = EclipseVmUtil .findExecutionEnvironment(targetVersion); if (executionEnvironment.isPresent()) { addExecutionEnvironmentToClasspath(project, executionEnvironment.get(), progress.newChild(1)); } else {/*from w w w .j a v a2 s .c o m*/ addVmToClasspath(project, vm, progress.newChild(1)); } boolean compilerOptionChanged = false; compilerOptionChanged |= updateJavaProjectOptionIfNeeded(project, JavaCore.COMPILER_COMPLIANCE, sourceVersion); compilerOptionChanged |= updateJavaProjectOptionIfNeeded(project, JavaCore.COMPILER_SOURCE, sourceVersion); compilerOptionChanged |= updateJavaProjectOptionIfNeeded(project, JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, targetVersion); if (compilerOptionChanged && isProjectAutoBuildingEnabled()) { scheduleJdtBuild(project.getProject()); } }
From source file:org.opendaylight.controller.netconf.impl.SubtreeFilter.java
/** * Shallow compare src node to filter: tag name and namespace must match. * If filter node has no children and has text content, it also must match. *//*from w ww . java2 s . c o m*/ private static MatchingResult matches(XmlElement src, XmlElement filter) throws NetconfDocumentedException { boolean tagMatch = src.getName().equals(filter.getName()) && src.getNamespaceOptionally().equals(filter.getNamespaceOptionally()); MatchingResult result = null; if (tagMatch) { // match text content Optional<String> maybeText = filter.getOnlyTextContentOptionally(); if (maybeText.isPresent()) { if (maybeText.equals(src.getOnlyTextContentOptionally()) || prefixedContentMatches(filter, src)) { result = MatchingResult.CONTENT_MATCH; } else { result = MatchingResult.CONTENT_MISMATCH; } } // match attributes, combination of content and tag is not supported if (result == null) { for (Attr attr : filter.getAttributes().values()) { // ignore namespace declarations if (XmlUtil.XMLNS_URI.equals(attr.getNamespaceURI()) == false) { // find attr with matching localName(), namespaceURI(), == value() in src String found = src.getAttribute(attr.getLocalName(), attr.getNamespaceURI()); if (attr.getValue().equals(found) && result != MatchingResult.NO_MATCH) { result = MatchingResult.TAG_MATCH; } else { result = MatchingResult.NO_MATCH; } } } } if (result == null) { result = MatchingResult.TAG_MATCH; } } if (result == null) { result = MatchingResult.NO_MATCH; } LOG.debug("Matching {} to {} resulted in {}", src, filter, result); return result; }
From source file:org.anhonesteffort.flock.crypto.KeyHelper.java
public static Optional<MasterCipher> getMasterCipher(Context context) throws IOException { Optional<byte[]> cipherKeyBytes = KeyStore.getCipherKey(context); Optional<byte[]> macKeyBytes = KeyStore.getMacKey(context); if (!cipherKeyBytes.isPresent() || !macKeyBytes.isPresent()) return Optional.absent(); SecretKey cipherKey = new SecretKeySpec(cipherKeyBytes.get(), "AES"); SecretKey macKey = new SecretKeySpec(cipherKeyBytes.get(), "SHA256"); return Optional.of(new MasterCipher(cipherKey, macKey)); }
From source file:org.opendaylight.vtn.manager.internal.util.vnode.VTenantUtils.java
/** * Read the VTN specified by the given name. * * @param rtx A {@link ReadTransaction} instance associated with the * read transaction for the MD-SAL datastore. * @param vname A {@link VnodeName} instance that contains the name of * the VTN./*from w w w. jav a2s. c o m*/ * @return A {@link Vtn} instance. * @throws VTNException An error occurred. */ public static Vtn readVtn(ReadTransaction rtx, VnodeName vname) throws VTNException { InstanceIdentifier<Vtn> path = getIdentifier(vname); LogicalDatastoreType oper = LogicalDatastoreType.OPERATIONAL; Optional<Vtn> opt = DataStoreUtils.read(rtx, oper, path); if (!opt.isPresent()) { throw getNotFoundException(vname.getValue()); } return opt.get(); }
From source file:net.es.nsi.pce.pf.PfUtils.java
public static P2PServiceBaseType getP2PServiceBaseTypeOrFail(AttrConstraints constraints) { // Generic reservation information are in string constraint attributes, // but the P2PS specific constraints are in the P2PS P2PServiceBaseType. Optional<ObjectAttrConstraint> p2pObject = Optional .fromNullable(constraints.getObjectAttrConstraint(Point2PointTypes.P2PS)); if (p2pObject.isPresent()) { return p2pObject.get().getValue(P2PServiceBaseType.class); }/*from ww w.j a v a2s.co m*/ throw Exceptions.missingParameter(Point2PointTypes.P2PS, "null", "null"); }
From source file:org.apache.gobblin.hive.HiveSerDeWrapper.java
/** * Get an instance of {@link HiveSerDeWrapper}. * * @param serDeType The SerDe type. If serDeType is one of the available {@link HiveSerDeWrapper.BuiltInHiveSerDe}, * the other three parameters are not used. Otherwise, serDeType should be the class name of a {@link SerDe}, * and the other three parameters must be present. */// w ww . j a v a 2 s . c o m public static HiveSerDeWrapper get(String serDeType, Optional<String> inputFormatClassName, Optional<String> outputFormatClassName) { Optional<BuiltInHiveSerDe> hiveSerDe = Enums.getIfPresent(BuiltInHiveSerDe.class, serDeType.toUpperCase()); if (hiveSerDe.isPresent()) { return new HiveSerDeWrapper(hiveSerDe.get()); } Preconditions.checkArgument(inputFormatClassName.isPresent(), "Missing input format class name for SerDe " + serDeType); Preconditions.checkArgument(outputFormatClassName.isPresent(), "Missing output format class name for SerDe " + serDeType); return new HiveSerDeWrapper(serDeType, inputFormatClassName.get(), outputFormatClassName.get()); }
From source file:org.eclipse.buildship.core.workspace.internal.ProjectNameUpdater.java
private static boolean isScheduledForRenaming(IProject duplicate, Set<OmniEclipseProject> allProjects) { if (!duplicate.isOpen()) { return false; }//w ww . j ava 2 s . c om Optional<OmniEclipseProject> duplicateEclipseProject = Iterables.tryFind(allProjects, Predicates.eclipseProjectMatchesProjectDir(duplicate.getLocation().toFile())); if (!duplicateEclipseProject.isPresent()) { return false; } String newName = checkProjectName(duplicateEclipseProject.get()); return !newName.equals(duplicate.getName()); }
From source file:org.apache.brooklyn.entity.nosql.redis.RedisStoreImpl.java
/** * Create a {@link Function} to retrieve a particular field value from a {@code redis-cli info} * command./*w w w . j av a2s . c o m*/ * * @param field the info field to retrieve and convert * @return a new function that converts a {@link SshPollValue} to an {@link Integer} */ private static Function<SshPollValue, Integer> infoFunction(final String field) { return Functions.compose(new Function<String, Integer>() { @Override public Integer apply(@Nullable String input) { Optional<String> line = Iterables.tryFind(Splitter.on('\n').split(input), Predicates.containsPattern(field + ":")); if (line.isPresent()) { String data = line.get().trim(); int colon = data.indexOf(":"); return Integer.parseInt(data.substring(colon + 1)); } else { throw new IllegalStateException("Data for field " + field + " not found: " + input); } } }, SshValueFunctions.stdout()); }
From source file:dagger2.internal.codegen.Util.java
/** * Unwraps an {@link Optional} of a {@link Wrapper} into an {@code Optional} of the underlying * type./*from w ww . ja v a 2 s . co m*/ */ static <T> Optional<T> unwrapOptionalEquivalence(Optional<Equivalence.Wrapper<T>> wrappedOptional) { return wrappedOptional.isPresent() ? Optional.of(wrappedOptional.get().get()) : Optional.<T>absent(); }
From source file:com.facebook.buck.cxx.CxxPreprocessorFlags.java
/** * Converts from CxxConstructorArg.preprocessorFlags and * CxxConstructorArg.langPreprocessorFlags to the multimap * of (source type: [flag, flag2, ...]) pairs. * * If the list version of the arg is present, fills every source * type with the list's value./*w w w . j a v a 2s.c o m*/ * * Otherwise, converts the map version of the arg to a multimap. */ public static ImmutableMultimap<CxxSource.Type, String> fromArgs(Optional<ImmutableList<String>> defaultFlags, Optional<ImmutableMap<CxxSource.Type, ImmutableList<String>>> perLanguageFlags) { ImmutableMultimap.Builder<CxxSource.Type, String> result = ImmutableMultimap.builder(); if (defaultFlags.isPresent()) { for (CxxSource.Type type : CxxSource.Type.values()) { result.putAll(type, defaultFlags.get()); } } if (perLanguageFlags.isPresent()) { for (ImmutableMap.Entry<CxxSource.Type, ImmutableList<String>> entry : perLanguageFlags.get() .entrySet()) { result.putAll(entry.getKey(), entry.getValue()); } } return result.build(); }