Example usage for com.google.common.base Optional asSet

List of usage examples for com.google.common.base Optional asSet

Introduction

In this page you can find the example usage for com.google.common.base Optional asSet.

Prototype

public abstract Set<T> asSet();

Source Link

Document

Returns an immutable singleton Set whose only element is the contained instance if it is present; an empty immutable Set otherwise.

Usage

From source file:com.qcadoo.mes.productionPerShift.util.NonWorkingShiftsNotifier.java

private Iterable<ShiftAndDate> extractShiftsAndDates(final Entity progressForDay) {
    Optional<Date> maybeActualDate = Optional
            .fromNullable(progressForDay.getDateField(ProgressForDayFields.ACTUAL_DATE_OF_DAY));
    for (Date actualDate : maybeActualDate.asSet()) {
        final LocalDate actualLocalDate = LocalDate.fromDateFields(actualDate);
        final int realizationDayNumber = progressForDay.getIntegerField(ProgressForDayFields.DAY);
        return FluentIterable.from(progressForDay.getHasManyField(ProgressForDayFields.DAILY_PROGRESS))
                .transformAndConcat(new Function<Entity, Iterable<ShiftAndDate>>() {

                    @Override/*from  ww  w . jav  a2  s  .c o m*/
                    public Iterable<ShiftAndDate> apply(final Entity dailyProgress) {
                        return toShiftAndDates(dailyProgress, realizationDayNumber, actualLocalDate);
                    }
                }).toList();
    }
    return Collections.emptyList();
}

From source file:com.qcadoo.mes.productionPerShift.listeners.ProductionPerShiftListeners.java

public void refreshView(final ViewDefinitionState view, final ComponentState state, final String[] args) {
    markViewAsUninitialized(view);// w  w  w  .  ja va  2 s.c o  m
    Optional<FormComponent> maybeForm = view.tryFindComponentByReference(FORM_COMPONENT_REF);
    for (FormComponent form : maybeForm.asSet()) {
        form.performEvent(view, "reset");
    }
}

From source file:org.pentaho.di.trans.dataservice.optimization.pushdown.ParameterPushdown.java

@VisibleForTesting
protected Map<String, String> captureParameterValues(SQL sql) {
    Optional<SQLCondition> whereCondition = Optional.fromNullable(sql.getWhereCondition());
    Multimap<String, Condition> conditionMap = FluentIterable.from(whereCondition.asSet())
            .transformAndConcat(new Function<SQLCondition, Iterable<Condition>>() {
                @Override/*from ww  w.  ja  v  a  2s.  c om*/
                public Iterable<Condition> apply(SQLCondition sqlCondition) {
                    Condition condition = sqlCondition.getCondition();
                    condition.simplify();

                    // Flatten first level of conditions
                    if (!condition.isComposite()) {
                        return Collections.singleton(condition);
                    }

                    // All child conditions must have allowable operators
                    for (Condition child : condition.getChildren()) {
                        if (!ALLOWED_OPERATORS.contains(child.getOperator())) {
                            return Collections.emptySet();
                        }
                    }

                    return condition.getChildren();
                }
            }).filter(new Predicate<Condition>() {
                @Override
                public boolean apply(Condition condition) {
                    // Only simple 'equals' conditions should be allowed
                    // in the form of: WHERE A = 1
                    return !condition.isComposite() && !condition.isNegated()
                            && condition.getRightExact() != null
                            && ALLOWED_FUNCTIONS.contains(condition.getFunction());
                }
            }).index(new Function<Condition, String>() {
                @Override
                public String apply(Condition condition) {
                    // Group by field for easy look up
                    return condition.getLeftValuename();
                }
            });

    Map<String, String> builder = Maps.newLinkedHashMap();
    for (Definition definition : definitions) {
        // There should be either 0 or 1 conditions for each field.
        for (Condition condition : conditionMap.get(definition.getFieldName())) {
            builder.put(definition.getParameter(), definition.format(condition));
        }
    }
    return ImmutableMap.copyOf(builder);
}

From source file:com.qcadoo.mes.productionPerShift.listeners.ProductionPerShiftListeners.java

private void markViewAsUninitialized(final ViewDefinitionState view) {
    Optional<CheckBoxComponent> maybeCheckbox = view
            .tryFindComponentByReference(VIEW_IS_INITIALIZED_CHECKBOX_REF);
    for (CheckBoxComponent checkbox : maybeCheckbox.asSet()) {
        checkbox.setChecked(false);//w ww  .ja  va 2 s .c  o  m
        checkbox.requestComponentUpdateState();
    }
}

From source file:com.qcadoo.mes.basic.shift.Shift.java

/**
 * Returns date range containing given date. This method IS AWARE of timetable exceptions.
 * //from   w w w  .j ava2  s  . c om
 * <b>Be aware</b> - this method doesn't compose returned date range with the timetable exclusions/inclusions. This means that
 * if you have a shift which works at Monday from 8:00-16:00 and there is defined work time exclusion from 12:00-20:00 and you
 * ask for 10:00 then you will get date range from 8:00-16:00 (as in plan). But if you ask for 14:00 you will get
 * Optional.absent().
 * 
 * @param date
 *            date with time for which work dates range you want to find.
 * @return
 */
