List of usage examples for com.google.common.base Optional get
public abstract T get();
From source file:com.facebook.buck.android.ProguardTranslatorFactory.java
private static Optional<Map<String, String>> loadOptionalRawMap(ExecutionContext context, Optional<Path> proguardFullConfigFile, Optional<Path> proguardMappingFile) throws IOException { if (!proguardFullConfigFile.isPresent()) { return Optional.absent(); }/*w w w. j a v a 2 s. c om*/ ProjectFilesystem projectFilesystem = context.getProjectFilesystem(); Path pathToProguardConfig = proguardFullConfigFile.get(); // Proguard doesn't print a mapping when obfuscation is disabled. boolean obfuscationSkipped = Iterables.any(projectFilesystem.readLines(pathToProguardConfig), Predicates.equalTo("-dontobfuscate")); if (obfuscationSkipped) { return Optional.absent(); } List<String> lines = projectFilesystem.readLines(proguardMappingFile.get()); return Optional.of(ProguardMapping.readClassMapping(lines)); }
From source file:org.apache.beam.runners.core.construction.ParDos.java
public static ParDoPayload toProto(ParDo.MultiOutput<?, ?> parDo, SdkComponents components) { DoFnSignature signature = DoFnSignatures.getSignature(parDo.getFn().getClass()); Map<String, StateDeclaration> states = signature.stateDeclarations(); Map<String, TimerDeclaration> timers = signature.timerDeclarations(); List<Parameter> parameters = signature.processElement().extraParameters(); ParDoPayload.Builder builder = ParDoPayload.newBuilder(); builder.setDoFn(toProto(parDo.getFn(), parDo.getMainOutputTag())); for (PCollectionView<?> sideInput : parDo.getSideInputs()) { builder.putSideInputs(sideInput.getTagInternal().getId(), toProto(sideInput)); }//w w w . j av a 2 s .c om for (Parameter parameter : parameters) { Optional<RunnerApi.Parameter> protoParameter = toProto(parameter); if (protoParameter.isPresent()) { builder.addParameters(protoParameter.get()); } } for (Map.Entry<String, StateDeclaration> state : states.entrySet()) { StateSpec spec = toProto(state.getValue()); builder.putStateSpecs(state.getKey(), spec); } for (Map.Entry<String, TimerDeclaration> timer : timers.entrySet()) { TimerSpec spec = toProto(timer.getValue()); builder.putTimerSpecs(timer.getKey(), spec); } return builder.build(); }
From source file:org.dswarm.common.model.util.AttributePathUtil.java
private static Attribute getOrCreateAttribute(final String uri, final Optional<Map<String, Attribute>> optionalAttributeMap) { if (!optionalAttributeMap.isPresent()) { return new Attribute(uri); }//from w w w . j a v a2 s. c o m if (!optionalAttributeMap.get().containsKey(uri)) { optionalAttributeMap.get().put(uri, new Attribute(uri)); } return optionalAttributeMap.get().get(uri); }
From source file:com.twitter.aurora.scheduler.base.Query.java
/** * Checks whether a query is strictly scoped to a specific job. A query is strictly job scoped, * iff it has the role, environment and jobName set. * * @param query Query to test./*from w w w. j a va 2s.c o m*/ * @return {@code true} if the query is strictly job scoped, otherwise {@code false}. */ public static boolean isOnlyJobScoped(Builder query) { Optional<IJobKey> jobKey = JobKeys.from(query); return jobKey.isPresent() && Query.jobScoped(jobKey.get()).equals(query); }
From source file:org.opendaylight.groupbasedpolicy.neutron.ovsdb.util.OvsdbHelper.java
/** * Get the manager node for this bridge node * * @param bridge the bridge node//from w ww . j av a 2 s .c om * @param dataBroker the {@link DataBroker} * @return The {@link OvsdbBridgeAugmentation} for the manager node, null * if not found or if it already is the manager node */ public static OvsdbNodeAugmentation getManagerNode(OvsdbBridgeAugmentation bridge, DataBroker dataBroker) { OvsdbNodeRef bareIId = bridge.getManagedBy(); if (bareIId != null) { if (bareIId.getValue().getTargetType().equals(Node.class)) { ReadWriteTransaction transaction = dataBroker.newReadWriteTransaction(); InstanceIdentifier<Node> iid = (InstanceIdentifier<Node>) bareIId.getValue(); Optional<Node> nodeOptional = readFromDs(LogicalDatastoreType.OPERATIONAL, iid, transaction); if (nodeOptional.isPresent() && nodeOptional.get().getAugmentation(OvsdbNodeAugmentation.class) != null) { return nodeOptional.get().getAugmentation(OvsdbNodeAugmentation.class); } else { LOG.warn("Could not find ovsdb-node for connection for {}", bridge); } } else { LOG.warn("Bridge 'managedBy' non-ovsdb-node. bridge {} getManagedBy() {}", bridge, bareIId.getValue()); } } else { LOG.debug("Bridge 'managedBy' is null. bridge {}", bridge); } return null; }
From source file:org.opendaylight.vpnservice.dhcpservice.DhcpServiceUtils.java
public static String getSegmentationId(Uuid networkId, DataBroker broker) { InstanceIdentifier<Network> inst = InstanceIdentifier.create(Neutron.class).child(Networks.class) .child(Network.class, new NetworkKey(networkId)); Optional<Network> optionalNetwork = MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION, inst); if (!optionalNetwork.isPresent()) { return null; }/*from w w w . ja va 2 s . com*/ Network network = optionalNetwork.get(); String segmentationId = NeutronUtils.getSegmentationIdFromNeutronNetwork(network); return segmentationId; }
From source file:org.deephacks.confit.internal.jpa.JpaBean.java
@SuppressWarnings("unchecked") public static List<Bean> findEager(String schemaName) { Optional<EntityManager> em = getEm(); if (!em.isPresent()) { return new ArrayList<>(); }//ww w .j a v a 2s . c om Query query = em.get().createNamedQuery(FIND_BEANS_FROM_SCHEMA_NAME); query.setParameter(1, schemaName); List<JpaBean> beans = (List<JpaBean>) query.getResultList(); Set<BeanId> ids = new HashSet<>(); for (JpaBean jpaBean : beans) { ids.add(jpaBean.getId()); } return findEager(ids); }
From source file:org.apache.lens.server.common.FormDataMultiPartFactory.java
public static FormDataMultiPart createFormDataMultiPartForQuery(final Optional<LensSessionHandle> sessionId, final Optional<String> query, final Optional<String> operation, final LensConf lensConf, MediaType mt) { final FormDataMultiPart mp = new FormDataMultiPart(); if (sessionId.isPresent()) { mp.bodyPart(getSessionIdFormDataBodyPart(sessionId.get(), mt)); }//from w w w . jav a 2 s . c o m if (query.isPresent()) { mp.bodyPart(getFormDataBodyPart("query", query.get(), mt)); } if (operation.isPresent()) { mp.bodyPart(getFormDataBodyPart("operation", operation.get(), mt)); } mp.bodyPart(getFormDataBodyPart("conf", "conf", lensConf, mt)); return mp; }
From source file:io.crate.analyze.GenericPropertiesConverter.java
public static Settings.Builder settingsFromProperties(Optional<GenericProperties> properties, ParameterContext parameterContext, Map<String, ? extends SettingsApplier> settingAppliers) { Settings.Builder builder = Settings.builder(); setDefaults(settingAppliers, builder); if (properties.isPresent()) { for (Map.Entry<String, Expression> entry : properties.get().properties().entrySet()) { SettingsApplier settingsApplier = settingAppliers.get(entry.getKey()); if (settingsApplier == null) { throw new IllegalArgumentException( String.format(Locale.ENGLISH, "setting '%s' not supported", entry.getKey())); }//from w ww .j a va 2s. co m settingsApplier.apply(builder, parameterContext.parameters(), entry.getValue()); } } return builder; }
From source file:de.azapps.mirakel.helper.DateTimeHelper.java
public static String formatDateTime(final Optional<Calendar> c) { if (c.isPresent()) { return dateTimeFormat.format(c.get().getTime()); } else {//from w w w .j a va 2 s . c o m return null; } }