List of usage examples for com.google.common.base Optional asSet
public abstract Set<T> asSet();
From source file:org.zanata.rest.service.TranslationsTMXExportStrategy.java
private Set<Element> buildTUVs(ITextFlow tf) throws InvalidContentsException { Set<Element> tuvSet = Sets.newLinkedHashSet(); tuvSet.add(buildSourceTUV(tf));//from w w w . j av a 2 s. c om if (exportAllLocales()) { Iterable<ITextFlowTarget> allTargets = tf.getAllTargetContents(); for (ITextFlowTarget target : allTargets) { Optional<Element> tuv = buildTargetTUV(target); tuvSet.addAll(tuv.asSet()); } } else { ITextFlowTarget target = tf.getTargetContents(this.localeId); if (target != null) { Optional<Element> tuv = buildTargetTUV(target); tuvSet.addAll(tuv.asSet()); } } return tuvSet; }
From source file:com.qcadoo.mes.productionPerShift.util.ProgressQuantitiesDeviationNotifier.java
public void compareAndNotify(final ViewDefinitionState view, final Entity order, final Entity technologyOperationComponent) { Optional<BigDecimal> maybeQuantitiesDifference = calculateQuantitiesDifference(order, technologyOperationComponent); for (BigDecimal quantitiesDifference : maybeQuantitiesDifference.asSet()) { int compareResult = quantitiesDifference.compareTo(BigDecimal.ZERO); if (compareResult > 0) { showQuantitiesDeviationNotice(view, quantitiesDifference, "productionPerShift.productionPerShiftDetails.sumPlanedQuantityPSSmaller"); } else if (compareResult < 0) { showQuantitiesDeviationNotice(view, quantitiesDifference, "productionPerShift.productionPerShiftDetails.sumPlanedQuantityPSGreater"); }//w ww. j a v a 2 s . c om } }
From source file:com.eucalyptus.cluster.VmStateHandler.java
public static void updateVmInfo(final VmStateUpdate stateUpdate) { UpdateInstanceResourcesType update = new UpdateInstanceResourcesType(); update.setPartition(stateUpdate.getCluster().getPartition()); update.setResources(TypeMappers.transform(stateUpdate, InstanceResourceReportType.class)); final boolean requestBroadcast = Networking.getInstance().update(update); if (Databases.isVolatile()) { return;/*from w ww. j a v a 2s. c om*/ } final Cluster cluster = stateUpdate.getCluster(); final Set<String> initialInstances = stateUpdate.getRequestedVms(); final List<VmInfo> vms = stateUpdate.getVmInfos(); final Map<String, VmStateView> localState = ImmutableMap.copyOf(CollectionUtils.putAll( instanceViewSupplier.get(), Maps.<String, VmStateView>newHashMapWithExpectedSize(vms.size()), HasName.GET_NAME, Functions.<VmStateView>identity())); final Set<String> reportedInstances = Sets.newHashSetWithExpectedSize(vms.size()); for (VmInfo vmInfo : vms) { reportedInstances.add(vmInfo.getInstanceId()); vmInfo.setPlacement(cluster.getConfiguration().getName()); VmTypeInfo typeInfo = vmInfo.getInstanceType(); if (typeInfo.getName() == null || "".equals(typeInfo.getName())) { for (VmType t : VmTypes.list()) { if (t.getCpu().equals(typeInfo.getCores()) && t.getDisk().equals(typeInfo.getDisk()) && t.getMemory().equals(typeInfo.getMemory())) { typeInfo.setName(t.getName()); } } } } final Set<String> unreportedInstances = Sets .newHashSet(Sets.difference(initialInstances, reportedInstances)); if (Databases.isVolatile()) { return; } final Set<String> unknownInstances = Sets.newHashSet(Sets.difference(reportedInstances, initialInstances)); final List<Optional<Runnable>> taskList = Lists.newArrayList(); for (final VmInfo runVm : vms) { if (initialInstances.contains(runVm.getInstanceId())) { taskList.add(UpdateTaskFunction.REPORTED.apply(context(localState, runVm))); } else if (unknownInstances.contains(runVm.getInstanceId())) { taskList.add(UpdateTaskFunction.UNKNOWN.apply(context(localState, runVm))); } } for (final String vmId : unreportedInstances) { taskList.add(UpdateTaskFunction.UNREPORTED.apply(context(localState, vmId))); } final Optional<Runnable> broadcastRequestRunnable = requestBroadcast ? Optional.<Runnable>of(new Runnable() { @Override public void run() { NetworkInfoBroadcaster.requestNetworkInfoBroadcast(); } }) : Optional.<Runnable>absent(); for (final Runnable task : Iterables.concat(Optional.presentInstances(taskList), broadcastRequestRunnable.asSet())) { Threads.enqueue(ClusterController.class, VmStateHandler.class, (Runtime.getRuntime().availableProcessors() * 2) + 1, Executors.callable(task)); } }
From source file:com.qcadoo.mes.deviationCausesReporting.hooks.DeviationReportGeneratorViewHooks.java
private void markDateFromAsRequired(final ViewDefinitionState view) { Optional<FieldComponent> maybeDateFromComponent = view .tryFindComponentByReference(DeviationReportGeneratorViewReferences.DATE_FROM); for (FieldComponent dateFromComponent : maybeDateFromComponent.asSet()) { dateFromComponent.setRequired(true); }/* w w w . jav a2 s .c o m*/ }
From source file:com.qcadoo.mes.deviationCausesReporting.hooks.DeviationReportGeneratorViewHooks.java
private void setDefaultDateRange(final ViewDefinitionState view) { for (ComponentState dateFromComponent : view .tryFindComponentByReference(DeviationReportGeneratorViewReferences.DATE_FROM).asSet()) { Date firstDayOfCurrentMonth = LocalDate.now().withDayOfMonth(1).toDate(); dateFromComponent.setFieldValue(DateUtils.toDateString(firstDayOfCurrentMonth)); }/*from w w w . j a v a2 s . c o m*/ Optional<ComponentState> maybeDateFromComponent = view .tryFindComponentByReference(DeviationReportGeneratorViewReferences.DATE_TO); for (ComponentState dateFromComponent : maybeDateFromComponent.asSet()) { Date today = LocalDate.now().toDate(); dateFromComponent.setFieldValue(DateUtils.toDateString(today)); } }
From source file:com.qcadoo.mes.assignmentToShift.dataProviders.AssignmentToShiftDataProvider.java
public List<Entity> findAll(final AssignmentToShiftCriteria criteria, final Optional<SearchProjection> maybeProjection, final Optional<SearchOrder> maybeSearchOrder) { SearchCriteriaBuilder scb = createCriteriaBuilder(criteria); setProjectionIfPresent(scb, maybeProjection); for (SearchOrder searchOrder : maybeSearchOrder.asSet()) { scb.addOrder(searchOrder);/*from www . jav a 2 s . c o m*/ } return scb.list().getEntities(); }
From source file:com.qcadoo.mes.deviationCausesReporting.hooks.DeviationReportGeneratorViewHooks.java
private void markViewAsAlreadyInitialized(final ViewDefinitionState view) { Optional<CheckBoxComponent> maybeCheckBox = view .tryFindComponentByReference(DeviationReportGeneratorViewReferences.IS_VIEW_INITIALIZED); for (CheckBoxComponent isViewInitializedCheckbox : maybeCheckBox.asSet()) { isViewInitializedCheckbox.setChecked(true); }/*w w w. j a v a 2 s . com*/ }
From source file:org.opendaylight.openflowplugin.impl.registry.flow.DeviceFlowRegistryImpl.java
private CheckedFuture<Optional<FlowCapableNode>, ReadFailedException> fillFromDatastore( final LogicalDatastoreType logicalDatastoreType, final InstanceIdentifier<FlowCapableNode> path) { // Create new read-only transaction final ReadOnlyTransaction transaction = dataBroker.newReadOnlyTransaction(); // Bail out early if transaction is null if (transaction == null) { return Futures.immediateFailedCheckedFuture(new ReadFailedException("Read transaction is null")); }//w w w . ja v a2s.c o m // Prepare read operation from datastore for path final CheckedFuture<Optional<FlowCapableNode>, ReadFailedException> future = transaction .read(logicalDatastoreType, path); // Bail out early if future is null if (future == null) { return Futures .immediateFailedCheckedFuture(new ReadFailedException("Future from read transaction is null")); } Futures.addCallback(future, new FutureCallback<Optional<FlowCapableNode>>() { @Override public void onSuccess(Optional<FlowCapableNode> result) { result.asSet().stream().filter(Objects::nonNull) .filter(flowCapableNode -> Objects.nonNull(flowCapableNode.getTable())) .flatMap(flowCapableNode -> flowCapableNode.getTable().stream()).filter(Objects::nonNull) .filter(table -> Objects.nonNull(table.getFlow())) .flatMap(table -> table.getFlow().stream()).filter(Objects::nonNull) .filter(flow -> Objects.nonNull(flow.getId())).forEach(flowConsumer); // After we are done with reading from datastore, close the transaction transaction.close(); } @Override public void onFailure(Throwable t) { // Even when read operation failed, close the transaction transaction.close(); } }); return future; }
From source file:com.google.devtools.build.lib.rules.objc.J2ObjcAspect.java
private static J2ObjcSource javaJ2ObjcSource(RuleContext ruleContext, Iterable<Artifact> javaInputSourceFiles, Iterable<Artifact> javaSourceJarFiles) { PathFragment objcFileRootRelativePath = ruleContext.getUniqueDirectory("_j2objc"); PathFragment objcFileRootExecPath = ruleContext.getConfiguration().getBinFragment() .getRelative(objcFileRootRelativePath); Iterable<Artifact> objcSrcs = getOutputObjcFiles(ruleContext, javaInputSourceFiles, objcFileRootRelativePath, ".m"); Iterable<Artifact> objcHdrs = getOutputObjcFiles(ruleContext, javaInputSourceFiles, objcFileRootRelativePath, ".h"); Iterable<PathFragment> headerSearchPaths = J2ObjcLibrary.j2objcSourceHeaderSearchPaths(ruleContext, objcFileRootExecPath, javaInputSourceFiles); Optional<Artifact> sourceJarTranslatedSrcs = Optional.absent(); Optional<Artifact> sourceJarTranslatedHdrs = Optional.absent(); Optional<PathFragment> sourceJarFileHeaderSearchPaths = Optional.absent(); if (!Iterables.isEmpty(javaSourceJarFiles)) { sourceJarTranslatedSrcs = Optional.of(j2ObjcSourceJarTranslatedSourceFiles(ruleContext)); sourceJarTranslatedHdrs = Optional.of(j2objcSourceJarTranslatedHeaderFiles(ruleContext)); sourceJarFileHeaderSearchPaths = Optional.of(sourceJarTranslatedHdrs.get().getExecPath()); }// www. j ava 2 s . c o m return new J2ObjcSource(ruleContext.getRule().getLabel(), Iterables.concat(objcSrcs, sourceJarTranslatedSrcs.asSet()), Iterables.concat(objcHdrs, sourceJarTranslatedHdrs.asSet()), objcFileRootExecPath, SourceType.JAVA, Iterables.concat(headerSearchPaths, sourceJarFileHeaderSearchPaths.asSet())); }
From source file:org.apache.aurora.scheduler.filter.SchedulingFilterImpl.java
@Timed("scheduling_filter") @Override//from w ww . j a v a 2 s . c om public Set<Veto> filter(UnusedResource resource, ResourceRequest request) { // Apply veto filtering rules from higher to lower score making sure we cut over and return // early any time a veto from a score group is applied. This helps to more accurately report // a veto reason in the NearestFit. // 1. Dedicated constraint check (highest score). if (!ConfigurationManager.isDedicated(request.getConstraints()) && isDedicated(resource.getAttributes())) { return ImmutableSet.of(Veto.dedicatedHostConstraintMismatch()); } // 2. Host maintenance check. Optional<Veto> maintenanceVeto = getAuroraMaintenanceVeto(resource.getAttributes().getMode()); if (maintenanceVeto.isPresent()) { return maintenanceVeto.asSet(); } Optional<Veto> mesosMaintenanceVeto = getMesosMaintenanceVeto(resource.getUnavailabilityStart()); if (mesosMaintenanceVeto.isPresent()) { return mesosMaintenanceVeto.asSet(); } // 3. Value and limit constraint check. Optional<Veto> constraintVeto = getConstraintVeto(request.getConstraints(), request.getJobState(), resource.getAttributes().getAttributes()); if (constraintVeto.isPresent()) { return constraintVeto.asSet(); } // 4. Resource check (lowest score). return getResourceVetoes(resource.getResourceBag(), request.getResourceBag()); }