本文整理匯總了Java中com.google.common.base.Enums.getIfPresent方法的典型用法代碼示例。如果您正苦於以下問題:Java Enums.getIfPresent方法的具體用法?Java Enums.getIfPresent怎麽用?Java Enums.getIfPresent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.common.base.Enums
的用法示例。
在下文中一共展示了Enums.getIfPresent方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: newJobLauncher
import com.google.common.base.Enums; //導入方法依賴的package包/類
/**
* Create a new {@link JobLauncher}.
*
* <p>
* This method will never return a {@code null}.
* </p>
*
* @param sysProps system configuration properties
* @param jobProps job configuration properties
* @return newly created {@link JobLauncher}
*/
public static @Nonnull JobLauncher newJobLauncher(Properties sysProps, Properties jobProps) throws Exception {
String launcherTypeValue =
sysProps.getProperty(ConfigurationKeys.JOB_LAUNCHER_TYPE_KEY, JobLauncherType.LOCAL.name());
Optional<JobLauncherType> launcherType = Enums.getIfPresent(JobLauncherType.class, launcherTypeValue);
if (launcherType.isPresent()) {
switch (launcherType.get()) {
case LOCAL:
return new LocalJobLauncher(JobConfigurationUtils.combineSysAndJobProperties(sysProps, jobProps));
case MAPREDUCE:
return new MRJobLauncher(JobConfigurationUtils.combineSysAndJobProperties(sysProps, jobProps));
default:
throw new RuntimeException("Unsupported job launcher type: " + launcherType.get().name());
}
} else {
@SuppressWarnings("unchecked")
Class<? extends AbstractJobLauncher> launcherClass =
(Class<? extends AbstractJobLauncher>) Class.forName(launcherTypeValue);
return launcherClass.getDeclaredConstructor(Properties.class)
.newInstance(JobConfigurationUtils.combineSysAndJobProperties(sysProps, jobProps));
}
}
示例2: getEnumValue
import com.google.common.base.Enums; //導入方法依賴的package包/類
/**
* Try and parse `value` as Enum. Throws `QueryException` if invalid value.
*
* @param klass Enum class
* @param value 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 ) );
}
}
示例3: load
import com.google.common.base.Enums; //導入方法依賴的package包/類
public void load() {
FileConfiguration config = plugin.getConfig();
loadMessages(config);
loadNotificationSound(config.getConfigurationSection("notification-sound"));
progressEnabled = config.getBoolean("progress");
for (String disableSkill : config.getStringList("progress-disabled")) {
Optional<SkillType> skillType = Enums.getIfPresent(SkillType.class, disableSkill.toUpperCase());
if (skillType.isPresent()) {
disabledSkillProgress.add(skillType.get());
} else {
plugin.getLogger()
.log(Level.WARNING, "The skill type {0} for disabled progress is unknown", disableSkill);
}
}
}
示例4: createConfiguration
import com.google.common.base.Enums; //導入方法依賴的package包/類
@Override public <K, V> CompleteConfiguration<K, V> createConfiguration( Class<K> keyType, Class<V> valueType,
Map<String, String> properties ) {
MutableConfiguration<K, V> configuration = new MutableConfiguration<K, V>();
configuration.setTypes( keyType, valueType );
if ( properties.containsKey( CONFIG_TTL ) ) {
Long ttl = Longs.tryParse( Strings.nullToEmpty( properties.get( CONFIG_TTL ) ) );
Preconditions.checkArgument( ttl != null, "Template config error", CONFIG_TTL );
Optional<ExpiryFunction> expiryFunction;
if ( properties.containsKey( CONFIG_TTL_RESET ) ) {
expiryFunction = Enums.getIfPresent( ExpiryFunction.class, properties.get( CONFIG_TTL_RESET ) );
} else {
expiryFunction = Optional.of( CONFIG_TTL_RESET_DEFAULT );
}
Preconditions.checkArgument( expiryFunction.isPresent(), "Template config error", CONFIG_TTL_RESET );
configuration.setExpiryPolicyFactory( expiryFunction.get().createFactory( ttl ) );
}
if ( properties.containsKey( CONFIG_STORE_BY_VALUE ) ) {
configuration.setStoreByValue( Boolean.valueOf( properties.get( CONFIG_STORE_BY_VALUE ) ) );
}
return configuration;
}
示例5: get
import com.google.common.base.Enums; //導入方法依賴的package包/類
/**
* 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.
* @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);
}
}
示例6: newJobLauncher
import com.google.common.base.Enums; //導入方法依賴的package包/類
/**
* 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..
* @return the JobLauncher instance
* @throws RuntimeException if the instantiation fails
*/
public static JobLauncher newJobLauncher(Properties sysProps, Properties jobProps,
String launcherTypeValue, SharedResourcesBroker<GobblinScopeTypes> instanceBroker) {
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);
case MAPREDUCE:
return new MRJobLauncher(JobConfigurationUtils.combineSysAndJobProperties(sysProps, jobProps), instanceBroker);
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);
}
}
示例7: getIsolationLevel
import com.google.common.base.Enums; //導入方法依賴的package包/類
/**
* Gets the isolation level.
*
* @return The isolation level.
*/
public int getIsolationLevel() {
final Optional<IsolationLevel> e = Enums.getIfPresent(IsolationLevel.class, getProperty(ISOLATION_LEVEL).toUpperCase());
if (!e.isPresent()) {
throw new DatabaseEngineRuntimeException(ISOLATION_LEVEL + " must be set and be one of the following: " + EnumSet.allOf(IsolationLevel.class));
}
switch (e.get()) {
case READ_UNCOMMITTED:
return Connection.TRANSACTION_READ_UNCOMMITTED;
case READ_COMMITTED:
return Connection.TRANSACTION_READ_COMMITTED;
case REPEATABLE_READ:
return Connection.TRANSACTION_REPEATABLE_READ;
case SERIALIZABLE:
return Connection.TRANSACTION_SERIALIZABLE;
default:
// Never happens.
throw new DatabaseEngineRuntimeException("New isolation level?!" + e.get());
}
}
示例8: parse
import com.google.common.base.Enums; //導入方法依賴的package包/類
public Optional<PlayerWorkMode> parse(XmlData data) {
Node node = data.getDocument()
.getFirstChild()
.getAttributes()
.getNamedItem("mode");
if (node == null) {
return Optional.absent();
} else {
return Enums.getIfPresent(PlayerWorkMode.class, node.getNodeValue()
.toUpperCase());
}
}
示例9: determinValidityOfReplica
import com.google.common.base.Enums; //導入方法依賴的package包/類
private void determinValidityOfReplica(ReplicationMode replicationMode, Table oldReplicaTable) {
// REPLICATION_MODE is a table parameter that was added later it might not be set, so we're checking the
// REPLICATION_EVENT to determine if a table was created via CT.
String previousEvent = oldReplicaTable.getParameters().get(REPLICATION_EVENT.parameterName());
if (StringUtils.isBlank(previousEvent)) {
throw new DestinationNotReplicaException(oldReplicaTable, getHiveConf().getVar(ConfVars.METASTOREURIS));
}
LOG.debug("Checking that replication modes are compatible.");
Optional<ReplicationMode> replicaReplicationMode = Enums.getIfPresent(ReplicationMode.class,
nullToEmpty(oldReplicaTable.getParameters().get(REPLICATION_MODE.parameterName())));
if (replicaReplicationMode.isPresent()) {
if (replicaReplicationMode.get() == METADATA_MIRROR && replicationMode != METADATA_MIRROR) {
throw new InvalidReplicationModeException("Trying a "
+ replicationMode.name()
+ " replication on a table that was previously only "
+ METADATA_MIRROR.name()
+ "-ed. This is not possible, rerun with a different table name or change the replication mode to "
+ METADATA_MIRROR.name()
+ ".");
}
if (replicaReplicationMode.get() != METADATA_MIRROR && replicationMode == METADATA_MIRROR) {
throw new InvalidReplicationModeException("Trying to "
+ METADATA_MIRROR.name()
+ " a previously replicated table. This is not possible, rerun with a different table name or change the replication mode to "
+ FULL.name()
+ " or "
+ METADATA_UPDATE.name()
+ ".");
}
} else if (replicationMode == METADATA_MIRROR) {
// no replicaReplicationMode found in table settings we assume FULL_REPLICATION was intended.
throw new InvalidReplicationModeException("Trying to "
+ METADATA_MIRROR.name()
+ " a previously replicated table. This is not possible, rerun with a different table name or change the replication mode to "
+ FULL.name()
+ " or "
+ METADATA_UPDATE.name()
+ ".");
}
}
示例10: getInclusionStrategy
import com.google.common.base.Enums; //導入方法依賴的package包/類
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;
}
示例11: getDedupKeyOption
import com.google.common.base.Enums; //導入方法依賴的package包/類
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;
}
示例12: getWorkUnitSizeEstimator
import com.google.common.base.Enums; //導入方法依賴的package包/類
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());
} else {
throw new IllegalArgumentException("WorkUnit size estimator type " + sizeEstimatorType + " not found");
}
} else {
return getWorkUnitSizeEstimator(DEFAULT_SIZE_ESTIMATOR_TYPE);
}
}
示例13: getInstance
import com.google.common.base.Enums; //導入方法依賴的package包/類
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);
} else {
throw new IllegalArgumentException("WorkUnit packer type " + packerTypeStr + " not found");
}
} else {
return getInstance(DEFAULT_PACKER_TYPE, source, state);
}
}
示例14: get
import com.google.common.base.Enums; //導入方法依賴的package包/類
/**
* 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<String> extension) {
Optional<BuiltInHiveSerDe> hiveSerDe = Enums.getIfPresent(BuiltInHiveSerDe.class, serDeType.toUpperCase());
if (hiveSerDe.isPresent()) {
return new HiveSerDeWrapper(hiveSerDe.get());
} else {
Preconditions.checkArgument(inputFormatClassName.isPresent(),
"Missing input format class name for SerDe " + serDeType);
Preconditions.checkArgument(outputFormatClassName.isPresent(),
"Missing output format class name for SerDe " + serDeType);
Preconditions.checkArgument(extension.isPresent(), "Missing file extension for SerDe " + serDeType);
return new HiveSerDeWrapper(serDeType, inputFormatClassName.get(), outputFormatClassName.get(), extension.get());
}
}
示例15: loadNotificationSound
import com.google.common.base.Enums; //導入方法依賴的package包/類
private void loadNotificationSound(ConfigurationSection section) {
if (section.getBoolean("enabled")) {
volume = (float) section.getDouble("volume");
pitch = (float) section.getDouble("pitch");
String soundType = section.getString("type");
Optional<Sound> sound = Enums.getIfPresent(Sound.class, soundType.toUpperCase());
if (sound.isPresent()) {
this.sound = sound.get();
} else {
plugin.getLogger().log(Level.WARNING, "Failed to load the sound type");
}
}
}