List of usage examples for com.google.common.base Optional or
@Beta public abstract T or(Supplier<? extends T> supplier);
From source file:com.qcadoo.mes.deviationCausesReporting.DeviationsReportCriteria.java
private static DeviationsReportCriteria fromLocalDates(final LocalDate fromDate, final Optional<LocalDate> maybeToDate) { DateTime rangeBegin = fromDate.toDateTimeAtStartOfDay(); DateTime rangeEnd = maybeToDate.or(LocalDate.now()).plusDays(1).toDateTimeAtStartOfDay().minusMillis(1); Preconditions.checkArgument(rangeBegin.isBefore(rangeEnd), "Passed dates have wrong order."); Interval searchInterval = new Interval(rangeBegin, rangeEnd); return new DeviationsReportCriteria(searchInterval); }
From source file:org.eclipse.che.plugin.gdb.ide.configuration.GdbConfigurationPagePresenter.java
private static String getBinaryPath(DebugConfiguration editedConfiguration) { Map<String, String> connectionProperties = editedConfiguration.getConnectionProperties(); Optional<String> binPathOptional = Optional .fromNullable(connectionProperties.get(BIN_PATH_CONNECTION_PROPERTY)); return binPathOptional.or(""); }
From source file:net.es.nsi.pce.pf.PfUtils.java
public static boolean getSymmetricPath(P2PServiceBaseType p2ps) { Optional<Boolean> symmetricPath = Optional.fromNullable(p2ps.isSymmetricPath()); return symmetricPath.or(Boolean.TRUE); }
From source file:com.fourmob.datetimepicker.date.DatePickerDialog.java
public static DatePickerDialog newInstance(final OnDateSetListener onDateSetListener, Optional<Calendar> date, final boolean dark) { final Calendar notNullDate = date.or(new GregorianCalendar()); final boolean hasNoDate = !date.isPresent(); final int year = notNullDate.get(Calendar.YEAR); final int month = notNullDate.get(Calendar.MONTH); final int day = notNullDate.get(Calendar.DAY_OF_MONTH); return newInstance(onDateSetListener, year, month, day, dark, hasNoDate); }
From source file:com.aegiswallet.widgets.AegisTypeface.java
public static Optional<Typeface> createTypeface(TextView widget, Optional<Font> option) { if (widget.isInEditMode()) { return Optional.absent(); }/* w w w.java 2 s. com*/ synchronized (TYPEFACES) { Font font = option.or(Font.regular); Typeface typeface = TYPEFACES.get(font); if (typeface == null) { typeface = Typeface.createFromAsset(widget.getContext().getAssets(), getAssetPath(font)); TYPEFACES.put(font, typeface); } // This is never null at runtime, but roboelectric cannot create typefaces so it is null during tests return Optional.fromNullable(typeface); } }
From source file:net.es.nsi.pce.pf.PfUtils.java
public static DirectionalityType getDirectionality(P2PServiceBaseType p2ps) { Optional<DirectionalityType> directionality = Optional.fromNullable(p2ps.getDirectionality()); return directionality.or(DirectionalityType.BIDIRECTIONAL); }
From source file:org.locationtech.geogig.plumbing.HashObject.java
public static ObjectId hashTree(Optional<ImmutableList<Node>> trees, Optional<ImmutableList<Node>> features, Optional<ImmutableSortedMap<Integer, Bucket>> buckets) { return hashTree(trees.or(ImmutableList.of()), features.or(ImmutableList.of()), buckets.or(ImmutableSortedMap.of())); }
From source file:com.shufudong.GuavaExample.collect.OptionalExample.java
/** * @return//w w w.j av a 2 s .c o m * @category <p></p> * <ol> * <li> boolean isPresent()Optional?T?nulltrueTnullfalse</li> * <li>T get()Optional?TT???nullOptionalget()IllegalStateException</li> * <li>T or(T)Optional?T?Optional?T?T</li> * <li>T orNull()Optional??TOptional?null?fromNullable()</li> * <li>Set<T> asSet()??SetSet?Optional??TSet?T??Optional?T??Set</li> * </ol> * @throw */ public static void testMethodReturn() { Optional<Long> value = method(); if (value.isPresent() == true) { System.out.println(": " + value.get()); } else { System.out.println(": " + value.or(-12L)); } System.out.println(" orNull: " + value.orNull()); Optional<Long> valueNoNull = methodNoNull(); if (valueNoNull.isPresent() == true) { Set<Long> set = valueNoNull.asSet(); System.out.println(" set size : " + set.size()); System.out.println(": " + valueNoNull.get()); } else { System.out.println(": " + valueNoNull.or(-12L)); } System.out.println(" orNull: " + valueNoNull.orNull()); }
From source file:org.gradle.internal.component.model.AttributeConfigurationSelector.java
public static ConfigurationMetadata selectConfigurationUsingAttributeMatching( ImmutableAttributes consumerAttributes, ComponentResolveMetadata targetComponent, AttributesSchemaInternal consumerSchema) { Optional<ImmutableList<? extends ConfigurationMetadata>> variantsForGraphTraversal = targetComponent .getVariantsForGraphTraversal(); ImmutableList<? extends ConfigurationMetadata> consumableConfigurations = variantsForGraphTraversal .or(ImmutableList.<ConfigurationMetadata>of()); AttributesSchemaInternal producerAttributeSchema = targetComponent.getAttributesSchema(); AttributeMatcher attributeMatcher = consumerSchema.withProducer(producerAttributeSchema); ConfigurationMetadata fallbackConfiguration = targetComponent .getConfiguration(Dependency.DEFAULT_CONFIGURATION); if (fallbackConfiguration != null && !fallbackConfiguration.isCanBeConsumed()) { fallbackConfiguration = null;//from w ww. jav a 2 s . c om } List<ConfigurationMetadata> matches = attributeMatcher.matches(consumableConfigurations, consumerAttributes, fallbackConfiguration); if (matches.size() == 1) { return matches.get(0); } else if (!matches.isEmpty()) { throw new AmbiguousConfigurationSelectionException(consumerAttributes, attributeMatcher, matches, targetComponent, variantsForGraphTraversal.isPresent()); } else { throw new NoMatchingConfigurationSelectionException(consumerAttributes, attributeMatcher, targetComponent, variantsForGraphTraversal.isPresent()); } }
From source file:de.azapps.widgets.DateTimeDialog.java
public static DateTimeDialog newInstance(final OnDateTimeSetListener callback, final Optional<Calendar> dateTime, final boolean dark) { final Calendar notNullDateTime = dateTime.or(new GregorianCalendar()); final int year = notNullDateTime.get(Calendar.YEAR); final int month = notNullDateTime.get(Calendar.MONTH); final int day = notNullDateTime.get(Calendar.DAY_OF_MONTH); final int hour = notNullDateTime.get(Calendar.HOUR_OF_DAY); final int minute = notNullDateTime.get(Calendar.MINUTE); return newInstance(callback, year, month, day, hour, minute, true, dark); }