/** * [PDI-15575] Ensuring that this enum can return with some default value. Necessary for when being used on the * GUI side if a user leaves the field empty, it will enforce a default value. This allows the object to be saved, * loaded, and cloned as necessary. * @param contentType * @return ContentType */ public static ContentType getIfPresent( String contentType ) { return Enums.getIfPresent( ContentType.class, contentType ).or( Element ); } }
private static Optional<TimeUnit> getTimeUnit(ExpressionTree timeUnit) { if (timeUnit instanceof IdentifierTree) { // e.g., SECONDS return Enums.getIfPresent(TimeUnit.class, ((IdentifierTree) timeUnit).getName().toString()); } if (timeUnit instanceof MemberSelectTree) { // e.g., TimeUnit.SECONDS return Enums.getIfPresent( TimeUnit.class, ((MemberSelectTree) timeUnit).getIdentifier().toString()); } return Optional.absent(); } }
private static Optional<Deserializers> getDeserializerType(Properties props) { Preconditions.checkArgument(props.containsKey(KAFKA_DESERIALIZER_TYPE), "Missing required property " + KAFKA_DESERIALIZER_TYPE); return Enums.getIfPresent(Deserializers.class, props.getProperty(KAFKA_DESERIALIZER_TYPE).toUpperCase()); }
/** * Return the {@link TaskSchedulerType} with the specified name. If the specified name * does not map to a {@link TaskSchedulerType}, then {@link #SCHEDULEDEXECUTORSERVICE} * will be returned. * * @param name the name of the {@link TaskSchedulerType} * @return the specified {@link TaskSchedulerType} or {@link #SCHEDULEDEXECUTORSERVICE} */ public static TaskSchedulerType parse(String name) { if (StringUtils.isEmpty(name)) { return SCHEDULEDEXECUTORSERVICE; } return Enums.getIfPresent(TaskSchedulerType.class, name.toUpperCase()).or(SCHEDULEDEXECUTORSERVICE); } }
/** * Get the devliery semantics type from {@link ConfigurationKeys#DELIVERY_SEMANTICS}. * The default value is {@link Type#AT_LEAST_ONCE}. */ public static DeliverySemantics parse(State state) { String value = state.getProp(ConfigurationKeys.GOBBLIN_RUNTIME_DELIVERY_SEMANTICS, AT_LEAST_ONCE.toString()).toUpperCase(); Optional<DeliverySemantics> semantics = Enums.getIfPresent(DeliverySemantics.class, value); Preconditions.checkState(semantics.isPresent(), value + " is not a valid delivery semantics"); return semantics.get(); } }
public void testGetIfPresent_caseSensitive() { assertThat(Enums.getIfPresent(TestEnum.class, "cHEETO")).isAbsent(); assertThat(Enums.getIfPresent(TestEnum.class, "Honda")).isAbsent(); assertThat(Enums.getIfPresent(TestEnum.class, "poodlE")).isAbsent(); }
public void testGetIfPresent() { assertThat(Enums.getIfPresent(TestEnum.class, "CHEETO")).hasValue(TestEnum.CHEETO); assertThat(Enums.getIfPresent(TestEnum.class, "HONDA")).hasValue(TestEnum.HONDA); assertThat(Enums.getIfPresent(TestEnum.class, "POODLE")).hasValue(TestEnum.POODLE); assertThat(Enums.getIfPresent(TestEnum.class, "CHEETO")).isPresent(); assertThat(Enums.getIfPresent(TestEnum.class, "HONDA")).isPresent(); assertThat(Enums.getIfPresent(TestEnum.class, "POODLE")).isPresent(); assertThat(Enums.getIfPresent(TestEnum.class, "CHEETO")).hasValue(TestEnum.CHEETO); assertThat(Enums.getIfPresent(TestEnum.class, "HONDA")).hasValue(TestEnum.HONDA); assertThat(Enums.getIfPresent(TestEnum.class, "POODLE")).hasValue(TestEnum.POODLE); }
/** * Refer to {@link MRCompactorAvroKeyDedupJobRunner#getDedupKeyOption()} */ private MRCompactorAvroKeyDedupJobRunner.DedupKeyOption getDedupKeyOption() { if (!this.state.contains(MRCompactorAvroKeyDedupJobRunner.COMPACTION_JOB_DEDUP_KEY)) { return MRCompactorAvroKeyDedupJobRunner.DEFAULT_DEDUP_KEY_OPTION; } Optional<MRCompactorAvroKeyDedupJobRunner.DedupKeyOption> option = Enums.getIfPresent(MRCompactorAvroKeyDedupJobRunner.DedupKeyOption.class, this.state.getProp(MRCompactorAvroKeyDedupJobRunner.COMPACTION_JOB_DEDUP_KEY).toUpperCase()); return option.isPresent() ? option.get() : MRCompactorAvroKeyDedupJobRunner.DEFAULT_DEDUP_KEY_OPTION; }
public void testGetIfPresent_whenNoMatchingConstant() { assertThat(Enums.getIfPresent(TestEnum.class, "WOMBAT")).isAbsent(); }
/** Implementation variation to use, or all if unset. */ Optional<Implementation> implementation() { return Optional.ofNullable(Enums.getIfPresent(Implementation.class, System.getProperty("implementation", "")).orNull()); }
private static DatePartitionType getGranularity(State state, int numBranches, int branchId) { String propName = ForkOperatorUtils.getPropertyNameForBranch(WRITER_PARTITION_GRANULARITY, numBranches, branchId); String granularityValue = state.getProp(propName, DEFAULT_WRITER_PARTITION_GRANULARITY.toString()); Optional<DatePartitionType> granularity = Enums.getIfPresent(DatePartitionType.class, granularityValue.toUpperCase()); Preconditions.checkState(granularity.isPresent(), granularityValue + " is not a valid writer partition granularity"); return granularity.get(); }
/** The key reference combination to use, or all if unset. */ Optional<ReferenceType> keys() { return Optional.ofNullable(Enums.getIfPresent(ReferenceType.class, System.getProperty("keys", "").toUpperCase()).orNull()); }
/** Indicates if statistics should be used, both if unset */ Optional<Stats> stats() { return Optional.ofNullable(Enums.getIfPresent(Stats.class, System.getProperty("stats", "").toUpperCase()).orNull()); }
/** The value reference combination to use, or all if unset. */ Optional<ReferenceType> values() { return Optional.ofNullable(Enums.getIfPresent(ReferenceType.class, System.getProperty("values", "").toUpperCase()).orNull()); } }
/** * Get the {@link LauncherTypeEnum} for this {@link JobState}. */ public LauncherTypeEnum getLauncherType() { return Enums.getIfPresent(LauncherTypeEnum.class, this.getProp(ConfigurationKeys.JOB_LAUNCHER_TYPE_KEY, JobLauncherFactory.JobLauncherType.LOCAL.name())) .or(LauncherTypeEnum.LOCAL); }
/** Compute indicates if an async or sync cache variation should be use, or both if unset. */ Optional<Compute> compute() { return Optional.ofNullable(Enums.getIfPresent(Compute.class, System.getProperty("compute", "").toUpperCase()).orNull()); }
public static KafkaWorkUnitPacker getInstance(AbstractSource<?, ?> source, SourceState state) { if (state.contains(KAFKA_WORKUNIT_PACKER_TYPE)) { String packerTypeStr = state.getProp(KAFKA_WORKUNIT_PACKER_TYPE); Optional<PackerType> packerType = Enums.getIfPresent(PackerType.class, packerTypeStr); if (packerType.isPresent()) { return getInstance(packerType.get(), source, state); } throw new IllegalArgumentException("WorkUnit packer type " + packerTypeStr + " not found"); } return getInstance(DEFAULT_PACKER_TYPE, source, state); }
private DedupKeyOption getDedupKeyOption() { if (!this.dataset.jobProps().contains(COMPACTION_JOB_DEDUP_KEY)) { return DEFAULT_DEDUP_KEY_OPTION; } Optional<DedupKeyOption> option = Enums.getIfPresent(DedupKeyOption.class, this.dataset.jobProps().getProp(COMPACTION_JOB_DEDUP_KEY).toUpperCase()); return option.isPresent() ? option.get() : DEFAULT_DEDUP_KEY_OPTION; }
private KafkaWorkUnitSizeEstimator getWorkUnitSizeEstimator() { if (this.state.contains(KAFKA_WORKUNIT_SIZE_ESTIMATOR_TYPE)) { String sizeEstimatorTypeString = this.state.getProp(KAFKA_WORKUNIT_SIZE_ESTIMATOR_TYPE); Optional<SizeEstimatorType> sizeEstimatorType = Enums.getIfPresent(SizeEstimatorType.class, sizeEstimatorTypeString); if (sizeEstimatorType.isPresent()) { return getWorkUnitSizeEstimator(sizeEstimatorType.get()); } throw new IllegalArgumentException("WorkUnit size estimator type " + sizeEstimatorType + " not found"); } return getWorkUnitSizeEstimator(DEFAULT_SIZE_ESTIMATOR_TYPE); }
@GwtIncompatible // weak references private WeakReference<?> doTestClassUnloading() throws Exception { URLClassLoader shadowLoader = new URLClassLoader(getClassPathUrls(), null); @SuppressWarnings("unchecked") Class<TestEnum> shadowTestEnum = (Class<TestEnum>) Class.forName(TestEnum.class.getName(), false, shadowLoader); assertNotSame(shadowTestEnum, TestEnum.class); // We can't write Set<TestEnum> because that is a Set of the TestEnum from the original // ClassLoader. Set<Object> shadowConstants = new HashSet<>(); for (TestEnum constant : TestEnum.values()) { Optional<TestEnum> result = Enums.getIfPresent(shadowTestEnum, constant.name()); assertThat(result).isPresent(); shadowConstants.add(result.get()); } assertEquals(ImmutableSet.<Object>copyOf(shadowTestEnum.getEnumConstants()), shadowConstants); Optional<TestEnum> result = Enums.getIfPresent(shadowTestEnum, "blibby"); assertThat(result).isAbsent(); return new WeakReference<>(shadowLoader); }