List of usage examples for com.google.common.base Optional get
public abstract T get();
From source file:org.opennms.newts.rest.Transform.java
private static Map<String, String> unwrapMap(Optional<Map<String, String>> wrapped) { if (!wrapped.isPresent()) return Collections.<String, String>emptyMap(); return wrapped.get(); }
From source file:org.sonar.server.ws.WsUtils.java
/** * @throws NotFoundException if the value is not present * @return the value//from w w w .j a v a 2 s. c o m */ public static <T> T checkFoundWithOptional(Optional<T> value, String message, Object... messageArguments) { if (!value.isPresent()) { throw new NotFoundException(format(message, messageArguments)); } return value.get(); }
From source file:org.apache.gobblin.metrics.event.EventSubmitter.java
/** * Calls submit on submitter if present. *///ww w . java 2 s . c o m public static void submit(Optional<EventSubmitter> submitter, String name, Map<String, String> additionalMetadata) { if (submitter.isPresent()) { submitter.get().submit(name, additionalMetadata); } }
From source file:org.eclipse.buildship.core.workspace.internal.BuildCommandUpdater.java
private static Set<ICommand> toCommands(Optional<List<OmniEclipseBuildCommand>> buildCommands, IProjectDescription description) { Set<ICommand> commands = Sets.newLinkedHashSet(); if (buildCommands.isPresent()) { commands.addAll(toCommands(buildCommands.get(), description)); } else {//from w w w. java 2 s . c o m commands.addAll(Arrays.asList(description.getBuildSpec())); } commands.add(toCommand(description, GradleProjectBuilder.ID, Collections.<String, String>emptyMap())); return commands; }
From source file:net.caseif.flint.steel.util.helper.ChatHelper.java
public static boolean isSpectatorBarrierPresent(Player sender, Player recipient) { Optional<Challenger> senderCh = SteelCore.getChallenger(sender.getUniqueId()); Optional<Challenger> recipCh = SteelCore.getChallenger(recipient.getUniqueId()); if (senderCh.isPresent()) { if (senderCh.get().isSpectating() && senderCh.get().getRound().getConfigValue(ConfigNode.WITHHOLD_SPECTATOR_CHAT)) { return !(recipCh.isPresent() && recipCh.get().getRound() == senderCh.get().getRound() && recipCh.get().isSpectating()); }// w w w .jav a 2 s. co m } return false; }
From source file:org.opendaylight.groupbasedpolicy.neutron.ovsdb.util.EndpointHelper.java
/** * Look up the {@link Endpoint} from the Endpoint Registry. * * @param epKey The {@link EndpointKey} to look up * @param transaction The {@link ReadOnlyTransaction} * @return The corresponding {@link Endpoint}, null if not found *//*from ww w . j ava 2s . c o m*/ public static Endpoint lookupEndpoint(EndpointKey epKey, ReadOnlyTransaction transaction) { Optional<Endpoint> optionalEp = readFromDs(LogicalDatastoreType.OPERATIONAL, endpointIid(epKey.getL2Context(), epKey.getMacAddress()), transaction); if (optionalEp.isPresent()) { return optionalEp.get(); } return null; }
From source file:org.opendaylight.controller.md.sal.binding.impl.BindingStructuralType.java
static BindingStructuralType from(final DataTreeCandidateNode domChildNode) { final Optional<NormalizedNode<?, ?>> dataBased = domChildNode.getDataAfter() .or(domChildNode.getDataBefore()); if (dataBased.isPresent()) { return from(dataBased.get()); }/* w w w . j a v a 2 s . c o m*/ return from(domChildNode.getIdentifier()); }
From source file:org.apache.rya.indexing.pcj.fluo.app.query.StatementPatternIdManager.java
/** * Add specified Set of ids to the Fluo table with Column {@link FluoQueryColumns#STATEMENT_PATTERN_IDS}. Also * updates the hash of the updated nodeId Set and writes that to the Column * {@link FluoQueryColumns#STATEMENT_PATTERN_IDS_HASH} * * @param tx - Fluo Transaction object for performing atomic operations on Fluo table. * @param ids - ids to add to the StatementPattern nodeId Set *///from w ww .ja v a 2s .c o m public static void addStatementPatternIds(TransactionBase tx, Set<String> ids) { checkNotNull(tx); checkNotNull(ids); Optional<Bytes> val = Optional.fromNullable(tx.get(Bytes.of(STATEMENT_PATTERN_ID), STATEMENT_PATTERN_IDS)); StringBuilder builder = new StringBuilder(); if (val.isPresent()) { builder.append(val.get().toString()); builder.append(VAR_DELIM); } String idString = builder.append(Joiner.on(VAR_DELIM).join(ids)).toString(); tx.set(Bytes.of(STATEMENT_PATTERN_ID), STATEMENT_PATTERN_IDS, Bytes.of(idString)); tx.set(Bytes.of(STATEMENT_PATTERN_ID), STATEMENT_PATTERN_IDS_HASH, Bytes.of(Hashing.sha256().hashString(idString).toString())); }
From source file:de.azapps.mirakel.model.tags.Tag.java
@NonNull public static Tag newTag(final String name, final boolean dark, final int color) { final Optional<Tag> t = getByName(name); if (t.isPresent()) { return t.get(); }//from w ww.j a v a 2 s . c o m final ContentValues cv = new ContentValues(); cv.put(ModelBase.NAME, name); cv.put(DARK_TEXT, dark); cv.put(BACKGROUND_COLOR, color); final long id = insert(URI, cv); return get(id).get(); }
From source file:org.opendaylight.controller.md.sal.dom.store.impl.tree.data.StoreMetadataNode.java
public static Optional<UnsignedLong> getVersion(final Optional<StoreMetadataNode> currentMetadata) { if (currentMetadata.isPresent()) { return Optional.of(currentMetadata.get().getNodeVersion()); }//from w w w . j a va 2s . c o m return Optional.absent(); }