List of usage examples for com.google.common.base Optional isPresent
public abstract boolean isPresent();
From source file:springfox.bean.validators.plugins.Validators.java
private static <T extends Annotation> Optional<T> findAnnotation( Optional<? extends AnnotatedElement> annotatedElement, Class<T> annotationType) { if (annotatedElement.isPresent()) { return Optional.fromNullable(AnnotationUtils.findAnnotation(annotatedElement.get(), annotationType)); } else {/*from ww w .j a v a2s . co m*/ return Optional.absent(); } }
From source file:extrabiomes.module.fabrica.scarecrow.ItemScarecrow.java
private static boolean spawnCreature(World world, double x, double y, double z) { //{/*from www . jav a2s . co m*/ final Optional<Entity> entity = Optional.fromNullable(EntityList.createEntityByName(NAME, world)); if (entity.isPresent()) { entity.get().setLocationAndAngles(x, y, z, world.rand.nextFloat() * 360.0F, 0.0F); world.spawnEntityInWorld(entity.get()); } return entity.isPresent(); //} }
From source file:org.anhonesteffort.flock.sync.account.AccountStore.java
public static void setCardInformation(Context context, Optional<FlockCardInformation> cardInformation) { if (cardInformation.isPresent()) { getStore(context).edit()/*from ww w .j ava 2 s . c om*/ .putString(KEY_CARD_INFORMATION_ACCOUNT_ID, cardInformation.get().getAccountId()) .putString(KEY_CARD_INFORMATION_LAST_FOUR, cardInformation.get().getCardLastFour()) .putString(KEY_CARD_INFORMATION_EXPIRATION, cardInformation.get().getCardExpiration()).apply(); } else { getStore(context).edit().putString(KEY_CARD_INFORMATION_ACCOUNT_ID, null) .putString(KEY_CARD_INFORMATION_LAST_FOUR, null) .putString(KEY_CARD_INFORMATION_EXPIRATION, null).apply(); } }
From source file:gobblin.hive.HiveMetaStoreClientFactory.java
private static HiveConf getHiveConf(Optional<String> hcatURI) { HiveConf hiveConf = new HiveConf(); if (hcatURI.isPresent() && StringUtils.isNotBlank(hcatURI.get())) { hiveConf.setVar(HiveConf.ConfVars.METASTOREURIS, hcatURI.get()); hiveConf.set(HIVE_METASTORE_TOKEN_SIGNATURE, hcatURI.get()); }//from w w w . j a v a 2s . co m return hiveConf; }
From source file:de.azapps.tools.OptionalUtils.java
@Nullable public static <F, V> V withOptional(@NonNull final Optional<F> optional, @NonNull final Function<F, V> function, final V alternative) { if (optional.isPresent()) { return function.apply(optional.get()); } else {//from w w w .j a v a2 s . c o m return alternative; } }
From source file:org.apache.aurora.scheduler.updater.InstanceUpdater.java
private static boolean isTaskPresent(Optional<IScheduledTask> task) { return task.isPresent() && !isPermanentlyKilled(task.get()); }
From source file:org.apache.gobblin.service.modules.spec.JobExecutionPlanDagFactory.java
/** * The job name is derived from the {@link org.apache.gobblin.runtime.api.JobTemplate} URI. It is the * simple name of the path component of the URI. * @param jobExecutionPlan//w w w .j a v a 2 s. c o m * @return the simple name from the URI path. */ private static String getJobName(JobExecutionPlan jobExecutionPlan) { Optional<URI> jobTemplateUri = jobExecutionPlan.getJobSpec().getTemplateURI(); if (jobTemplateUri.isPresent()) { return Files.getNameWithoutExtension(new Path(jobTemplateUri.get()).getName()); } else { return null; } }
From source file:org.fusesource.fabric.service.jclouds.functions.ToTemplate.java
public static Template apply(CreateJCloudsContainerOptions options) { ComputeService service = options.getComputeService(); TemplateOptions templateOptions = service.templateOptions(); TemplateBuilder builder = service.templateBuilder().any(); applyInstanceType(builder, options); applyImageType(builder, options);/*from ww w . j a v a2 s .c om*/ applyLocation(builder, options); applyProviderSpecificOptions(templateOptions, options); Optional<AdminAccess> adminAccess = ToAdminAccess.apply(options); if (adminAccess.isPresent()) { templateOptions.runScript(adminAccess.get()); } builder = builder.options(templateOptions); return builder.build(); }
From source file:gobblin.compaction.event.CompactionSlaEventHelper.java
private static long getRecordCount(Optional<Job> job) { if (!job.isPresent()) { return -1l; }/* www. j ava 2 s . com*/ Counters counters = null; try { counters = job.get().getCounters(); } catch (IOException e) { LOG.debug("Failed to get job counters. Record count will not be set. ", e); return -1l; } Counter recordCounter = counters.findCounter(AvroKeyDedupReducer.EVENT_COUNTER.RECORD_COUNT); if (recordCounter != null && recordCounter.getValue() != 0) { return recordCounter.getValue(); } recordCounter = counters.findCounter(AvroKeyMapper.EVENT_COUNTER.RECORD_COUNT); if (recordCounter != null && recordCounter.getValue() != 0) { return recordCounter.getValue(); } LOG.debug("Non zero record count not found in both mapper and reducer counters"); return -1l; }
From source file:org.anhonesteffort.flock.AccountAndKeyRequiredActivity.java
protected static DavAccount handleGetAccountOrFail(Activity activity) { Intent nextIntent;//from ww w. j a v a 2 s. c o m Optional<DavAccount> davAccount = DavAccountHelper.getAccount(activity); if (!davAccount.isPresent()) { if (!DavAccountHelper.isAccountRegistered(activity)) { Log.w(TAG, "dav account missing and account not registered, directing to setup activity"); nextIntent = new Intent(activity, SetupActivity.class); nextIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); } else { Log.w(TAG, "dav account missing and account is registered, directing to correct password"); nextIntent = new Intent(activity, CorrectPasswordActivity.class); nextIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); Toast.makeText(activity, R.string.error_password_unavailable_please_login, Toast.LENGTH_SHORT) .show(); } activity.startActivity(nextIntent); activity.finish(); return null; } else return davAccount.get(); }