java.util.EnumSet.allOf()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(10.2k)|赞(0)|评价(0)|浏览(135)

本文整理了Java中java.util.EnumSet.allOf()方法的一些代码示例,展示了EnumSet.allOf()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。EnumSet.allOf()方法的具体详情如下:
包路径:java.util.EnumSet
类名称:EnumSet
方法名:allOf

EnumSet.allOf介绍

[英]Creates an enum set filled with all the enum elements of the specified elementType.
[中]创建用指定elementType的所有枚举元素填充的枚举集。

代码示例

代码示例来源:origin: google/guava

@GwtIncompatible // java.lang.ref.WeakReference
private static <T extends Enum<T>> Map<String, WeakReference<? extends Enum<?>>> populateCache(
  Class<T> enumClass) {
 Map<String, WeakReference<? extends Enum<?>>> result = new HashMap<>();
 for (T enumInstance : EnumSet.allOf(enumClass)) {
  result.put(enumInstance.name(), new WeakReference<Enum<?>>(enumInstance));
 }
 enumConstantCache.put(enumClass, result);
 return result;
}

代码示例来源:origin: stackoverflow.com

public static Map<TimeUnit,Long> computeDiff(Date date1, Date date2) {
  long diffInMillies = date2.getTime() - date1.getTime();
  List<TimeUnit> units = new ArrayList<TimeUnit>(EnumSet.allOf(TimeUnit.class));
  Collections.reverse(units);
  Map<TimeUnit,Long> result = new LinkedHashMap<TimeUnit,Long>();
  long milliesRest = diffInMillies;
  for ( TimeUnit unit : units ) {
    long diff = unit.convert(milliesRest,TimeUnit.MILLISECONDS);
    long diffInMilliesForUnit = unit.toMillis(diff);
    milliesRest = milliesRest - diffInMilliesForUnit;
    result.put(unit,diff);
  }
  return result;
}

代码示例来源:origin: prestodb/presto

@GwtIncompatible // java.lang.ref.WeakReference
private static <T extends Enum<T>> Map<String, WeakReference<? extends Enum<?>>> populateCache(
  Class<T> enumClass) {
 Map<String, WeakReference<? extends Enum<?>>> result = new HashMap<>();
 for (T enumInstance : EnumSet.allOf(enumClass)) {
  result.put(enumInstance.name(), new WeakReference<Enum<?>>(enumInstance));
 }
 enumConstantCache.put(enumClass, result);
 return result;
}

代码示例来源:origin: google/j2objc

@GwtIncompatible // java.lang.ref.WeakReference
private static <T extends Enum<T>> Map<String, WeakReference<? extends Enum<?>>> populateCache(
  Class<T> enumClass) {
 Map<String, WeakReference<? extends Enum<?>>> result = new HashMap<>();
 for (T enumInstance : EnumSet.allOf(enumClass)) {
  result.put(enumInstance.name(), new WeakReference<Enum<?>>(enumInstance));
 }
 enumConstantCache.put(enumClass, result);
 return result;
}

代码示例来源:origin: stackoverflow.com

import java.util.*;

public enum Foo
{
  BAR, BAZ;

  private static final Map<String, Foo> lowerCaseMap;

  static
  {
    lowerCaseMap = new HashMap<String, Foo>();
    for (Foo foo : EnumSet.allOf(Foo.class))
    {
      // Yes, use some appropriate locale in production code :)
      lowerCaseMap.put(foo.name().toLowerCase(), foo);
    }
  }
}

代码示例来源:origin: wildfly/wildfly

@GwtIncompatible // java.lang.ref.WeakReference
private static <T extends Enum<T>> Map<String, WeakReference<? extends Enum<?>>> populateCache(
  Class<T> enumClass) {
 Map<String, WeakReference<? extends Enum<?>>> result = new HashMap<>();
 for (T enumInstance : EnumSet.allOf(enumClass)) {
  result.put(enumInstance.name(), new WeakReference<Enum<?>>(enumInstance));
 }
 enumConstantCache.put(enumClass, result);
 return result;
}

代码示例来源:origin: stackoverflow.com

public enum Week 
{
   SUNDAY(0),
   MONDAY(1)

   private static final Map<Integer,Week> lookup 
     = new HashMap<Integer,Week>();

   static {
     for(Week w : EnumSet.allOf(Week.class))
        lookup.put(w.getCode(), w);
   }

