List of usage examples for com.google.common.base Optional isPresent
public abstract boolean isPresent();
From source file:org.dswarm.graph.batch.rdf.pnx.utils.NodeTypeUtils.java
public static Optional<NodeType> getNodeType(final Optional<Node> optionalNode, final Optional<Boolean> optionalIsType) { if (!optionalNode.isPresent()) { return Optional.absent(); }//from w w w. j av a2 s . co m final NodeType nodeType; final Node node = optionalNode.get(); if (node instanceof Resource) { if (optionalIsType.isPresent()) { if (Boolean.FALSE.equals(optionalIsType.get())) { nodeType = NodeType.Resource; } else { nodeType = NodeType.TypeResource; } } else { nodeType = NodeType.Resource; } } else if (node instanceof BNode) { if (optionalIsType.isPresent()) { if (Boolean.FALSE.equals(optionalIsType.get())) { nodeType = NodeType.BNode; } else { nodeType = NodeType.TypeBNode; } } else { nodeType = NodeType.BNode; } } else if (node instanceof Literal) { nodeType = NodeType.Literal; } else { nodeType = null; } return Optional.fromNullable(nodeType); }
From source file:org.sonar.server.computation.task.projectanalysis.measure.MeasureDtoToMeasure.java
private static Measure.NewMeasureBuilder setCommonProperties(Measure.NewMeasureBuilder builder, MeasureDto measureDto) {/*from w ww.ja va 2 s . c o m*/ if (measureDto.getAlertStatus() != null) { Optional<Measure.Level> qualityGateStatus = toLevel(measureDto.getAlertStatus()); if (qualityGateStatus.isPresent()) { builder.setQualityGateStatus( new QualityGateStatus(qualityGateStatus.get(), measureDto.getAlertText())); } } if (hasAnyVariation(measureDto)) { builder.setVariation(measureDto.getVariation()); } return builder; }
From source file:harp.HarpMain.java
private static void run(String[] args) throws Exception { Preconditions.checkArgument(args[0].equals("run")); if (args.length != 3) { System.err.println("Harp 'run' usage:"); System.err.println("java -jar <path to harp jar> run ENVIRONMENT EXECUTABLE"); System.err.println();/*from ww w . java 2 s. c o m*/ System.err.println("Parameters:"); System.err.println("ENVIRONMENT name of the Harp Environment to use for execution"); System.err.println("EXECUTABLE Harp-path of the Harp executable to execute"); System.exit(1); } Optional<Path> potentialRootHarpFilePath = FileUtil.findUpward("root.harp", Paths.get("").toAbsolutePath()); if (!potentialRootHarpFilePath.isPresent()) { throw new FileNotFoundException("No root.harp file was found in or above the present directory."); } Path rootHarpFilePath = potentialRootHarpFilePath.get(); String environmentName = args[1]; // TODO implement a real naming system for paths. A Harp path like run.harp:executable might be // stupid. String[] executablePathParts = args[2].split(":"); String executablePath = executablePathParts[0]; String executableName = executablePathParts[1]; String rootHarpContents = new String(Files.readAllBytes(rootHarpFilePath), Charsets.UTF_8); RootContext rootContext = RootGroovyRunner.parseRootHarpScript(rootHarpContents); Environment environment = rootContext.getEnvironment(environmentName); ScriptGraph linkedScripts = environment.getLinker().link(executablePath); HarpJob thisJob = new HarpJob(linkedScripts, ImmutableList.of(executableName)); Dispatcher dispatcher = environment.getDispatcher(); dispatcher.dispatch(thisJob); System.out.println("Done executing " + executableName); System.exit(0); }
From source file:org.dswarm.graph.rdf.nx.utils.NodeTypeUtils.java
public static Optional<NodeType> getNodeType(final Optional<Node> optionalNode, final Optional<Boolean> optionalIsType) { if (!optionalNode.isPresent()) { return Optional.absent(); }//w ww . j a v a 2 s .c om final NodeType nodeType; final Node node = optionalNode.get(); if (node instanceof BNode) { if (optionalIsType.isPresent()) { if (Boolean.FALSE.equals(optionalIsType.get())) { nodeType = NodeType.BNode; } else { nodeType = NodeType.TypeBNode; } } else { nodeType = NodeType.BNode; } } else if (node instanceof Literal) { nodeType = NodeType.Literal; } else if (node instanceof Resource) { if (optionalIsType.isPresent()) { if (Boolean.FALSE.equals(optionalIsType.get())) { nodeType = NodeType.Resource; } else { nodeType = NodeType.TypeResource; } } else { nodeType = NodeType.Resource; } } else { nodeType = null; } return Optional.fromNullable(nodeType); }
From source file:org.sonar.server.computation.task.projectanalysis.measure.BatchMeasureToMeasure.java
private static Optional<Measure> toLevelMeasure(Measure.NewMeasureBuilder builder, ScannerReport.Measure batchMeasure) { if (batchMeasure.getValueCase() == ValueCase.VALUE_NOT_SET) { return toNoValueMeasure(builder, batchMeasure); }//from w ww . j av a2 s . c o m Optional<Measure.Level> level = Measure.Level.toLevel(batchMeasure.getStringValue().getValue()); if (!level.isPresent()) { return toNoValueMeasure(builder, batchMeasure); } return of(builder.create(level.get())); }
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 ava2 s . c om 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.opendaylight.protocol.bgp.openconfig.impl.moduleconfig.DataBrokerFunction.java
public static <T extends ServiceRef & ChildOf<Module>> T getRibInstance( final BGPConfigModuleProvider configModuleOp, final Function<String, T> function, final String instanceName, final ReadOnlyTransaction rTx) { Preconditions.checkNotNull(rTx);//w ww . jav a 2 s.com try { final Optional<Service> maybeService = configModuleOp .readConfigService(new ServiceKey(DomAsyncDataBroker.class), rTx); if (maybeService.isPresent()) { final Optional<Instance> maybeInstance = Iterables.tryFind(maybeService.get().getInstance(), new Predicate<Instance>() { @Override public boolean apply(final Instance instance) { final String moduleName = OpenConfigUtil.getModuleName(instance.getProvider()); if (moduleName.equals(instanceName)) { return true; } return false; } }); if (maybeInstance.isPresent()) { return function.apply(maybeInstance.get().getName()); } } return null; } catch (ReadFailedException e) { throw new IllegalStateException("Failed to read service.", e); } }
From source file:org.eclipse.buildship.core.workspace.internal.GradleClasspathContainerRuntimeClasspathEntryResolver.java
private static void collectContainerRuntimeClasspath(IClasspathContainer container, List<IRuntimeClasspathEntry> result, boolean includeExportedEntriesOnly) throws CoreException { for (final IClasspathEntry cpe : container.getClasspathEntries()) { if (!includeExportedEntriesOnly || cpe.isExported()) { if (cpe.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { result.add(JavaRuntime.newArchiveRuntimeClasspathEntry(cpe.getPath())); } else if (cpe.getEntryKind() == IClasspathEntry.CPE_PROJECT) { Optional<IProject> candidate = findAccessibleJavaProject(cpe.getPath().segment(0)); if (candidate.isPresent()) { IJavaProject dependencyProject = JavaCore.create(candidate.get()); IRuntimeClasspathEntry projectRuntimeEntry = JavaRuntime .newProjectRuntimeClasspathEntry(dependencyProject); Collections.addAll(result, JavaRuntime.resolveRuntimeClasspathEntry(projectRuntimeEntry, dependencyProject)); collectContainerRuntimeClasspathIfPresent(dependencyProject, result, true); }/*from ww w . java 2 s . c om*/ } } } }
From source file:com.facebook.watchman.environment.ExecutableFinder.java
public static Path getExecutable(Path suggestedExecutable, ImmutableMap<String, String> env) { Optional<Path> exe = getOptionalExecutable(suggestedExecutable, env); if (!exe.isPresent()) { throw new RuntimeException(String.format( "Unable to locate %s on PATH, or it's not marked as being executable", suggestedExecutable)); }/*from ww w .j a v a 2 s . c o m*/ return exe.get(); }
From source file:org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundUtil.java
public static Optional<HwvtepGlobalAugmentation> getManagingNode(DataBroker db, HwvtepGlobalRef ref) { try {//from w w w. j ava2 s. c o m ReadOnlyTransaction transaction = db.newReadOnlyTransaction(); @SuppressWarnings("unchecked") // Note: erasure makes this safe in combination with the typecheck // below InstanceIdentifier<Node> path = (InstanceIdentifier<Node>) ref.getValue(); CheckedFuture<Optional<Node>, ReadFailedException> nf = transaction .read(LogicalDatastoreType.OPERATIONAL, path); transaction.close(); Optional<Node> optional = nf.get(); if (optional != null && optional.isPresent()) { HwvtepGlobalAugmentation hwvtepNode = null; Node node = optional.get(); if (node instanceof HwvtepGlobalAugmentation) { hwvtepNode = (HwvtepGlobalAugmentation) node; } else if (node != null) { hwvtepNode = node.getAugmentation(HwvtepGlobalAugmentation.class); } if (hwvtepNode != null) { return Optional.of(hwvtepNode); } else { LOG.warn("Hwvtep switch claims to be managed by {} but " + "that HwvtepNode does not exist", ref.getValue()); return Optional.absent(); } } else { LOG.warn("Mysteriously got back a thing which is *not* a topology Node: {}", optional); return Optional.absent(); } } catch (Exception e) { LOG.warn("Failed to get HwvtepNode {}", ref, e); return Optional.absent(); } }