List of usage examples for com.google.common.base Optional isPresent
public abstract boolean isPresent();
From source file:org.blockartistry.mod.ThermalRecycling.support.recipe.accessor.IC2AccessorBase.java
private static ItemStack crackRecipeInputOreDict(final Object o) { final RecipeInputOreDict r = (RecipeInputOreDict) o; final Optional<ItemStack> opt = ItemStackHelper.getItemStack(r.input, r.amount); return opt.isPresent() ? opt.get() : null; }
From source file:module.organization.domain.groups.PersistentUnitGroup.java
static PersistentUnitGroup getInstance(final Unit unit, final Set<AccountabilityType> memberTypes, final Set<AccountabilityType> childUnitTypes) { Optional<PersistentUnitGroup> group = select(unit, memberTypes, childUnitTypes); return group.isPresent() ? group.get() : create(unit, memberTypes, childUnitTypes); }
From source file:org.icgc.dcc.release.job.join.task.CreateSgvObservation.java
public static Optional<Collection<ObjectNode>> convertConsequences( Optional<? extends Iterable<SgvConsequence>> consequences) { if (!consequences.isPresent()) { return Optional.absent(); }//from ww w . j av a2s . c o m val builder = ImmutableList.<ObjectNode>builder(); for (val consequence : consequences.get()) { val json = (ObjectNode) JacksonFactory.MAPPER.valueToTree(consequence); builder.add(trimConsequence(json)); } return Optional.of(builder.build()); }
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:module.organization.domain.groups.PersistentUnitGroup.java
@Atomic private static PersistentUnitGroup create(final Unit unit, final Set<AccountabilityType> memberTypes, final Set<AccountabilityType> childUnitTypes) { Optional<PersistentUnitGroup> group = select(unit, memberTypes, childUnitTypes); return group.isPresent() ? group.get() : new PersistentUnitGroup(unit, memberTypes, childUnitTypes); }
From source file:org.pshdl.model.types.builtIn.HDLGenerators.java
public static Optional<HDLInterface> getInterface(HDLDirectGeneration hdl) { final IHDLGenerator generator = generators.get(hdl.getGeneratorID()); if (generator != null) { final Optional<HDLInterface> hif = generator.getInterface(hdl); if (hif.isPresent()) return Optional.of(hif.get().copyDeepFrozen(hdl)); return hif; }//from w ww . ja v a 2s .c om return Optional.absent(); }
From source file:com.github.kevints.mesos.scheduler.server.LibprocessServletUtils.java
static Optional<PID> getSenderPid(HttpServletRequest req) { Optional<String> libprocessFrom = Optional.fromNullable(req.getHeader("X-Libprocess-From")); if (libprocessFrom.isPresent()) { try {//from w ww . j av a2 s .c o m return Optional.of(PID.fromString(libprocessFrom.get())); } catch (IllegalArgumentException e) { return Optional.absent(); } } Optional<String> userAgent = Optional.fromNullable(req.getHeader("User-Agent")); if (userAgent.isPresent()) { List<String> pid = Splitter.on("libprocess/").omitEmptyStrings().splitToList(userAgent.get()); if (pid.size() != 1) { return Optional.absent(); } else { try { return Optional.of(PID.fromString(pid.get(0))); } catch (IllegalArgumentException e) { return Optional.absent(); } } } return Optional.absent(); }
From source file:org.opendaylight.protocol.bgp.rib.impl.CheckUtil.java
public static <R, T extends DataObject> R readData(final DataBroker dataBroker, final InstanceIdentifier<T> iid, final Function<T, R> function) throws ReadFailedException { AssertionError lastError = null; final Stopwatch sw = Stopwatch.createStarted(); while (sw.elapsed(TimeUnit.SECONDS) <= TIMEOUT) { try (final ReadOnlyTransaction tx = dataBroker.newReadOnlyTransaction()) { final Optional<T> data = tx.read(LogicalDatastoreType.OPERATIONAL, iid).checkedGet(); if (data.isPresent()) { try { return function.apply(data.get()); } catch (final AssertionError e) { lastError = e;//from www. j av a 2s. c o m Uninterruptibles.sleepUninterruptibly(SLEEP_FOR, TimeUnit.MILLISECONDS); } } } } Assert.fail(lastError.getMessage()); throw lastError; }
From source file:org.onos.yangtools.yang.data.api.schema.tree.StoreTreeNodes.java
public static <T extends StoreTreeNode<T>> T findNodeChecked(final T tree, final YangInstanceIdentifier path) { T current = tree;/* w ww . j av a2 s .c o m*/ int i = 1; for (PathArgument pathArg : path.getPathArguments()) { Optional<T> potential = current.getChild(pathArg); if (!potential.isPresent()) { throw new IllegalArgumentException(String.format("Child %s is not present in tree.", Iterables.toString(Iterables.limit(path.getPathArguments(), i)))); } current = potential.get(); ++i; } return current; }
From source file:com.atlassian.jira.rest.client.api.domain.OperationGroup.java
static <T> Optional<T> accept(final Iterable<? extends Operation> operations, final OperationVisitor<T> visitor) { for (Operation operation : operations) { Optional<T> result = operation.accept(visitor); if (result.isPresent()) { return result; }/* ww w . j a va 2s .c o m*/ } return Optional.absent(); }