List of usage examples for com.google.common.base Optional isPresent
public abstract boolean isPresent();
From source file:org.onos.yangtools.yang.model.util.repo.SourceIdentifier.java
/** * Returns filename for this YANG module as specified in RFC 6020. * * Returns filename in format//w w w.ja va2s . c o m * <code>moduleName ['@' revision] '.yang'</code> * * Where Where revision-date is in format YYYY-mm-dd. * * <p> * See * http://tools.ietf.org/html/rfc6020#section-5.2 * * @return Filename for this source identifier. */ public static final String toYangFileName(final String moduleName, final Optional<String> revision) { StringBuilder filename = new StringBuilder(moduleName); if (revision.isPresent()) { filename.append("@"); filename.append(revision.get()); } filename.append(".yang"); return filename.toString(); }
From source file:org.anhonesteffort.flock.crypto.KeyHelper.java
public static void importSaltAndEncryptedKeyMaterial(Context context, String[] saltAndEncryptedKeyMaterial) throws GeneralSecurityException, InvalidMacException, IOException { Log.d(TAG, "IMPORTING ENCRYPTED KEY MATERIAL!"); Optional<String> masterPassphrase = KeyStore.getMasterPassphrase(context); if (!masterPassphrase.isPresent()) throw new InvalidMacException("Passphrase unavailable."); byte[] salt = Base64.decode(saltAndEncryptedKeyMaterial[0]); SecretKey[] masterKeys = KeyUtil.getCipherAndMacKeysForPassphrase(salt, masterPassphrase.get()); SecretKey masterCipherKey = masterKeys[0]; SecretKey masterMacKey = masterKeys[1]; MasterCipher masterCipher = new MasterCipher(masterCipherKey, masterMacKey); byte[] plaintextKeyMaterial = masterCipher.decodeAndDecrypt(saltAndEncryptedKeyMaterial[1].getBytes()); boolean saltLengthValid = salt.length == KeyUtil.SALT_LENGTH_BYTES; boolean keyMaterialLengthValid = plaintextKeyMaterial.length == (KeyUtil.CIPHER_KEY_LENGTH_BYTES + KeyUtil.MAC_KEY_LENGTH_BYTES); if (!saltLengthValid || !keyMaterialLengthValid) throw new GeneralSecurityException( "invalid length on salt or key material >> " + saltLengthValid + " " + keyMaterialLengthValid); byte[] plaintextCipherKey = Arrays.copyOfRange(plaintextKeyMaterial, 0, KeyUtil.CIPHER_KEY_LENGTH_BYTES); byte[] plaintextMacKey = Arrays.copyOfRange(plaintextKeyMaterial, KeyUtil.CIPHER_KEY_LENGTH_BYTES, KeyUtil.CIPHER_KEY_LENGTH_BYTES + KeyUtil.MAC_KEY_LENGTH_BYTES); KeyStore.saveEncryptedKeyMaterial(context, saltAndEncryptedKeyMaterial[1]); KeyStore.saveKeyMaterialSalt(context, salt); KeyStore.saveCipherKey(context, plaintextCipherKey); KeyStore.saveMacKey(context, plaintextMacKey); }
From source file:com.dangdang.ddframe.job.lite.lifecycle.internal.reg.RegistryCenterFactory.java
/** * ./*from ww w .java2s .com*/ * * @param connectString * @param namespace ?? * @param digest ? * @return */ public static CoordinatorRegistryCenter createCoordinatorRegistryCenter(final String connectString, final String namespace, final Optional<String> digest) { Hasher hasher = Hashing.md5().newHasher().putString(connectString, Charsets.UTF_8).putString(namespace, Charsets.UTF_8); if (digest.isPresent()) { hasher.putString(digest.get(), Charsets.UTF_8); } HashCode hashCode = hasher.hash(); CoordinatorRegistryCenter result = REG_CENTER_REGISTRY.get(hashCode); if (null != result) { return result; } ZookeeperConfiguration zkConfig = new ZookeeperConfiguration(connectString, namespace); if (digest.isPresent()) { zkConfig.setDigest(digest.get()); } result = new ZookeeperRegistryCenter(zkConfig); result.init(); REG_CENTER_REGISTRY.put(hashCode, result); return result; }
From source file:google.registry.keyring.api.PgpHelper.java
/** * Search for public key on keyring based on a substring (like an email address). * * @throws VerifyException if the key couldn't be found. * @see #lookupKeyPair/* w ww. j a va 2 s . c o m*/ */ public static PGPPublicKey lookupPublicKey(PGPPublicKeyRingCollection keyring, String query, KeyRequirement want) { try { // Safe by specification. @SuppressWarnings("unchecked") Iterator<PGPPublicKeyRing> results = keyring.getKeyRings(checkNotNull(query, "query"), true, true); verify(results.hasNext(), "No public key found matching substring: %s", query); while (results.hasNext()) { Optional<PGPPublicKey> result = lookupPublicSubkey(results.next(), want); if (result.isPresent()) { return result.get(); } } throw new VerifyException( String.format("No public key (%s) found matching substring: %s", want, query)); } catch (PGPException e) { throw new VerifyException( String.format("Public key lookup with query %s failed: %s", query, e.getMessage())); } }
From source file:org.locationtech.geogig.test.integration.remoting.RemotesIndexTestSupport.java
public static List<Ref> getBranches(Repository repo, Optional<String> branch) { List<Ref> branches; if (branch.isPresent()) { Optional<Ref> r = repo.command(RefParse.class).setName(branch.get()).call(); if (r.isPresent()) { branches = Collections.singletonList(r.get()); } else {//from www .j a v a2s.c o m return Collections.emptyList(); } } else { branches = repo.command(BranchListOp.class).call(); } return branches; }
From source file:net.caseif.flint.steel.util.helper.ChatHelper.java
public static boolean isTeamBarrierPresent(Player sender, Player recipient) { Optional<Challenger> senderCh = SteelCore.getChallenger(sender.getUniqueId()); Optional<Challenger> recipCh = SteelCore.getChallenger(recipient.getUniqueId()); if (senderCh.isPresent() && recipCh.isPresent()) { if (senderCh.get().getRound() == recipCh.get().getRound()) { if (senderCh.get().getRound().getConfigValue(ConfigNode.SEPARATE_TEAM_CHATS)) { return true; }//w w w.j a v a 2 s .com } } return false; }
From source file:net.caseif.flint.steel.util.helper.ChatHelper.java
public static boolean isSpectatorBarrierPresent(Player sender, Player recipient) { Optional<Challenger> senderCh = SteelCore.getChallenger(sender.getUniqueId()); Optional<Challenger> recipCh = SteelCore.getChallenger(recipient.getUniqueId()); if (senderCh.isPresent()) { if (senderCh.get().isSpectating() && senderCh.get().getRound().getConfigValue(ConfigNode.WITHHOLD_SPECTATOR_CHAT)) { return !(recipCh.isPresent() && recipCh.get().getRound() == senderCh.get().getRound() && recipCh.get().isSpectating()); }//from ww w . j a va2 s.c om } return false; }
From source file:org.eclipse.buildship.ui.view.task.TaskViewContentProvider.java
private static boolean isIncludedProject(Optional<IProject> workspaceProject, OmniEclipseProject modelProject) { if (!workspaceProject.isPresent()) { return false; }//www.j a v a 2s.c o m Optional<ProjectConfiguration> configuration = CorePlugin.projectConfigurationManager() .tryReadProjectConfiguration(workspaceProject.get()); if (!configuration.isPresent()) { return false; } File projectDirectory = modelProject.getProjectIdentifier().getBuildIdentifier().getRootDir(); return !projectDirectory.equals(configuration.get().getRootProjectDirectory()); }
From source file:com.voxelplugineering.voxelsniper.sponge.util.SpongeUtilities.java
/** * Gets an instance of a Gunsmith {@link Location} corresponding to the given sponge location. * //from ww w .j a v a2 s. co m * @param location The location * @return The gunsmith location */ public static Optional<Location> fromSpongeLocation(org.spongepowered.api.world.Location location, WorldRegistry<org.spongepowered.api.world.World> worlds) { if (location.getExtent() instanceof World) { Optional<World> world = worlds .getWorld(((org.spongepowered.api.world.World) location.getExtent()).getName()); if (!world.isPresent()) { return Optional.absent(); } com.flowpowered.math.vector.Vector3d position = location.getPosition(); return Optional.<Location>of( new CommonLocation(world.get(), position.getX(), position.getY(), position.getZ())); } return Optional.absent(); }
From source file:com.google.errorprone.bugpatterns.threadsafety.GuardedByUtils.java
public static GuardedByValidationResult isGuardedByValid(Tree tree, VisitorState state) { String guard = GuardedByUtils.getGuardValue(tree); if (guard == null) { return GuardedByValidationResult.ok(); }/*from w ww . j a v a 2s. c o m*/ Optional<GuardedByExpression> boundGuard = GuardedByBinder.bindString(guard, GuardedBySymbolResolver.from(tree, state)); if (!boundGuard.isPresent()) { return GuardedByValidationResult.invalid("could not resolve guard"); } Symbol treeSym = ASTHelpers.getSymbol(tree); if (treeSym == null) { // this shouldn't happen unless the compilation had already failed. return GuardedByValidationResult.ok(); } boolean staticGuard = boundGuard.get().kind() == GuardedByExpression.Kind.CLASS_LITERAL || (boundGuard.get().sym() != null && boundGuard.get().sym().isStatic()); if (treeSym.isStatic() && !staticGuard) { return GuardedByValidationResult.invalid("static member guarded by instance"); } return GuardedByValidationResult.ok(); }