List of usage examples for com.google.common.base Optional get
public abstract T get();
From source file:org.killbill.billing.plugin.cielo.api.CieloPaymentTransactionInfoPlugin.java
private static PaymentPluginStatus getPaymentPluginStatus(final Optional<PaymentServiceProviderResult> result) { return (result.isPresent()) ? resultToPaymentPluginStatus(result.get()) : cieloCallErrorStatusToPaymentPluginStatus(CieloCallErrorStatus.UNKNOWN_FAILURE); }
From source file:com.viadeo.kasper.common.tools.ReflectionGenericsResolver.java
/** * Can be used to analyze a field, taking into account the generic parameters of the specified declaring type * * @param runtimeField the runtime field to be analyzed * @param declaringType the declaring type to take into account for generic parameters analysis * @param targetType the target type to resolve the runtimeType against * @param nbParameter the generic parameter position on the targetType * * @return the (optional) type of the resolved parameter at specific position *///w w w . j a v a 2 s. com @SuppressWarnings("rawtypes") public static Optional<? extends Class> getParameterTypeFromClass(final Field runtimeField, final Type declaringType, final Type targetType, final Integer nbParameter) { final Map<Type, Type> bindings = Maps.newHashMap(); fillBindingsFromClass(declaringType, bindings); Optional<Class> clazz = getClass(declaringType); while (clazz.isPresent()) { final Type parent = clazz.get().getGenericSuperclass(); fillBindingsFromClass(parent, bindings); clazz = getClass(parent); } // Boot recursive process with an empty bindings maps return getParameterTypeFromClass(runtimeField.getGenericType(), targetType, nbParameter, bindings); }
From source file:org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodes.java
public static Optional<NormalizedNode<?, ?>> findNode(final Optional<NormalizedNode<?, ?>> parent, final Iterable<PathArgument> relativePath) { checkNotNull(parent, "Parent must not be null"); checkNotNull(relativePath, "Relative path must not be null"); Optional<NormalizedNode<?, ?>> currentNode = parent; final Iterator<PathArgument> pathIterator = relativePath.iterator(); while (currentNode.isPresent() && pathIterator.hasNext()) { currentNode = getDirectChild(currentNode.get(), pathIterator.next()); }/*from w w w . ja v a 2 s .co m*/ return currentNode; }
From source file:net.pterodactylus.sonitus.io.OggVorbisIdentifier.java
/** * Tries to parse the given stream as Ogg Vorbis file and returns a {@link * Metadata} describing the stream./*from w w w. j a v a 2 s . c o m*/ * * @param inputStream * The input stream to identify as Ogg Vorbis * @return The identified metadata, or {@link Optional#absent()} if the stream * could not be identified * @throws IOException * if an I/O error occurs */ public static Optional<Metadata> identify(InputStream inputStream) throws IOException { /* stuff needed to decode Ogg. */ Packet packet = new Packet(); Page page = new Page(); StreamState streamState = new StreamState(); SyncState syncState = new SyncState(); /* stuff needed to decode Vorbis. */ Comment comment = new Comment(); Info info = new Info(); /* initialize jorbis. */ syncState.init(); int bufferSize = BUFFER_SIZE; int index = syncState.buffer(bufferSize); byte[] buffer = syncState.data; boolean streamStateInitialized = false; int packetsRead = 0; /* read until we have read the three packets required to decode the header. */ while (packetsRead < 3) { int read = inputStream.read(buffer, index, bufferSize); syncState.wrote(read); switch (syncState.pageout(page)) { case -1: return Optional.absent(); case 1: if (!streamStateInitialized) { /* init stream state. */ streamState.init(page.serialno()); streamState.reset(); info.init(); comment.init(); streamStateInitialized = true; } if (streamState.pagein(page) == -1) { return Optional.absent(); } switch (streamState.packetout(packet)) { case -1: return Optional.absent(); case 1: info.synthesis_headerin(comment, packet); packetsRead++; default: /* continue. */ } default: /* continue. */ } index = syncState.buffer(bufferSize); buffer = syncState.data; } FormatMetadata formatMetadata = new FormatMetadata(info.channels, info.rate, "Vorbis"); ContentMetadata contentMetadata = new ContentMetadata(""); for (int c = 0; c < comment.comments; ++c) { String field = comment.getComment(c); Optional<String> extractedField = extractField(field, "ARTIST"); if (extractedField.isPresent()) { contentMetadata = contentMetadata.artist(extractedField.get()); continue; } extractedField = extractField(field, "TITLE"); if (extractedField.isPresent()) { contentMetadata = contentMetadata.name(extractedField.get()); continue; } } return Optional.of(new Metadata(formatMetadata, contentMetadata)); }
From source file:org.blockartistry.mod.ThermalRecycling.support.recipe.AppendHelper.java
public static void append(final List<ItemStack> list, final String... items) { assert list != null; assert items != null && items.length > 0; for (final String s : items) { final Optional<ItemStack> stack = ItemStackHelper.getItemStack(s); if (stack.isPresent()) list.add(stack.get()); }//from ww w . j a va2 s.c om }
From source file:jcomposition.processor.utils.AnnotationUtils.java
public static String getCompositionName(TypeElement element, ProcessingEnvironment env) { Optional<AnnotationValue> value = getParameterFrom(element, Composition.class, "name", env); String defaultName = element.getSimpleName() + "_Generated"; if (value.isPresent()) { String name = (String) value.get().getValue(); if (!Const.UNDEFINED.equals(name)) { return name; }// w w w.ja v a 2 s . co m } return defaultName; }
From source file:com.facebook.buck.cli.Command.java
/** * @return a non-empty {@link Optional} if {@code name} corresponds to a * command or its levenshtein distance to the closest command isn't larger * than {@link #MAX_ERROR_RATIO} * length_of_closest_command; otherwise, an * empty {@link Optional}. This will return the latter if the user tries * to run something like {@code buck --help}. *//*w w w . j a v a 2s .co m*/ public static ParseResult parseCommandName(String name) { Preconditions.checkNotNull(name); Command command = null; String errorText = null; try { command = valueOf(name.toUpperCase()); } catch (IllegalArgumentException e) { Optional<Command> fuzzyCommand = fuzzyMatch(name.toUpperCase()); if (fuzzyCommand.isPresent()) { errorText = String.format("(Cannot find command '%s', assuming command '%s'.)\n", name, fuzzyCommand.get().name().toLowerCase()); command = fuzzyCommand.get(); } } return new ParseResult(Optional.fromNullable(command), Optional.fromNullable(errorText)); }
From source file:org.eclipse.buildship.core.workspace.internal.EclipseVmUtil.java
private static Optional<IVMInstall> findRegisteredVM(String version) { Optional<IExecutionEnvironment> possibleExecutionEnvironment = findExecutionEnvironment(version); if (!possibleExecutionEnvironment.isPresent()) { return Optional.absent(); }//from w ww . j a va 2 s . c o m IExecutionEnvironment executionEnvironment = possibleExecutionEnvironment.get(); IVMInstall defaultVm = executionEnvironment.getDefaultVM(); if (defaultVm != null) { return Optional.of(defaultVm); } else { IVMInstall firstVm = Iterables.getFirst(Arrays.asList(executionEnvironment.getCompatibleVMs()), null); return Optional.fromNullable(firstVm); } }
From source file:org.opendaylight.protocol.bgp.labeled.unicast.AbstractLabeledUnicastRIBSupport.java
public static List<LabelStack> extractLabel(final DataContainerNode<? extends PathArgument> route, final NodeIdentifier labelStackNid, final NodeIdentifier labelValueNid) { final List<LabelStack> labels = new ArrayList<>(); final Optional<DataContainerChild<? extends PathArgument, ?>> labelStacks = route.getChild(labelStackNid); if (labelStacks.isPresent()) { for (final UnkeyedListEntryNode label : ((UnkeyedListNode) labelStacks.get()).getValue()) { final Optional<DataContainerChild<? extends PathArgument, ?>> labelStack = label .getChild(labelValueNid); if (labelStack.isPresent()) { final LabelStackBuilder labelStackbuilder = new LabelStackBuilder(); labelStackbuilder.setLabelValue(new MplsLabel((Long) labelStack.get().getValue())); labels.add(labelStackbuilder.build()); }/*from w w w .j ava 2 s . c o m*/ } } return labels; }
From source file:org.eclipse.recommenders.utils.rcp.ast.BindingUtils.java
public static List<ITypeName> toTypeNames(final ITypeBinding[] interfaces) { final List<ITypeName> res = Lists.newLinkedList(); for (final ITypeBinding b : interfaces) { final Optional<ITypeName> opt = toTypeName(b); if (opt.isPresent()) { res.add(opt.get()); }//from w w w .j av a 2 s. c o m } return res; }