List of usage examples for com.google.common.base Optional isPresent
public abstract boolean isPresent();
From source file:org.apache.gobblin.hive.HiveSerDeManager.java
/** * Get an instance of {@link HiveSerDeManager}. * * @param type The {@link HiveSerDeManager} type. It should be either AVRO, or the name of a class that implements * {@link HiveSerDeManager}. The specified {@link HiveSerDeManager} type must have a constructor that takes a * {@link State} object./* www .java 2s . com*/ * @param props A {@link State} object. To get a specific implementation of {@link HiveSerDeManager}, specify either * one of the values in {@link Implementation} (e.g., AVRO) or the name of a class that implements * {@link HiveSerDeManager} in property {@link #HIVE_ROW_FORMAT}. The {@link State} object is also used to * instantiate the {@link HiveSerDeManager}. */ public static HiveSerDeManager get(State props) { String type = props.getProp(HIVE_ROW_FORMAT, Implementation.AVRO.name()); Optional<Implementation> implementation = Enums.getIfPresent(Implementation.class, type.toUpperCase()); try { if (implementation.isPresent()) { return (HiveSerDeManager) ConstructorUtils .invokeConstructor(Class.forName(implementation.get().toString()), props); } return (HiveSerDeManager) ConstructorUtils.invokeConstructor(Class.forName(type), props); } catch (ReflectiveOperationException e) { throw new RuntimeException( "Unable to instantiate " + HiveSerDeManager.class.getSimpleName() + " with type " + type, e); } }
From source file:org.opendaylight.controller.md.sal.binding.impl.BindingStructuralType.java
static BindingStructuralType from(final DataTreeCandidateNode domChildNode) { final Optional<NormalizedNode<?, ?>> dataBased = domChildNode.getDataAfter() .or(domChildNode.getDataBefore()); if (dataBased.isPresent()) { return from(dataBased.get()); }//from w w w . j a v a 2s .c o m return from(domChildNode.getIdentifier()); }
From source file:org.opendaylight.distributed.tx.impl.RollbackImpl.java
private static ModifyAction getRevertAction(final ModifyAction operation, final Optional<DataObject> data) { switch (operation) { case MERGE: { return data.isPresent() ? ModifyAction.REPLACE : ModifyAction.DELETE; }//from w w w.j a v a 2 s. c o m case REPLACE: { return data.isPresent() ? ModifyAction.REPLACE : ModifyAction.DELETE; } case DELETE: return data.isPresent() ? ModifyAction.REPLACE : ModifyAction.NONE; } throw new IllegalStateException("Unexpected operation: " + operation); }
From source file:org.blockartistry.mod.ThermalRecycling.data.RecipeHelper.java
/** * Adds the given recipe to the tracking tables. It assumes control over * output./*w w w . j a va2 s . co m*/ */ public static int put(final ItemStack input, List<ItemStack> output) { assert input != null; assert output != null; int retCode = DUPLICATE; // See if we have an existing mapping final RecipeData result = ItemRegistry.getRecipe(input); // Use the incoming recipe if: // * It doesn't exist // * Existing entry is wildcard and the new one isn't // * The new entry has a quantity greater than the existing one if (result == RecipeData.EPHEMERAL || (result.isGeneric() && !OreDictionaryHelper.isGeneric(input)) || (input.stackSize > result.getMinimumInputQuantityRequired())) { final ItemStack stack = input.copy(); // An immutable list has already been processed by // something like RecipeDecomposition if (!(output instanceof ImmutableList)) { // Traverse the list replacing WILDCARD stacks with concrete // ones. The logic prefers Thermal Foundation equivalents // if found. for (int i = 0; i < output.size(); i++) { ItemStack working = output.get(i); if (OreDictionaryHelper.isGeneric(working)) { final String oreName = OreDictionaryHelper.getOreName(working); if (oreName != null) { final Optional<ItemStack> t = ItemStackHelper.getItemStack(oreName, working.stackSize); if (t.isPresent()) output.set(i, t.get()); } } } output = ImmutableList.copyOf(InventoryHelper.coelece(output)); } ItemRegistry.setRecipe(stack, new RecipeData(stack, output)); retCode = SUCCESS; } return retCode; }
From source file:org.opendaylight.groupbasedpolicy.renderer.iovisor.utils.IovisorModuleUtils.java
/** * Make sure the specified IOvisor module Uri exists in the datastore. * @param dataBroker An instance of the {@link DataBroker} * @param iovisorModuleUri The Uri of the {@link IovisorModule} we want to validate * @return <code>true</code> if validated, else, <code>false</code> */// w w w . ja v a 2s . c o m public static boolean validateIovisorModuleInstance(DataBroker dataBroker, Uri iovisorModuleUri) { Optional<IovisorModuleInstances> res = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION, IovisorIidFactory.iovisorModuleInstanceWildCardIid(), dataBroker.newReadOnlyTransaction()); if (res.isPresent()) { for (IovisorModuleInstance instance : res.get().getIovisorModuleInstance()) { if (instance.getUri().equals(iovisorModuleUri)) { return true; } } } return false; }
From source file:org.opendaylight.bier.driver.common.util.DataGetter.java
public static <T extends DataObject> T readData(DataBroker dataBroker, InstanceIdentifier<T> path) { T data = null;//from w w w . j ava 2s . c om final ReadOnlyTransaction transaction = dataBroker.newReadOnlyTransaction(); Optional<T> optionalData; try { optionalData = transaction.read(LogicalDatastoreType.CONFIGURATION, path).checkedGet(); if (optionalData.isPresent()) { data = optionalData.get(); } else { LOG.debug("{}: Failed to read {}", Thread.currentThread().getStackTrace()[1], path); } } catch (ReadFailedException e) { LOG.warn("Failed to read {} ", path, e); } transaction.close(); return data; }
From source file:org.apache.rya.indexing.pcj.fluo.app.query.StatementPatternIdManager.java
/** * Add specified Set of ids to the Fluo table with Column {@link FluoQueryColumns#STATEMENT_PATTERN_IDS}. Also * updates the hash of the updated nodeId Set and writes that to the Column * {@link FluoQueryColumns#STATEMENT_PATTERN_IDS_HASH} * * @param tx - Fluo Transaction object for performing atomic operations on Fluo table. * @param ids - ids to add to the StatementPattern nodeId Set *///from ww w. ja v a2 s. c om public static void addStatementPatternIds(TransactionBase tx, Set<String> ids) { checkNotNull(tx); checkNotNull(ids); Optional<Bytes> val = Optional.fromNullable(tx.get(Bytes.of(STATEMENT_PATTERN_ID), STATEMENT_PATTERN_IDS)); StringBuilder builder = new StringBuilder(); if (val.isPresent()) { builder.append(val.get().toString()); builder.append(VAR_DELIM); } String idString = builder.append(Joiner.on(VAR_DELIM).join(ids)).toString(); tx.set(Bytes.of(STATEMENT_PATTERN_ID), STATEMENT_PATTERN_IDS, Bytes.of(idString)); tx.set(Bytes.of(STATEMENT_PATTERN_ID), STATEMENT_PATTERN_IDS_HASH, Bytes.of(Hashing.sha256().hashString(idString).toString())); }
From source file:org.anhonesteffort.flock.crypto.KeyHelper.java
public static boolean masterPassphraseIsValid(Context context) throws GeneralSecurityException, IOException { Optional<String> masterPassphrase = KeyStore.getMasterPassphrase(context); if (!masterPassphrase.isPresent()) return false; Optional<String> encryptedKeyMaterial = KeyStore.getEncryptedKeyMaterial(context); if (!encryptedKeyMaterial.isPresent()) throw new GeneralSecurityException("Where did my key material go! XXX!!!!"); Optional<byte[]> salt = KeyStore.getKeyMaterialSalt(context); if (!salt.isPresent()) throw new GeneralSecurityException("Where did my salt go! XXX!!!!"); SecretKey[] masterKeys = KeyUtil.getCipherAndMacKeysForPassphrase(salt.get(), masterPassphrase.get()); SecretKey masterCipherKey = masterKeys[0]; SecretKey masterMacKey = masterKeys[1]; MasterCipher masterCipher = new MasterCipher(masterCipherKey, masterMacKey); try {/*from ww w .j a v a 2 s . c om*/ masterCipher.decodeAndDecrypt(encryptedKeyMaterial.get()); } catch (InvalidMacException e) { return false; } return true; }
From source file:org.opendaylight.groupbasedpolicy.neutron.ovsdb.util.EndpointHelper.java
/** * Look up the {@link Endpoint} from the Endpoint Registry. * * @param epKey The {@link EndpointKey} to look up * @param transaction The {@link ReadOnlyTransaction} * @return The corresponding {@link Endpoint}, null if not found *//*from w ww . j a va 2s .co m*/ public static Endpoint lookupEndpoint(EndpointKey epKey, ReadOnlyTransaction transaction) { Optional<Endpoint> optionalEp = readFromDs(LogicalDatastoreType.OPERATIONAL, endpointIid(epKey.getL2Context(), epKey.getMacAddress()), transaction); if (optionalEp.isPresent()) { return optionalEp.get(); } return null; }
From source file:org.apache.isis.viewer.restfulobjects.server.mappers.ExceptionMapperAbstract.java
private static String messageFor(final Throwable ex) { final List<Throwable> chain = Throwables.getCausalChain(ex); final Optional<RecoverableException> recoverableIfAny = FluentIterable.from(chain) .filter(RecoverableException.class).first(); return (recoverableIfAny.isPresent() ? recoverableIfAny.get() : ex).getMessage(); }