   private int code;

   private Week(int code) {
     this.code = code;
   }

   public int getCode() { return code; }

   public static Week get(int code) { 
     return lookup.get(code); 
   }
}

代码示例来源:origin: com.thoughtworks.xstream/xstream

private static <T extends Enum<T>> Map<String, T> extractStringMap(Class<T> type) {
  checkType(type);
  EnumSet<T> values = EnumSet.allOf(type);
  Map<String, T> strings = new HashMap<String, T>(values.size());
  for (T value : values) {
    if (strings.put(value.toString(), value) != null) {
      throw new InitializationException("Enum type "
        + type.getName()
        + " does not have unique string representations for its values");
    }
  }
  return strings;
}

代码示例来源:origin: stackoverflow.com

public enum Status {
WAITING(0),
READY(1),
SKIPPED(-1),
COMPLETED(5);
private static final Map<Integer,Status> lookup 
  = new HashMap<Integer,Status>();
static {
  for(Status s : EnumSet.allOf(Status.class))
     lookup.put(s.getCode(), s);
}
private int code;
private Status(int code) {
  this.code = code;
}
public int getCode() { return code; }
public static Status get(int code) { 
  return lookup.get(code); 
}

代码示例来源:origin: stackoverflow.com

import java.util.*;

enum SampleEnum {
  Foo,
  Bar;

  private static final Map<String, SampleEnum> nameToValueMap =
    new HashMap<String, SampleEnum>();

  static {
    for (SampleEnum value : EnumSet.allOf(SampleEnum.class)) {
      nameToValueMap.put(value.name(), value);
    }
  }

  public static SampleEnum forName(String name) {
    return nameToValueMap.get(name);
  }
}

public class Test {
  public static void main(String [] args)
    throws Exception { // Just for simplicity!
    System.out.println(SampleEnum.forName("Foo"));
    System.out.println(SampleEnum.forName("Bar"));
    System.out.println(SampleEnum.forName("Baz"));
  }
}

代码示例来源:origin: wildfly/wildfly

static Map<String, AbstractMetaDataParser<?>> createJbossEjbJarParsers() {
    Map<String, AbstractMetaDataParser<?>> parsers = new HashMap<String, AbstractMetaDataParser<?>>();
    for (ClusteringSchema schema : EnumSet.allOf(ClusteringSchema.class)) {
      parsers.put(schema.getNamespaceUri(), new EJBBoundClusteringMetaDataParser(schema));
    }
    parsers.put(EJBBoundSecurityMetaDataParser.LEGACY_NAMESPACE_URI, EJBBoundSecurityMetaDataParser.INSTANCE);
    parsers.put(EJBBoundSecurityMetaDataParser.NAMESPACE_URI_1_0, EJBBoundSecurityMetaDataParser.INSTANCE);
    parsers.put(EJBBoundSecurityMetaDataParser11.NAMESPACE_URI_1_1, EJBBoundSecurityMetaDataParser11.INSTANCE);
    parsers.put(SecurityRoleMetaDataParser.LEGACY_NAMESPACE_URI, SecurityRoleMetaDataParser.INSTANCE);
    parsers.put(SecurityRoleMetaDataParser.NAMESPACE_URI, SecurityRoleMetaDataParser.INSTANCE);
    parsers.put(EJBBoundResourceAdapterBindingMetaDataParser.LEGACY_NAMESPACE_URI, EJBBoundResourceAdapterBindingMetaDataParser.INSTANCE);
    parsers.put(EJBBoundResourceAdapterBindingMetaDataParser.NAMESPACE_URI, EJBBoundResourceAdapterBindingMetaDataParser.INSTANCE);
    parsers.put(EJBBoundMdbDeliveryMetaDataParser.NAMESPACE_URI_1_0, EJBBoundMdbDeliveryMetaDataParser.INSTANCE);
    parsers.put(EJBBoundMdbDeliveryMetaDataParser11.NAMESPACE_URI_1_1, EJBBoundMdbDeliveryMetaDataParser11.INSTANCE);
    parsers.put("urn:iiop", new IIOPMetaDataParser());
    parsers.put("urn:iiop:1.0", new IIOPMetaDataParser());
    parsers.put("urn:trans-timeout", new TransactionTimeoutMetaDataParser());
    parsers.put("urn:trans-timeout:1.0", new TransactionTimeoutMetaDataParser());
    parsers.put(EJBBoundPoolParser.NAMESPACE_URI, new EJBBoundPoolParser());
    parsers.put(EJBBoundCacheParser.NAMESPACE_URI, new EJBBoundCacheParser());
    parsers.put(ContainerInterceptorsParser.NAMESPACE_URI_1_0, ContainerInterceptorsParser.INSTANCE);
    parsers.put(TimerServiceMetaDataParser.NAMESPACE_URI, TimerServiceMetaDataParser.INSTANCE);
    return parsers;
  }
}

