List of usage examples for com.google.common.base Optional get
public abstract T get();
From source file:org.obm.push.mail.bean.Flag.java
public static Flag from(String value) { Optional<Flag> systemFlag = isSystemFlag(value); if (systemFlag.isPresent()) { return systemFlag.get(); }/*from www .j a v a2 s . c o m*/ return new Flag(value, false); }
From source file:de.azapps.tools.OptionalUtils.java
public static <T> void writeToParcel(final @NonNull Parcel dest, final @NonNull Optional<T> value) { dest.writeValue(value.isPresent());//w w w.ja v a2 s .com if (value.isPresent()) { dest.writeValue(value.get()); } }
From source file:auto.http.internal.codegen.SourceFileGenerationException.java
private static String createMessage(Optional<ClassName> generatedClassName, String message) { return String.format("Could not generate %s: %s.", generatedClassName.isPresent() ? generatedClassName.get() : "unknown file", message); }
From source file:org.opendaylight.controller.md.sal.dom.store.impl.tree.TreeNodeUtils.java
public static <T extends StoreTreeNode<T>> Optional<T> getChild(final Optional<T> parent, final PathArgument child) { if (parent.isPresent()) { return parent.get().getChild(child); }//from w w w.j a va 2 s . co m return Optional.absent(); }
From source file:com.github.filosganga.geogson.model.Matchers.java
public static <T> Matcher<Optional<? extends T>> optionalThatContain(final Matcher<? extends T> matcher) { return new TypeSafeMatcher<Optional<? extends T>>() { @Override/* ww w .j a v a2 s . co m*/ protected boolean matchesSafely(Optional<? extends T> item) { return item.isPresent() && matcher.matches(item.get()); } @Override public void describeTo(Description description) { description.appendText("Optional that contains ").appendDescriptionOf(matcher); } }; }
From source file:com.facebook.buck.apple.ApplePlatforms.java
public static AppleCxxPlatform getAppleCxxPlatformForBuildTarget( FlavorDomain<CxxPlatform> cxxPlatformFlavorDomain, CxxPlatform defaultCxxPlatform, ImmutableMap<Flavor, AppleCxxPlatform> platformFlavorsToAppleCxxPlatforms, BuildTarget target, Optional<FatBinaryInfo> fatBinaryInfo) { AppleCxxPlatform appleCxxPlatform;//from w w w . jav a 2 s .c o m if (fatBinaryInfo.isPresent()) { appleCxxPlatform = fatBinaryInfo.get().getRepresentativePlatform(); } else { CxxPlatform cxxPlatform = getCxxPlatformForBuildTarget(cxxPlatformFlavorDomain, defaultCxxPlatform, target); appleCxxPlatform = platformFlavorsToAppleCxxPlatforms.get(cxxPlatform.getFlavor()); if (appleCxxPlatform == null) { throw new HumanReadableException("%s: Apple bundle requires an Apple platform, found '%s'", target, cxxPlatform.getFlavor().getName()); } } return appleCxxPlatform; }
From source file:org.sonar.server.computation.task.projectanalysis.step.QualityProfileEventsStep.java
private static Map<String, QualityProfile> parseJsonData(Optional<Measure> measure) { String data = measure.get().getStringValue(); if (data == null) { return Collections.emptyMap(); }// ww w . jav a 2s . co m return QPMeasureData.fromJson(data).getProfilesByKey(); }
From source file:com.google.caliper.runner.PlatformModule.java
/** * Chooses the {@link DalvikPlatform} if available, otherwise uses the default * {@link JvmPlatform}./*from w w w . j a v a2s .c o m*/ */ @Provides static Platform providePlatform(Optional<DalvikPlatform> optionalDalvikPlatform, Provider<JvmPlatform> jvmPlatformProvider) { if (optionalDalvikPlatform.isPresent()) { return optionalDalvikPlatform.get(); } else { return jvmPlatformProvider.get(); } }
From source file:gobblin.http.HttpClientConfiguratorLoader.java
private static Class<? extends HttpClientConfigurator> getConfiguratorClass(Optional<String> configuratorType) throws ClassNotFoundException { return configuratorType.isPresent() ? TYPE_RESOLVER.resolveClass(configuratorType.get()) : DEFAULT_CONFIGURATOR_CLASS; }
From source file:net.pterodactylus.sonitus.io.Mp3Identifier.java
/** * Tries to identify the MP3 file contained in the given stream. * * @param inputStream//from w w w. j a va2 s . com * The input stream * @return The identified metadata, or {@link Optional#absent()} if the * metadata can not be identified * @throws IOException * if an I/O error occurs */ public static Optional<Metadata> identify(InputStream inputStream) throws IOException { Parser mp3Parser = new Parser(inputStream); Frame frame = mp3Parser.nextFrame(); FormatMetadata formatMetadata = new FormatMetadata((frame.channelMode() == SINGLE_CHANNEL) ? 1 : 2, frame.samplingRate(), "MP3"); ContentMetadata contentMetadata = new ContentMetadata(""); /* check for ID3v2 tag. */ Optional<byte[]> id3v2TagBuffer = mp3Parser.getId3Tag(); if (id3v2TagBuffer.isPresent()) { byte[] buffer = id3v2TagBuffer.get(); ByteArrayInputStream tagInputStream = new ByteArrayInputStream( Arrays.copyOfRange(buffer, 3, buffer.length)); try { /* skip ID3? header tag. */ ID3V2Tag id3v2Tag = ID3V2Tag.read(tagInputStream); if (id3v2Tag != null) { contentMetadata = contentMetadata.artist(id3v2Tag.getArtist()).name(id3v2Tag.getTitle()); } } catch (ID3Exception id3e1) { id3e1.printStackTrace(); } finally { close(tagInputStream, true); } } return Optional.of(new Metadata(formatMetadata, contentMetadata)); }