List of usage examples for com.google.common.base Optional of
public static <T> Optional<T> of(T reference)
From source file:com.empcraft.xpbank.util.ChunkUtil.java
public static Optional<Chunk> getLoadedChunk(World world, Location loc) { Preconditions.checkNotNull(loc);/*w w w . j av a2 s . c om*/ Optional<Chunk> loadedChunk = Optional.absent(); final Chunk chunkAt = world.getChunkAt(loc); if (chunkAt.isLoaded()) { loadedChunk = Optional.of(chunkAt); } return loadedChunk; }
From source file:org.apache.beam.sdk.extensions.sql.impl.utils.SqlTypeUtils.java
/** * Finds an operand with provided type. Returns Optional.absent() if no operand found with * matching type/* www . ja v a 2 s. c om*/ */ public static Optional<BeamSqlExpression> findExpressionOfType(List<BeamSqlExpression> operands, SqlTypeName type) { for (BeamSqlExpression operand : operands) { if (type.equals(operand.getOutputType())) { return Optional.of(operand); } } return Optional.absent(); }
From source file:com.kegare.frozenland.util.Version.java
private static void initialize() { CURRENT = Optional.of(Strings.nullToEmpty(Frozenland.metadata.version)); LATEST = Optional.fromNullable(CURRENT.orNull()); File file = FrozenUtils.getModContainer().getSource(); if (file != null && file.exists()) { if (file.isFile()) { String name = FilenameUtils.getBaseName(file.getName()); if (StringUtils.endsWithIgnoreCase(name, "dev")) { DEV_DEBUG = true;/* w w w.j a v a 2 s. c om*/ } } else if (file.isDirectory()) { DEV_DEBUG = true; } } else if (!FMLForgePlugin.RUNTIME_DEOBF) { DEV_DEBUG = true; } if (Frozenland.metadata.version.endsWith("dev")) { DEV_DEBUG = true; } else if (DEV_DEBUG) { Frozenland.metadata.version += "-dev"; } }
From source file:org.dswarm.graph.delta.match.model.util.CSEntityUtil.java
public static Optional<? extends Collection<ValueEntity>> getValueEntities( final Optional<? extends Collection<CSEntity>> csEntities) { if (!csEntities.isPresent() || csEntities.get().isEmpty()) { return Optional.absent(); }/* www.j a v a 2s. c om*/ final Set<ValueEntity> valueEntities = new HashSet<>(); for (final CSEntity csEntity : csEntities.get()) { valueEntities.addAll(csEntity.getValueEntities()); } return Optional.of(valueEntities); }
From source file:com.facebook.presto.block.BlockUtils.java
public static BlockIterable emptyBlockIterable() { return new BlockIterable() { @Override//from ww w . j a v a 2s . c om public TupleInfo getTupleInfo() { return TupleInfo.SINGLE_LONG; } @Override public Optional<DataSize> getDataSize() { return Optional.of(new DataSize(0, Unit.BYTE)); } @Override public Optional<Integer> getPositionCount() { return Optional.of(0); } @Override public Iterator<Block> iterator() { return Iterators.emptyIterator(); } }; }
From source file:org.geogit.di.PluginDefaults.java
public PluginDefaults(VersionedFormat objects, VersionedFormat staging, VersionedFormat refs, VersionedFormat graph) {//from w w w . j av a 2 s . c om this.refs = Optional.of(refs); this.objects = Optional.of(objects); this.staging = Optional.of(staging); this.graph = Optional.of(graph); }
From source file:gobblin.metrics.MetricReportUtils.java
/** * Parses a {@link gobblin.metrics.MetricReport} from a byte array representing a json input. * @param reuse MetricReport to reuse.//from w ww . j a v a 2 s.com * @param bytes Input bytes. * @return MetricReport. * @throws java.io.IOException */ public synchronized static MetricReport deserializeReportFromJson(MetricReport reuse, byte[] bytes) throws IOException { if (!READER.isPresent()) { READER = Optional.of(new SpecificDatumReader<MetricReport>(MetricReport.class)); } Closer closer = Closer.create(); try { DataInputStream inputStream = closer.register(new DataInputStream(new ByteArrayInputStream(bytes))); // Check version byte int versionNumber = inputStream.readInt(); if (versionNumber != SCHEMA_VERSION) { throw new IOException( String.format("MetricReport schema version not recognized. Found version %d, expected %d.", versionNumber, SCHEMA_VERSION)); } // Decode the rest Decoder decoder = DecoderFactory.get().jsonDecoder(MetricReport.SCHEMA$, inputStream); return READER.get().read(reuse, decoder); } catch (Throwable t) { throw closer.rethrow(t); } finally { closer.close(); } }
From source file:org.opendaylight.yangtools.yang.data.api.schema.tree.StoreTreeNodes.java
/** * Finds a node in tree//from www . jav a 2 s . c om * @param <T> * Store tree node type. * @param tree Data Tree * @param path Path to the node * @return Optional with node if the node is present in tree, {@link Optional#absent()} otherwise. */ public static <T extends StoreTreeNode<T>> Optional<T> findNode(final T tree, final YangInstanceIdentifier path) { Optional<T> current = Optional.of(tree); Iterator<PathArgument> pathIter = path.getPathArguments().iterator(); while (current.isPresent() && pathIter.hasNext()) { current = current.get().getChild(pathIter.next()); } return current; }
From source file:org.apache.james.mailbox.store.FakeAuthorizator.java
public static FakeAuthorizator forUserAndAdmin(String admin, String user) { return new FakeAuthorizator(Optional.of(admin), Optional.of(user)); }
From source file:org.basepom.mojo.propertyhelper.PropertyField.java
public static List<PropertyElement> createProperties(final Model model, final Map<String, String> values, final PropertyGroup propertyGroup) throws IOException, InterpolationException { checkNotNull(model, "model is null"); checkNotNull(values, "values is null"); checkNotNull(propertyGroup, "propertyGroup is null"); final InterpolatorFactory interpolatorFactory = new InterpolatorFactory(Optional.of(model)); final ImmutableList.Builder<PropertyElement> result = ImmutableList.builder(); final Map<String, String> properties = propertyGroup.getProperties(); for (String name : properties.keySet()) { final String value = propertyGroup.getPropertyValue(interpolatorFactory, name, values); result.add(new PropertyField(name, value)); }/*from www .ja va 2 s . c o m*/ return result.build(); }