List of usage examples for com.google.common.base Optional or
@Beta public abstract T or(Supplier<? extends T> supplier);
From source file:software.betamax.Recorder.java
/** * Starts the Recorder, inserting a tape with the specified parameters. * * @param tapeName the name of the tape. * @param mode the tape mode. If not supplied the default mode from the configuration is used. * @param matchRule the rules used to match recordings on the tape. If not supplied a default is used. * * @throws IllegalStateException if the Recorder is already started. *///from w w w. ja v a 2 s. c om public void start(String tapeName, Optional<TapeMode> mode, Optional<MatchRule> matchRule) { if (tape != null) { throw new IllegalStateException("start called when Recorder is already started"); } tape = getTapeLoader().loadTape(tapeName); tape.setMode(mode.or(configuration.getDefaultMode())); tape.setMatchRule(matchRule.or(configuration.getDefaultMatchRule())); for (RecorderListener listener : listeners) { listener.onRecorderStart(tape); } }
From source file:co.paralleluniverse.fibers.dropwizard.MyDropwizardApp.java
@GET @Path("/http") @Timed/* w w w .j a v a 2s. c om*/ public String http(@QueryParam("name") Optional<String> name) throws InterruptedException, SuspendExecution, IOException { return httpClient.execute(new HttpGet("http://localhost:8080/?sleep=10&name=" + name.or("name")), new BasicResponseHandler()); }
From source file:org.geogit.cli.porcelain.Show.java
private void printRaw(GeogitCLI cli) throws IOException { ConsoleReader console = cli.getConsole(); GeoGIT geogit = cli.getGeogit();/*from ww w .j a v a 2 s. c om*/ for (String ref : refs) { Optional<RevObject> obj = geogit.command(RevObjectParse.class).setRefSpec(ref).call(); checkParameter(obj.isPresent(), "refspec did not resolve to any object."); RevObject revObject = obj.get(); if (revObject instanceof RevFeature) { RevFeatureType ft = geogit.command(ResolveFeatureType.class).setRefSpec(ref).call().get(); ImmutableList<PropertyDescriptor> attribs = ft.sortedDescriptors(); RevFeature feature = (RevFeature) revObject; Ansi ansi = super.newAnsi(console.getTerminal()); ansi.a(ref).newline(); ansi.a(feature.getId().toString()).newline(); ImmutableList<Optional<Object>> values = feature.getValues(); int i = 0; for (Optional<Object> value : values) { ansi.a(attribs.get(i).getName()).newline(); ansi.a(value.or("[NULL]").toString()).newline(); i++; } console.println(ansi.toString()); } else { CharSequence s = geogit.command(CatObject.class).setObject(Suppliers.ofInstance(revObject)).call(); console.println(s); } } }
From source file:org.apache.rya.indexing.pcj.fluo.app.observers.ConstructQueryResultObserver.java
private void insertTriples(TransactionBase tx, final Collection<RyaStatement> triples) { for (final RyaStatement triple : triples) { Optional<byte[]> visibility = Optional.fromNullable(triple.getColumnVisibility()); try {/*from w w w . j ava2 s .c o m*/ tx.set(Bytes.of(spoFormat(triple)), FluoQueryColumns.TRIPLES, Bytes.of(visibility.or(new byte[0]))); } catch (final TripleRowResolverException e) { log.error("Could not convert a Triple into the SPO format: " + triple); } } }
From source file:org.eclipse.buildship.core.workspace.internal.ClasspathContainerUpdater.java
private ClasspathContainerUpdater(IJavaProject project, Optional<List<OmniEclipseClasspathContainer>> containers, OmniJavaSourceSettings sourceSettings) { this.project = project; this.gradleSupportsContainers = containers.isPresent(); this.containers = containers.or(Collections.<OmniEclipseClasspathContainer>emptyList()); this.sourceSettings = sourceSettings; }
From source file:com.pinterest.teletraan.resource.Groups.java
@GET @Path("/names") public List<String> getGroupNames(@QueryParam("start") Optional<Integer> start, @QueryParam("size") Optional<Integer> size) throws Exception { return groupHandler.getEnvGroupNames(start.or(1), size.or(DEFAULT_SIZE)); }
From source file:com.intuit.wasabi.authentication.impl.DefaultAuthentication.java
/** * @param authHeader The http authroization header * @return UserCredential for the authHeader *//* w ww . j ava 2 s. c o m*/ private UserCredential parseUsernamePassword(final Optional<String> authHeader) { if (!authHeader.isPresent()) { throw new AuthenticationException("Null Authentication Header is not supported"); } if (!authHeader.or(SPACE).contains(BASIC)) { throw new AuthenticationException("Only Basic Authentication is supported"); } final String encodedUserPassword = authHeader.get().substring(authHeader.get().lastIndexOf(SPACE)); String usernameAndPassword; LOGGER.trace("Base64 decoded username and password is: {}", encodedUserPassword); try { usernameAndPassword = new String(decodeBase64(encodedUserPassword.getBytes())); } catch (Exception e) { throw new AuthenticationException("error parsing username and password", e); } //Split username and password tokens String[] fields = usernameAndPassword.split(SEMICOLON); if (fields.length > 2) { throw new AuthenticationException("More than one username and password provided, or one contains ':'"); } else if (fields.length < 2) { throw new AuthenticationException("Username or password are empty."); } if (isBlank(fields[0]) || isBlank(fields[1])) { throw new AuthenticationException("Username or password are empty."); } return new UserCredential(fields[0], fields[1]); }
From source file:org.openqa.selenium.testing.drivers.ExternalDriverSupplier.java
@Override public WebDriver get() { Optional<Supplier<WebDriver>> delegate = createDelegate(desiredCapabilities, requiredCapabilities); delegate = createForExternalServer(desiredCapabilities, requiredCapabilities, delegate); return delegate.or(Suppliers.<WebDriver>ofInstance(null)).get(); }
From source file:com.arpnetworking.configuration.BaseConfiguration.java
/** * {@inheritDoc}/*from w w w . j a v a 2 s . com*/ */ @Override public long getPropertyAsLong(final String name, final long defaultValue) throws NumberFormatException { final Optional<Long> property = getPropertyAsLong(name); return property.or(defaultValue); }
From source file:net.wouterdanes.docker.maven.AbstractDockerMojo.java
protected void enqueueForPushing(final String imageId, final Optional<String> nameAndTag) { getLog().info(String.format("Enqueuing image '%s' to be pushed with tag '%s'..", imageId, nameAndTag.or("<none>"))); List<PushableImage> images = obtainListFromPluginContext(PUSHABLE_IMAGES_KEY); PushableImage newImage = new PushableImage(imageId, nameAndTag); if (!images.contains(newImage)) { images.add(newImage);//from w ww . j ava 2s. co m } }