代码示例来源:origin: wildfly/wildfly

@Override
public ServiceConfigurator configure(OperationContext context, ModelNode model) throws OperationFailedException {
  for (ColumnAttribute column : EnumSet.allOf(ColumnAttribute.class)) {
    ModelNode columnModel = column.resolveModelAttribute(context, model);
    String name = column.getColumnName().resolveModelAttribute(context, columnModel).asString();
    String type = column.getColumnType().resolveModelAttribute(context, columnModel).asString();
    this.columns.put(column, new AbstractMap.SimpleImmutableEntry<>(name, type));
  }
  this.fetchSize = FETCH_SIZE.resolveModelAttribute(context, model).asInt();
  this.prefix = this.prefixAttribute.resolveModelAttribute(context, model).asString();
  return this;
}

代码示例来源:origin: wildfly/wildfly

GlobalConfigurationServiceConfigurator(PathAddress address) {
  super(CONFIGURATION, address);
  this.name = address.getLastElement().getValue();
  this.module = new ServiceSupplierDependency<>(CacheContainerComponent.MODULE.getServiceName(address));
  this.transport = new ServiceSupplierDependency<>(CacheContainerComponent.TRANSPORT.getServiceName(address));
  this.site = new ServiceSupplierDependency<>(CacheContainerComponent.SITE.getServiceName(address));
  for (ThreadPoolResourceDefinition pool : EnumSet.complementOf(EnumSet.of(ThreadPoolResourceDefinition.CLIENT))) {
    this.pools.put(pool, new ServiceSupplierDependency<>(pool.getServiceName(address)));
  }
  for (ScheduledThreadPoolResourceDefinition pool : EnumSet.allOf(ScheduledThreadPoolResourceDefinition.class)) {
    this.schedulers.put(pool, new ServiceSupplierDependency<>(pool.getServiceName(address)));
  }
}

代码示例来源:origin: apache/hbase

for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) {
 byName.put(field.getFieldName(), field);

代码示例来源:origin: apache/hive

for (_Fields field : EnumSet.allOf(_Fields.class)) {
 byName.put(field.getFieldName(), field);

代码示例来源:origin: ahmetaa/zemberek-nlp

private static <E extends Enum<E>> Map<String, E> createEnumNameMap(
  Class<E> enumType) {
 Map<String, E> nameToEnum = new HashMap<>();
 // put Enums in map by name
 for (E enumElement : EnumSet.allOf(enumType)) {
  nameToEnum.put(enumElement.name(), enumElement);
 }
 return nameToEnum;
}

代码示例来源:origin: protostuff/protostuff

firstMap.put("share", share);
firstMap.put("share3", share3);
bean.firstMap = firstMap;
secondMap.put("share", share);
secondMap.put("share3", share3);
bean.secondMap = secondMap;
EnumSet<Order> orderEnumSet = EnumSet.allOf(Order.class);

代码示例来源:origin: ehcache/ehcache3

@Override
public <K, V> Store<K, V> createStore(Configuration<K, V> storeConfig, ServiceConfiguration<?>... serviceConfigs) {
 Set<ResourceType.Core> supportedTypes = EnumSet.allOf(ResourceType.Core.class);
  new SoftLockValueCombinedSerializerLifecycleHelper<V>(softLockSerializerRef, storeConfig.getClassLoader());
 createdStores.put(store, new CreatedStoreRef(underlyingStoreProvider, helper));
 return store;

代码示例来源:origin: org.apache.hadoop/hadoop-hdfs

/**
 * Creates a new StartupProgress by initializing internal data structure for
 * tracking progress of all defined phases.
 */
public StartupProgress() {
 for (Phase phase: EnumSet.allOf(Phase.class)) {
  phases.put(phase, new PhaseTracking());
 }
}

代码示例来源:origin: line/armeria

for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) {
 byName.put(field.getFieldName(), field);

相关文章