com.google.common.base.Enums Java Examples
The following examples show how to use
com.google.common.base.Enums.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HiveSerDeManager.java From incubator-gobblin with Apache License 2.0 | 6 votes |
/** * Get an instance of {@link HiveSerDeManager}. * * @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 ORC) 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); } }
Example #2
Source File: DefaultTrackerImportService.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
private <T extends Enum<T>> T getEnumWithDefault( Class<T> enumKlass, Map<String, List<String>> parameters, String key, T defaultValue ) { if ( parameters == null || parameters.get( key ) == null || parameters.get( key ).isEmpty() ) { return defaultValue; } if ( TrackerIdScheme.class.equals( enumKlass ) && IdScheme.isAttribute( parameters.get( key ).get( 0 ) ) ) { return Enums.getIfPresent( enumKlass, "ATTRIBUTE" ).orNull(); } String value = String.valueOf( parameters.get( key ).get( 0 ) ); return Enums.getIfPresent( enumKlass, value ).or( defaultValue ); }
Example #3
Source File: JobLauncherFactory.java From incubator-gobblin with Apache License 2.0 | 6 votes |
/** * Creates a new instance for a JobLauncher with a given type * @param sysProps the system/environment properties * @param jobProps the job properties * @param launcherTypeValue the type of the launcher; either a {@link JobLauncherType} value or * the name of the class that extends {@link AbstractJobLauncher} and has a constructor * that has a single Properties parameter.. * @param metadataTags additional metadata to be added to timing events * @return the JobLauncher instance * @throws RuntimeException if the instantiation fails */ public static JobLauncher newJobLauncher(Properties sysProps, Properties jobProps, String launcherTypeValue, SharedResourcesBroker<GobblinScopeTypes> instanceBroker, List<? extends Tag<?>> metadataTags) { Optional<JobLauncherType> launcherType = Enums.getIfPresent(JobLauncherType.class, launcherTypeValue); try { if (launcherType.isPresent()) { switch (launcherType.get()) { case LOCAL: return new LocalJobLauncher(JobConfigurationUtils.combineSysAndJobProperties(sysProps, jobProps), instanceBroker, metadataTags); case MAPREDUCE: return new MRJobLauncher(JobConfigurationUtils.combineSysAndJobProperties(sysProps, jobProps), instanceBroker, metadataTags); default: throw new RuntimeException("Unsupported job launcher type: " + launcherType.get().name()); } } @SuppressWarnings("unchecked") Class<? extends AbstractJobLauncher> launcherClass = (Class<? extends AbstractJobLauncher>) Class.forName(launcherTypeValue); return launcherClass.getDeclaredConstructor(Properties.class) .newInstance(JobConfigurationUtils.combineSysAndJobProperties(sysProps, jobProps)); } catch (Exception e) { throw new RuntimeException("Failed to create job launcher: " + e, e); } }
Example #4
Source File: QueryUtils.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Try and parse `value` as Enum. Throws `QueryException` if invalid value. * * @param klass the Enum class. * @param value the enum value. */ @SuppressWarnings( { "unchecked", "rawtypes" } ) public static <T> T getEnumValue( Class<T> klass, String value ) { Optional<? extends Enum<?>> enumValue = Enums.getIfPresent( (Class<? extends Enum>) klass, value ); if ( enumValue.isPresent() ) { return (T) enumValue.get(); } else { Object[] possibleValues = klass.getEnumConstants(); throw new QueryParserException( "Unable to parse `" + value + "` as `" + klass + "`, available values are: " + Arrays.toString( possibleValues ) ); } }
Example #5
Source File: EncryptionConfig.java From incubator-gobblin with Apache License 2.0 | 6 votes |
private void validate(String encryptionLevel, String encryptedFields) throws IOException { if (!Enums.getIfPresent(EncryptionLevel.class, encryptionLevel.toUpperCase()).isPresent()) { throw new IOException("Invalid encryption level " + encryptionLevel); } switch (EncryptionLevel.valueOf(encryptionLevel.toUpperCase())) { case FIELD: if ((encryptedFields.equalsIgnoreCase(DatasetDescriptorConfigKeys.DATASET_DESCRIPTOR_CONFIG_ANY)) || (encryptedFields.equalsIgnoreCase(DatasetDescriptorConfigKeys.DATASET_DESCRIPTOR_CONFIG_NONE))) { log.error("Invalid input for encryptedFields {}", encryptedFields); throw new IOException("Invalid encryptedFields"); } break; case NONE: if (!encryptedFields.equalsIgnoreCase(DatasetDescriptorConfigKeys.DATASET_DESCRIPTOR_CONFIG_NONE)) { log.error("Invalid input for encryptedFields {}", encryptedFields); throw new IOException("Invalid encryptedFields"); } break; default: break; } return; }
Example #6
Source File: CmTemplateProcessor.java From cloudbreak with Apache License 2.0 | 6 votes |
private <T extends Enum<T>> Set<String> getRecommendationByBlacklist(Class<T> enumClass, boolean emptyServiceListBlacklisted) { Map<String, Set<String>> componentsByHostGroup = getNonGatewayComponentsByHostGroup(); Set<String> recos = new HashSet<>(); for (Entry<String, Set<String>> hostGroupServices : componentsByHostGroup.entrySet()) { if (emptyServiceListBlacklisted && hostGroupServices.getValue().isEmpty()) { continue; } boolean foundBlackListItem = false; for (String service : hostGroupServices.getValue()) { if (Enums.getIfPresent(enumClass, service).isPresent()) { foundBlackListItem = true; break; } } if (!foundBlackListItem) { recos.add(hostGroupServices.getKey()); } } return recos; }
Example #7
Source File: EnumsExample.java From levelup-java-examples with Apache License 2.0 | 6 votes |
@Test public void transform_string_to_enum () { List<String> days = Lists.newArrayList( "WEDNESDAY", "SUNDAY", "MONDAY", "TUESDAY", "WEDNESDAY"); Function<String, Day> valueOfFunction = Enums.valueOfFunction(Day.class); Iterable<Day> daysAsEnums = Iterables.transform(days, valueOfFunction); assertThat(daysAsEnums, IsIterableWithSize.<Day>iterableWithSize(5)); assertThat(daysAsEnums, IsIterableContainingInOrder. <Day>contains( Day.WEDNESDAY, Day.SUNDAY, Day.MONDAY, Day.TUESDAY, Day.WEDNESDAY)); }
Example #8
Source File: EnumsExample.java From levelup-java-examples with Apache License 2.0 | 6 votes |
@Test public void transform_string_to_enum_string_converter () { List<String> days = Lists.newArrayList( "WEDNESDAY", "SUNDAY", "MONDAY", "TUESDAY", "WEDNESDAY"); Function<String, Day> valueOfFunction = Enums.stringConverter(Day.class); Iterable<Day> daysAsEnums = Iterables.transform(days, valueOfFunction); assertThat(daysAsEnums, IsIterableWithSize.<Day>iterableWithSize(5)); assertThat(daysAsEnums, IsIterableContainingInOrder. <Day>contains( Day.WEDNESDAY, Day.SUNDAY, Day.MONDAY, Day.TUESDAY, Day.WEDNESDAY)); }
Example #9
Source File: EnumValueConverter.java From bisq-core with GNU Affero General Public License v3.0 | 5 votes |
/** * Attempt to resolve an enum of the specified type by looking for a label with the * given value, trying all case variations in the process. * * @return the matching enum label (if any) * @throws IllegalArgumentException if no such label matching the given value is found. */ @Override public Enum convert(String value) { Set<String> candidates = Sets.newHashSet(value, value.toUpperCase(), value.toLowerCase()); for (String candidate : candidates) { Optional<? extends Enum> result = Enums.getIfPresent(enumType, candidate); if (result.isPresent()) return result.get(); } throw new IllegalArgumentException(String.format( "No enum constant %s.[%s]", enumType.getName(), collectionToDelimitedString(candidates, "|"))); }
Example #10
Source File: JsonInclusionTest.java From jackson-datatype-protobuf with Apache License 2.0 | 5 votes |
private static EnumSet<Include> presentValues(String... values) { EnumSet<Include> set = EnumSet.noneOf(Include.class); for (String value : values) { set.addAll(Enums.getIfPresent(Include.class, value).asSet()); } return set; }
Example #11
Source File: ListHostHAProvidersCmd.java From cloudstack with Apache License 2.0 | 5 votes |
@Override public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException { if (!Enums.getIfPresent(HAResource.ResourceSubType.class, hypervisorType).isPresent()) { throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Invalid or unsupported host hypervisor type provided. Supported types are: " + Arrays.toString(HAResource.ResourceSubType.values())); } final List<String> hostHAProviders = haConfigManager.listHAProviders(HAResource.ResourceType.Host, getHypervisorType()); setupResponse(hostHAProviders); }
Example #12
Source File: DefaultMetadataImportService.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
private <T extends Enum<T>> T getEnumWithDefault( Class<T> enumKlass, Map<String, List<String>> parameters, String key, T defaultValue ) { if ( parameters == null || parameters.get( key ) == null || parameters.get( key ).isEmpty() ) { return defaultValue; } String value = String.valueOf( parameters.get( key ).get( 0 ) ); return Enums.getIfPresent( enumKlass, value ).or( defaultValue ); }
Example #13
Source File: ConfigurationHelper.java From neoscada with Eclipse Public License 1.0 | 5 votes |
private static void fillWithDefault ( final List<ColumnLabelProviderInformation> columnInformation ) { columnInformation.add ( new ColumnLabelProviderInformation ( "sourceTimestamp", "sourceTimestamp", true, DEFAULT_INITIAL_SIZE, Collections.<String, String> emptyMap () ) ); for ( final Fields field : Fields.values () ) { if ( Enums.getField ( field ).getAnnotation ( Deprecated.class ) != null ) { // ignore deprecated fields continue; } final Map<String, String> properties = new HashMap<String, String> (); properties.put ( "key", field.getName () ); switch ( field ) { case ACTOR_NAME: properties.put ( "decoration", Decoration.ACTOR.toString () ); break; case EVENT_TYPE: properties.put ( "decoration", Decoration.MONITOR.toString () ); break; default: break; } columnInformation.add ( new ColumnLabelProviderInformation ( field.getName (), "variant", false, DEFAULT_INITIAL_SIZE, properties ) ); } columnInformation.add ( new ColumnLabelProviderInformation ( "entryTimestamp", "entryTimestamp", true, DEFAULT_INITIAL_SIZE, Collections.<String, String> emptyMap () ) ); }
Example #14
Source File: UcteImporter.java From powsybl-core with Mozilla Public License 2.0 | 5 votes |
/** * If the substation has a more specific geographical information than just its country, * returns the corresponding geographical code, otherwise null. */ private static EntsoeGeographicalCode getRegionalGeographicalCode(Substation substation) { //Currently only DE has subregions if (substation.getCountry().map(country -> country != Country.DE).orElse(true)) { return null; } EntsoeGeographicalCode res = Enums.getIfPresent(EntsoeGeographicalCode.class, substation.getNameOrId().substring(0, 2)).orNull(); //handle case where a D-node would start with DE ... return res == EntsoeGeographicalCode.DE ? null : res; }
Example #15
Source File: ChartFacadeController.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
private InclusionStrategy.Include getInclusionStrategy( String inclusionStrategy ) { if ( inclusionStrategy != null ) { Optional<InclusionStrategy.Include> optional = Enums.getIfPresent( InclusionStrategy.Include.class, inclusionStrategy ); if ( optional.isPresent() ) { return optional.get(); } } return InclusionStrategy.Include.NON_NULL; }
Example #16
Source File: ReportTableFacadeController.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
private InclusionStrategy.Include getInclusionStrategy( String inclusionStrategy ) { if ( inclusionStrategy != null ) { Optional<InclusionStrategy.Include> optional = Enums.getIfPresent( InclusionStrategy.Include.class, inclusionStrategy ); if ( optional.isPresent() ) { return optional.get(); } } return InclusionStrategy.Include.NON_NULL; }
Example #17
Source File: XEntity.java From XSeries with MIT License | 5 votes |
public static Entity spawn(Location location, ConfigurationSection config) { String typeStr = config.getString("type"); if (typeStr == null) return null; EntityType type = Enums.getIfPresent(EntityType.class, typeStr.toUpperCase(Locale.ENGLISH)).or(EntityType.ZOMBIE); return edit(location.getWorld().spawnEntity(location, type), config); }
Example #18
Source File: ConsumerHandler.java From pulsar with Apache License 2.0 | 5 votes |
private ConsumerBuilder<byte[]> getConsumerConfiguration(PulsarClient client) { ConsumerBuilder<byte[]> builder = client.newConsumer(); if (queryParams.containsKey("ackTimeoutMillis")) { builder.ackTimeout(Integer.parseInt(queryParams.get("ackTimeoutMillis")), TimeUnit.MILLISECONDS); } if (queryParams.containsKey("subscriptionType")) { checkArgument(Enums.getIfPresent(SubscriptionType.class, queryParams.get("subscriptionType")).isPresent(), "Invalid subscriptionType %s", queryParams.get("subscriptionType")); builder.subscriptionType(SubscriptionType.valueOf(queryParams.get("subscriptionType"))); } if (queryParams.containsKey("receiverQueueSize")) { builder.receiverQueueSize(Math.min(Integer.parseInt(queryParams.get("receiverQueueSize")), 1000)); } if (queryParams.containsKey("consumerName")) { builder.consumerName(queryParams.get("consumerName")); } if (queryParams.containsKey("priorityLevel")) { builder.priorityLevel(Integer.parseInt(queryParams.get("priorityLevel"))); } if (queryParams.containsKey("maxRedeliverCount") || queryParams.containsKey("deadLetterTopic")) { DeadLetterPolicy.DeadLetterPolicyBuilder dlpBuilder = DeadLetterPolicy.builder(); if (queryParams.containsKey("maxRedeliverCount")) { dlpBuilder.maxRedeliverCount(Integer.parseInt(queryParams.get("maxRedeliverCount"))) .deadLetterTopic(String.format("%s-%s-DLQ", topic, subscription)); } if (queryParams.containsKey("deadLetterTopic")) { dlpBuilder.deadLetterTopic(queryParams.get("deadLetterTopic")); } builder.deadLetterPolicy(dlpBuilder.build()); } return builder; }
Example #19
Source File: CypherType.java From jetbrains-plugin-graph-database-support with Apache License 2.0 | 5 votes |
static CypherType parse(@NotNull String type) { if (type.startsWith("LIST")) { if (!type.contains("OF")) { return CypherList.of(ANY); } String param = type.split("OF")[1] .replaceAll("\\?", "") .trim(); return CypherList.of(Enums.getIfPresent(CypherSimpleType.class, param).or(ANY)); } return Enums.getIfPresent(CypherSimpleType.class, type.replaceAll("\\?", "").trim()) .or(ANY); }
Example #20
Source File: TaskContext.java From incubator-gobblin with Apache License 2.0 | 5 votes |
/** * Get the output format of the writer of type {@link WriterOutputFormat}. * * @param branches number of forked branches * @param index branch index * @return output format of the writer */ public WriterOutputFormat getWriterOutputFormat(int branches, int index) { String writerOutputFormatValue = this.taskState.getProp( ForkOperatorUtils.getPropertyNameForBranch(ConfigurationKeys.WRITER_OUTPUT_FORMAT_KEY, branches, index), WriterOutputFormat.OTHER.name()); log.debug("Found writer output format value = {}", writerOutputFormatValue); WriterOutputFormat wof = Enums.getIfPresent(WriterOutputFormat.class, writerOutputFormatValue.toUpperCase()) .or(WriterOutputFormat.OTHER); log.debug("Returning writer output format = {}", wof); return wof; }
Example #21
Source File: DatePartitionedNestedRetriever.java From incubator-gobblin with Apache License 2.0 | 5 votes |
private void initDatePartitionFromGranularity(State state) { String granularityProp = state.getProp(PartitionedFileSourceBase.DATE_PARTITIONED_SOURCE_PARTITION_GRANULARITY); DatePartitionType partitionType = null; if (granularityProp == null) { partitionType = PartitionedFileSourceBase.DEFAULT_DATE_PARTITIONED_SOURCE_PARTITION_GRANULARITY; } else { Optional<DatePartitionType> partitionTypeOpt = Enums.getIfPresent(DatePartitionType.class, granularityProp.toUpperCase()); Preconditions .checkState(partitionTypeOpt.isPresent(), "Invalid source partition granularity: " + granularityProp); partitionType = partitionTypeOpt.get(); } this.partitionPatternFormatter = DateTimeFormat.forPattern(partitionType.getDateTimePattern()); this.incrementalUnit = partitionType.getDateTimeFieldType().getDurationType(); }
Example #22
Source File: TimeBasedWriterPartitioner.java From incubator-gobblin with Apache License 2.0 | 5 votes |
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(); }
Example #23
Source File: EnumValueConverter.java From bisq with GNU Affero General Public License v3.0 | 5 votes |
/** * Attempt to resolve an enum of the specified type by looking for a label with the * given value, trying all case variations in the process. * * @return the matching enum label (if any) * @throws ConfigException if no such label matching the given value is found. */ @Override public Enum convert(String value) { Set<String> candidates = Sets.newHashSet(value, value.toUpperCase(), value.toLowerCase()); for (String candidate : candidates) { Optional<? extends Enum> result = Enums.getIfPresent(enumType, candidate); if (result.isPresent()) return result.get(); } throw new ConfigException("Enum label %s.{%s} does not exist", enumType.getSimpleName(), String.join("|", candidates)); }
Example #24
Source File: ProtoUtil.java From bisq with GNU Affero General Public License v3.0 | 5 votes |
/** * Get a Java enum from a Protobuf enum in a safe way. * * @param enumType the class of the enum, e.g: BlaEnum.class * @param name the name of the enum entry, e.g: proto.getWinner().name() * @param <E> the enum Type * @return an enum */ @Nullable public static <E extends Enum<E>> E enumFromProto(Class<E> enumType, String name) { E result = Enums.getIfPresent(enumType, name).orNull(); if (result == null) { log.error("Invalid value for enum " + enumType.getSimpleName() + ": " + name); result = Enums.getIfPresent(enumType, "UNDEFINED").orNull(); log.error("We try to lookup for an enum entry with name 'UNDEFINED' and use that if available, " + "otherwise the enum is null. enum={}", result); return result; } return result; }
Example #25
Source File: HiveSerDeWrapper.java From incubator-gobblin with Apache License 2.0 | 5 votes |
/** * Get an instance of {@link HiveSerDeWrapper}. * * @param serDeType The SerDe type. If serDeType is one of the available {@link HiveSerDeWrapper.BuiltInHiveSerDe}, * the other three parameters are not used. Otherwise, serDeType should be the class name of a {@link SerDe}, * and the other three parameters must be present. */ public static HiveSerDeWrapper get(String serDeType, Optional<String> inputFormatClassName, Optional<String> outputFormatClassName) { Optional<BuiltInHiveSerDe> hiveSerDe = Enums.getIfPresent(BuiltInHiveSerDe.class, serDeType.toUpperCase()); if (hiveSerDe.isPresent()) { return new HiveSerDeWrapper(hiveSerDe.get()); } Preconditions.checkArgument(inputFormatClassName.isPresent(), "Missing input format class name for SerDe " + serDeType); Preconditions.checkArgument(outputFormatClassName.isPresent(), "Missing output format class name for SerDe " + serDeType); return new HiveSerDeWrapper(serDeType, inputFormatClassName.get(), outputFormatClassName.get()); }
Example #26
Source File: KafkaDeserializerExtractor.java From incubator-gobblin with Apache License 2.0 | 5 votes |
/** * Constructs a {@link KafkaSchemaRegistry} using the value of {@link #KAFKA_DESERIALIZER_TYPE}, if not set it * defaults to {@link SimpleKafkaSchemaRegistry}. */ private static KafkaSchemaRegistry<?, ?> getKafkaSchemaRegistry(Properties props) throws ReflectiveOperationException { Optional<Deserializers> deserializerType = Enums.getIfPresent(Deserializers.class, props.getProperty(KAFKA_DESERIALIZER_TYPE).toUpperCase()); if (deserializerType.isPresent()) { return ConstructorUtils.invokeConstructor(deserializerType.get().getSchemaRegistryClass(), props); } if (props.containsKey(KafkaSchemaRegistry.KAFKA_SCHEMA_REGISTRY_CLASS)) { return KafkaSchemaRegistry.get(props); } return new SimpleKafkaSchemaRegistry(props); }
Example #27
Source File: MRCompactorAvroKeyDedupJobRunner.java From incubator-gobblin with Apache License 2.0 | 5 votes |
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; }
Example #28
Source File: CompactionAvroJobConfigurator.java From incubator-gobblin with Apache License 2.0 | 5 votes |
/** * Refer to 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; }
Example #29
Source File: KafkaWorkUnitPacker.java From incubator-gobblin with Apache License 2.0 | 5 votes |
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); }
Example #30
Source File: KafkaWorkUnitPacker.java From incubator-gobblin with Apache License 2.0 | 5 votes |
public static KafkaWorkUnitPacker getInstance(AbstractSource<?, ?> source, SourceState state, Optional<MetricContext> metricContext) { 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, metricContext); } throw new IllegalArgumentException("WorkUnit packer type " + packerTypeStr + " not found"); } return getInstance(DEFAULT_PACKER_TYPE, source, state, metricContext); }