本文整理匯總了Java中com.google.common.base.Enums類的典型用法代碼示例。如果您正苦於以下問題:Java Enums類的具體用法?Java Enums怎麽用?Java Enums使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Enums類屬於com.google.common.base包,在下文中一共展示了Enums類的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: propertyHasModel
import com.google.common.base.Enums; //導入依賴的package包/類
/**
* Use reflection to validate the Java model.
*/
@Test
public void propertyHasModel() throws ReflectiveOperationException {
assume().that(bdioEnum instanceof Bdio.ObjectProperty || bdioEnum instanceof Bdio.DataProperty).isTrue();
Bdio.AllowedOn allowedOn = Enums.getField(bdioEnum).getAnnotation(Bdio.AllowedOn.class);
// Check the BdioMetadata class for metadata properties
if (allowedOn.metadata()) {
assertThat(Stream.of(BdioMetadata.class.getMethods())
.anyMatch(this::methodName))
.named("BdioMetadata").isTrue();
}
// Check the model type for other domain assignments
assertThat(Stream.of(allowedOn.value())
.filter(bdioClass -> modelTypeMethods(bdioClass).noneMatch(this::methodName))
.map(Bdio.Class::name))
.isEmpty();
}
示例3: getConsumerConfiguration
import com.google.common.base.Enums; //導入依賴的package包/類
private ConsumerConfiguration getConsumerConfiguration() {
ConsumerConfiguration conf = new ConsumerConfiguration();
if (queryParams.containsKey("ackTimeoutMillis")) {
conf.setAckTimeout(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"));
conf.setSubscriptionType(SubscriptionType.valueOf(queryParams.get("subscriptionType")));
}
if (queryParams.containsKey("receiverQueueSize")) {
conf.setReceiverQueueSize(Math.min(Integer.parseInt(queryParams.get("receiverQueueSize")), 1000));
}
if (queryParams.containsKey("consumerName")) {
conf.setConsumerName(queryParams.get("consumerName"));
}
return conf;
}
示例4: 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 ) );
}
}
示例5: 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);
}
}
}
示例6: parseStatus
import com.google.common.base.Enums; //導入依賴的package包/類
private Change.Status parseStatus(ChangeNotesCommit commit) throws ConfigInvalidException {
List<String> statusLines = commit.getFooterLineValues(FOOTER_STATUS);
if (statusLines.isEmpty()) {
return null;
} else if (statusLines.size() > 1) {
throw expectedOneFooter(FOOTER_STATUS, statusLines);
}
Change.Status status =
Enums.getIfPresent(Change.Status.class, statusLines.get(0).toUpperCase()).orNull();
if (status == null) {
throw invalidFooter(FOOTER_STATUS, statusLines.get(0));
}
// All approvals after MERGED and before the next status change get the postSubmit
// bit. (Currently the state can't change from MERGED to something else, but just in case.) The
// exception is the legacy SUBM approval, which is never considered post-submit, but might end
// up sorted after the submit during rebuilding.
if (status == Change.Status.MERGED) {
for (PatchSetApproval psa : bufferedApprovals) {
if (!psa.isLegacySubmit()) {
psa.setPostSubmit(true);
}
}
}
bufferedApprovals.clear();
return status;
}
示例7: parsePatchSetState
import com.google.common.base.Enums; //導入依賴的package包/類
private PatchSetState parsePatchSetState(ChangeNotesCommit commit) throws ConfigInvalidException {
String psIdLine = parseExactlyOneFooter(commit, FOOTER_PATCH_SET);
int s = psIdLine.indexOf(' ');
if (s < 0) {
return null;
}
String withParens = psIdLine.substring(s + 1);
if (withParens.startsWith("(") && withParens.endsWith(")")) {
PatchSetState state =
Enums.getIfPresent(
PatchSetState.class,
withParens.substring(1, withParens.length() - 1).toUpperCase())
.orNull();
if (state != null) {
return state;
}
}
throw invalidFooter(FOOTER_PATCH_SET, psIdLine);
}
示例8: 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;
}
示例9: 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);
}
}
示例10: 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);
}
}
示例11: transform_string_to_enum
import com.google.common.base.Enums; //導入依賴的package包/類
@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));
}
示例12: transform_string_to_enum_string_converter
import com.google.common.base.Enums; //導入依賴的package包/類
@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));
}
示例13: 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());
}
}
示例14: 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());
}
}
示例15: checkFirstLine
import com.google.common.base.Enums; //導入依賴的package包/類
/**
* Perform basic checks on the first line of the file.
*
* @throws TermAnnotationParserException In case of problems with the first line in the file.
*/
private void checkFirstLine() throws TermAnnotationParserException {
final String[] arr = nextLine.split("\t");
if (arr.length != 14) {
throw new TermAnnotationParserException(
"Does not look like HPO disease annotation file. Invalid number of fields in first "
+ "line, expected 14, was " + arr.length);
}
if (!Enums.getIfPresent(HpoDiseaseAnnotation.DatabaseSource.class, arr[0]).isPresent()) {
throw new TermAnnotationParserException(
"Does not look like HPO disease annotation file. First field value was " + arr[0]
+ " but was expected to be one of "
+ Arrays.toString(HpoDiseaseAnnotation.DatabaseSource.values()));
}
}