List of usage examples for com.google.common.base Optional of
public static <T> Optional<T> of(T reference)
From source file:org.eclipse.buildship.core.util.file.FileUtils.java
/** * Derives a {@code File} instance with absolute path from the specified path. * * @param path the relative or absolute path of the {@code File} instance to derive * @return the absolute {@code File} if the path is not {@code null} or empty, otherwise * {@link Optional#absent()}/*from ww w. j a v a2s .com*/ */ public static Optional<File> getAbsoluteFile(String path) { if (Strings.isNullOrEmpty(path)) { return Optional.absent(); } else { return Optional.of(new File(path.trim()).getAbsoluteFile()); } }
From source file:org.verdictdb.core.querying.SubscriptionTicket.java
public SubscriptionTicket(ExecutableNodeBase subscriber, int channel) { this.subscriber = subscriber; this.channel = Optional.of(channel); }
From source file:org.sonar.server.permission.ws.ProjectWsRef.java
public static Optional<ProjectWsRef> newOptionalWsProjectRef(@Nullable String uuid, @Nullable String key) { if (uuid == null && key == null) { return Optional.absent(); }/*from w ww .j av a2 s . c om*/ return Optional.of(new ProjectWsRef(uuid, key)); }
From source file:org.immutables.fixture.OptionalCast.java
@SuppressWarnings("CheckReturnValue") default void use() { ImmutableOptionalCast.of(Optional.absent(), Optional.of("String is object"), Optional.<String[]>absent(), Optional.absent());//from w w w. j av a 2 s . c o m }
From source file:org.apache.beam.sdk.extensions.sql.impl.utils.SqlTypeUtils.java
/** * Finds an operand with the type in typesToFind. Returns Optional.absent() if no operand found * with matching type/*from w w w . j a v a 2 s .c o m*/ */ public static Optional<BeamSqlExpression> findExpressionOfType(List<BeamSqlExpression> operands, Collection<SqlTypeName> typesToFind) { for (BeamSqlExpression operand : operands) { if (typesToFind.contains(operand.getOutputType())) { return Optional.of(operand); } } return Optional.absent(); }
From source file:com.google.devtools.build.xcode.zippingoutput.ArgumentsParsing.java
/** * @param args raw arguments passed to wrapper tool through the {@code main} method * @param subtoolName name of the subtool, such as "actool" * @return an instance based on results of parsing the given arguments. *//*from w w w .j a v a 2s. c o m*/ public static ArgumentsParsing parse(FileSystem fileSystem, String[] args, String wrapperName, String subtoolName) { String capitalizedSubtool = subtoolName.toUpperCase(Locale.US); if (args.length < MIN_ARGS) { return new ArgumentsParsing(Optional.of(String.format( "Expected at least %1$d args.\n" + "Usage: java %2$s OUTZIP ARCHIVEROOT (%3$s_CMD %3$s ARGS)\n" + "Runs %4$s and zips the results.\n" + "OUTZIP - the path to place the output zip file.\n" + "ARCHIVEROOT - the path in the zip to place the output, or an empty\n" + " string for the root of the zip. e.g. 'Payload/foo.app'. If\n" + " this tool outputs a single file, ARCHIVEROOT is the name of\n" + " the only file in the zip file.\n" + "%3$s_CMD - path to the subtool.\n" + " e.g. /Applications/Xcode.app/Contents/Developer/usr/bin/actool\n" + "%3$s ARGS - the arguments to pass to %4$s besides the\n" + " one that specifies the output directory.\n", MIN_ARGS, wrapperName, capitalizedSubtool, subtoolName)), Optional.<Arguments>absent()); } String outputZip = args[0]; String archiveRoot = args[1]; String subtoolCmd = args[2]; if (archiveRoot.startsWith("/")) { return new ArgumentsParsing( Optional.of(String.format("Archive root cannot start with /: '%s'\n", archiveRoot)), Optional.<Arguments>absent()); } // TODO(bazel-team): Remove this hack when the released version of Bazel uses the correct momc // path for device builds. subtoolCmd = subtoolCmd.replace("/iPhoneOS.platform/", "/iPhoneSimulator.platform/"); if (!Files.isRegularFile(fileSystem.getPath(subtoolCmd))) { return new ArgumentsParsing(Optional .of(String.format("The given %s_CMD does not exist: '%s'\n", capitalizedSubtool, subtoolCmd)), Optional.<Arguments>absent()); } return new ArgumentsParsing(Optional.<String>absent(), Optional.<Arguments>of(new Arguments(outputZip, archiveRoot, subtoolCmd, ImmutableList.copyOf(args).subList(MIN_ARGS, args.length)))); }
From source file:com.siemens.sw360.portal.common.datatables.data.DataTablesColumn.java
public DataTablesColumn(DataTablesSearch search) { this.search = Optional.of(search); }
From source file:org.jtwig.functions.parameters.resolve.HttpRequestParameterResolver.java
@Override public Optional<Value> resolve(JavaMethodParameter parameter) { if (parameter.type().isAssignableFrom(HttpServletRequest.class)) return Optional.of(new Value(LocalThreadHolder.getServletRequest())); return Optional.absent(); }
From source file:org.opendaylight.genius.interfacemanager.renderer.ovs.confighelpers.OvsVlanMemberConfigAddHelper.java
public static List<ListenableFuture<Void>> addConfiguration(DataBroker dataBroker, ParentRefs parentRefs, Interface interfaceNew, IfL2vlan ifL2vlan, IdManagerService idManager) { LOG.debug("add vlan member configuration {}", interfaceNew.getName()); List<ListenableFuture<Void>> futures = new ArrayList<>(); WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction(); InterfaceManagerCommonUtils.createInterfaceChildEntry(parentRefs.getParentInterface(), interfaceNew.getName(), Optional.of(writeTransaction)); futures.add(writeTransaction.submit()); InterfaceKey interfaceKey = new InterfaceKey(parentRefs.getParentInterface()); Interface ifaceParent = InterfaceManagerCommonUtils.getInterfaceFromConfigDS(interfaceKey, dataBroker); if (ifaceParent == null) { LOG.info("Parent Interface: {} not found when adding child interface: {}", parentRefs.getParentInterface(), interfaceNew.getName()); return futures; }/*from w w w. j a v a 2 s .com*/ IfL2vlan parentIfL2Vlan = ifaceParent.getAugmentation(IfL2vlan.class); if (parentIfL2Vlan == null || parentIfL2Vlan.getL2vlanMode() != IfL2vlan.L2vlanMode.Trunk) { LOG.error("Parent Interface: {} not of trunk Type when adding trunk-member: {}", ifaceParent, interfaceNew); return futures; } org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface ifState = InterfaceManagerCommonUtils .getInterfaceStateFromOperDS(parentRefs.getParentInterface(), dataBroker); LOG.debug("add interface state info for vlan member {}, with ifState for parent {}", interfaceNew.getName(), ifState); InterfaceManagerCommonUtils.addStateEntry(interfaceNew.getName(), dataBroker, idManager, futures, ifState); return futures; }
From source file:manifestor.util.ManifestUtil.java
public final static Optional<Map<String, String>> readManifestFromInputStream(final InputStream inputStream) { try {//from w ww .j ava 2 s.c o m final Map<String, String> manifestMap = ManifestUtil.load(inputStream); return Optional.of(manifestMap); } catch (IOException ioex) { logger.error("Failed to fetch manifest details", ioex); } return Optional.absent(); }