List of usage examples for com.google.common.base Optional of
public static <T> Optional<T> of(T reference)
From source file:de.Keyle.MyPet.util.UpdateCheck.java
public static Optional<String> checkForUpdate(String plugin) { try {/*w ww. j ava 2s.c o m*/ String parameter = ""; parameter += "&package=" + MyPetApi.getCompatUtil().getInternalVersion(); parameter += "&build=" + MyPetVersion.getBuild(); // no data will be saved on the server String content = Util.readUrlContent("http://update.mypet-plugin.de/" + plugin + "?" + parameter); JSONParser parser = new JSONParser(); JSONObject result = (JSONObject) parser.parse(content); if (result.containsKey("latest")) { latest = result.get("latest").toString(); return Optional.of(latest); } } catch (Exception ignored) { } return Optional.absent(); }
From source file:org.mayocat.addons.util.AddonUtils.java
/** * Finds a addon group definition in a list of group definitions. The priority of the group definitions is order in * which they are passed : first passed has the highest priority, last passed the lowest. * * @param name the name of the addon group definition to find * @param groupDefinitions the list of group definitions * @return the first definition found, or absent if none is found *///w ww . ja va2 s . c o m public static Optional<AddonGroupDefinition> findAddonGroupDefinition(String name, Map<String, AddonGroupDefinition>... groupDefinitions) { for (Map<String, AddonGroupDefinition> groupDefinition : groupDefinitions) { if (groupDefinition.containsKey(name)) { return Optional.of(groupDefinition.get(name)); } } return Optional.absent(); }
From source file:org.gradle.model.internal.core.NodeInitializerContext.java
public static NodeInitializerContext forProperty(ModelType<?> modelType, ModelProperty<?> modelProperty, ModelType<?> containingType) { return new NodeInitializerContext(modelType, Optional.<ModelProperty<?>>of(modelProperty), Optional.of(containingType)); }
From source file:com.facebook.buck.apple.AppleInfoPlistParsing.java
/** * Extracts the bundle ID (CFBundleIdentifier) from an Info.plist, returning it if present. *///from w ww . j a v a2s .c o m public static Optional<String> getBundleIdFromPlistStream(InputStream inputStream) throws IOException { NSDictionary infoPlist; try (BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream)) { try { infoPlist = (NSDictionary) PropertyListParser.parse(bufferedInputStream); } catch (Exception e) { throw new IOException(e); } } NSObject bundleId = infoPlist.objectForKey("CFBundleIdentifier"); if (bundleId == null) { return Optional.absent(); } else { return Optional.of(bundleId.toString()); } }
From source file:org.locationtech.geogig.hooks.Hookables.java
/** * Returns the filename to be used for a script corresponding to the hook for a given GeoGig * operation. Returns {@link Optional.absent} if the specified operation does not allows hooks * /*from w ww . j a v a 2 s . c o m*/ * @param class the operation * @return the string to be used as filename for storing the script files for the corresponding * hook */ public static Optional<String> getFilename(Class<? extends AbstractGeoGigOp<?>> clazz) { Hookable annotation = clazz.getAnnotation(Hookable.class); if (annotation != null) { return Optional.of(annotation.name()); } else { return Optional.absent(); } }
From source file:google.registry.request.auth.UserAuthInfo.java
static UserAuthInfo create(User user, boolean isUserAdmin, OAuthTokenInfo oauthTokenInfo) { return new AutoValue_UserAuthInfo(user, isUserAdmin, Optional.of(oauthTokenInfo)); }
From source file:com.complexible.common.base.Reflect.java
/** * Returns the class with the given name. A ClassNotFoundException will not be thrown if * the class does not exist, an {@link com.google.common.base.Optional} with an absent value will be returned instead. * Similarly, if a ClassCastException is thrown, because the class name is valid, but is * not of the correct type of class requested by the user, an Optional without a value will be returned.. * * @param theClassName the class name// w ww. j ava2 s .c o m * @return the class, or null if it does not exist */ public static <T> Optional<Class<T>> getClass(final String theClassName) { try { return Optional.of((Class<T>) Class.forName(theClassName)); } catch (ClassNotFoundException e) { return Optional.absent(); } catch (ClassCastException e) { return Optional.absent(); } }
From source file:com.google.cloud.genomics.localrepo.VcfFile.java
public static Optional<VcfFile> create(File file) { return isReadableFile(file) && file.getName().endsWith(".vcf") ? Optional.of(new VcfFile(file)) : Optional.<VcfFile>absent(); }
From source file:gobblin.data.management.copy.watermark.CopyableFileWatermarkHelper.java
/** * Get Optional {@link CopyableFileWatermarkGenerator} from {@link State}. *//*from w ww. java2s .c om*/ public static Optional<CopyableFileWatermarkGenerator> getCopyableFileWatermarkGenerator(State state) throws IOException { try { if (state.contains(WATERMARK_CREATOR)) { Class<?> watermarkCreatorClass = Class.forName(state.getProp(WATERMARK_CREATOR)); return Optional.of((CopyableFileWatermarkGenerator) watermarkCreatorClass.newInstance()); } else { return Optional.absent(); } } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { throw new IOException("Failed to instantiate watermarkCreator."); } }
From source file:de.flapdoodle.logparser.matcher.stacktrace.AbstractStackElement.java
protected static <T> Optional<T> match(CharSequence input, Pattern pattern, IStackElementFactory<T> factory) { Optional<Map<String, String>> m = Patterns.match(pattern.matcher(input)); if (m.isPresent()) { return Optional.of(factory.newInstance(input.toString(), m.get())); }// w ww .jav a 2 s . co m return Optional.absent(); }