public Optional<DateRange> findWorkTimeAt(final Date date) {
    if (timetableExceptions.hasFreeTimeAt(date)) {
        return Optional.absent();
    }
    DateTime dateTime = new DateTime(date);
    Optional<TimeRange> maybeTimeRangeFromPlan = findWorkTimeAt(dateTime.getDayOfWeek(),
            dateTime.toLocalTime());
    for (TimeRange timeRangeFromPlan : maybeTimeRangeFromPlan.asSet()) {
        return Optional.of(buildDateRangeFrom(timeRangeFromPlan, date));
    }
    return timetableExceptions.findDateRangeFor(TimetableExceptionType.WORK_TIME, date);
}

From source file:clocker.docker.location.strategy.basic.GroupPlacementStrategy.java

@Override
public List<DockerHostLocation> filterLocations(List<DockerHostLocation> locations, Entity entity) {
    if (locations == null || locations.isEmpty()) {
        return ImmutableList.of();
    }/*from  www .  ja  v a 2  s.  c om*/
    if (getDockerInfrastructure() == null)
        config().set(DOCKER_INFRASTRUCTURE, Iterables.getLast(locations).getDockerInfrastructure());
    List<DockerHostLocation> available = MutableList.copyOf(locations);
    boolean requireExclusive = config().get(REQUIRE_EXCLUSIVE);

    try {
        acquireMutex(entity.getApplicationId(), "Filtering locations for " + entity);
    } catch (InterruptedException ie) {
        Exceptions.propagate(ie); // Should never happen...
    }

    // Find hosts with entities from our application deployed there
    Iterable<DockerHostLocation> sameApplication = Iterables.filter(available,
            hasApplicationId(entity.getApplicationId()));

    // Check if hosts have any deployed entities that share a parent with the input entity
    Optional<DockerHostLocation> sameParent = Iterables.tryFind(sameApplication,
            childrenOf(entity.getParent()));
    if (sameParent.isPresent()) {
        LOG.debug("Returning {} (same parent) for {} placement", sameParent.get(), entity);
        return ImmutableList.copyOf(sameParent.asSet());
    }

    // Remove hosts if they have any entities from our application deployed there
    Iterables.removeIf(available, hasApplicationId(entity.getApplicationId()));
    if (requireExclusive) {
        Iterables.removeIf(available, nonEmpty());
    }
    LOG.debug("Returning {} for {} placement", Iterables.toString(available), entity);
    return available;
}

From source file:com.qcadoo.mes.productionPerShift.hooks.ProductionPerShiftDetailsHooks.java

private void markViewAsInitialized(final ViewDefinitionState view) {
    Optional<CheckBoxComponent> maybeCheckbox = view
            .tryFindComponentByReference(VIEW_IS_INITIALIZED_CHECKBOX_REF);
    for (CheckBoxComponent checkbox : maybeCheckbox.asSet()) {
        checkbox.setChecked(true);//from  www  . ja  v  a  2s . c  o m
        checkbox.requestComponentUpdateState();
    }
}

From source file:com.eucalyptus.auth.euare.identity.region.RegionConfigurationManager.java

/**
 * Get all region information (if any)/*from w w  w .ja  v a 2s .  c  o m*/
 *
 * @return The region information
 */
public Iterable<RegionInfo> getRegionInfos() {
    final Optional<RegionConfiguration> regionConfigurationOptional = regionConfigurationSupplier.get();
    return Iterables.transform(Iterables.concat(regionConfigurationOptional.asSet()),
            regionToRegionInfoTransform(regionConfigurationOptional));
}

From source file:com.eucalyptus.auth.euare.identity.region.RegionConfigurationManager.java

/**
 * Get the region information for the local region (if any)
 *
 * @return The optional region information
 *//*from w  w  w .j  ava2s. c  om*/
public Optional<RegionInfo> getRegionInfoByHost(final String host) {
    final Optional<RegionConfiguration> regionConfigurationOptional = regionConfigurationSupplier.get();
    return Iterables
            .tryFind(Iterables.concat(regionConfigurationOptional.asSet()),
                    propertyContainsPredicate(host, RegionServiceHostTransform.INSTANCE))
            .transform(regionToRegionInfoTransform(regionConfigurationOptional));
}

From source file:com.eucalyptus.auth.euare.identity.region.RegionConfigurationManager.java

/**
 * Get the region information for the local region (if any)
 *
 * @return The optional region information
 */// ww  w.  j a  v  a  2  s  .co m
public Optional<RegionInfo> getRegionInfo() {
    final Optional<RegionConfiguration> regionConfigurationOptional = regionConfigurationSupplier.get();
    return Iterables
            .tryFind(Iterables.concat(regionConfigurationOptional.asSet()),
                    propertyPredicate(RegionConfigurations.getRegionName().asSet(),
                            RegionNameTransform.INSTANCE))
            .transform(regionToRegionInfoTransform(regionConfigurationOptional));
}