当前位置: 首页>>代码示例>>Java>>正文


Java Enum类代码示例

本文整理汇总了Java中java.lang.Enum的典型用法代码示例。如果您正苦于以下问题:Java Enum类的具体用法?Java Enum怎么用?Java Enum使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Enum类属于java.lang包,在下文中一共展示了Enum类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: copyOf

import java.lang.Enum; //导入依赖的package包/类
/**
 * Creates an {@link EnumSet} using the contents of the given collection.
 * If the collection is also an {@link EnumSet}, this method works the
 * same as {@link #copyOf(EnumSet)}.  Otherwise, the elements of the collection
 * are inspected and used to populate the new set.
 *
 * @param other the collection to use to populate the new set.
 * @return an {@link EnumSet} containing elements from the given collection.
 * @throws NullPointerException if <code>other</code> is <code>null</code>.
 * @throws IllegalArgumentException if the collection is empty.
 */
public static <T extends Enum<T>> EnumSet4D<T> copyOf(Collection<T> other)
{
  if (other instanceof EnumSet)
    return ((EnumSet4D)other).clone();
  if (other.isEmpty())
      throw new IllegalArgumentException("Collection is empty");
  EnumSet4D<T> r = null;
  
  for (T val : other)
    {
      if (r == null)
        r = of(val);
      else
        r.add(val);
    }

  return r;
}
 
开发者ID:guilhermehazan,项目名称:TotalCrossSDK,代码行数:30,代码来源:EnumSet4D.java

示例2: range

import java.lang.Enum; //导入依赖的package包/类
/**
 * Creates a new {@link EnumSet} using the enumeration constants
 * starting from {@code from} and ending at {@code to} inclusive.
 * The two may be the same, but they must be in the correct order.
 * So giving the first constant twice would give a set with just that
 * constant set, while supplying the first and second constant will give
 * a set with those two elements.  However, specifying the second as
 * the {@code from} element followed by an earlier element as the
 * {@code to} element will result in an error.
 *
 * @param from the element to start from.
 * @param to the element to end at (may be the same as {@code from}.
 * @return an {@link EnumSet} containing the specified range of elements.
 * @throws NullPointerException if any of the parameters are <code>null</code>.
 * @throws IllegalArgumentException if {@code first.compareTo(last) > 0}.
 */
public static <T extends Enum<T>> EnumSet4D<T> range(T from, T to)
{
  if (from.compareTo(to) > 0)
    throw new IllegalArgumentException();
  Class<T> type = from.getDeclaringClass();
  EnumSet4D<T> r = noneOf(type);

  T[] values = type.getEnumConstants();
  // skip over values until start of range is found
  int i = 0;
  while (from != values[i])
    i++;

  // add values until end of range is found
  while (to != values[i]) {
    r.add(values[i]);
    i++;
  }

  // add end of range
  r.add(to);

  return r;
}
 
开发者ID:guilhermehazan,项目名称:TotalCrossSDK,代码行数:41,代码来源:EnumSet4D.java

示例3: of

import java.lang.Enum; //导入依赖的package包/类
/**
 * Creates a new {@link EnumSet} populated with the given elements.
 *
 * @param first the first element to use to populate the new set.
 * @param rest the other elements to use.
 * @return an {@link EnumSet} containing the elements.
 * @throws NullPointerException if any of the parameters are <code>null</code>.
 */
public static <T extends Enum<T>> EnumSet4D<T> of(T first, T... rest)
{
  EnumSet4D<T> r = noneOf(first.getDeclaringClass());
  r.add(first);
  for (T val : rest)
    r.add(val);
  return r;
}
 
开发者ID:guilhermehazan,项目名称:TotalCrossSDK,代码行数:17,代码来源:EnumSet4D.java

示例4: containsKey

import java.lang.Enum; //导入依赖的package包/类
public boolean containsKey(Object key)
{
  if (! (key instanceof Enum))
    return false;
  Enum<K> e = (Enum<K>) key;
  if (e.getDeclaringClass() != enumClass)
    return false;
  return store[e.ordinal()] != emptySlot;
}
 
开发者ID:guilhermehazan,项目名称:TotalCrossSDK,代码行数:10,代码来源:EnumMap4D.java

示例5: get

import java.lang.Enum; //导入依赖的package包/类
public V get(Object key)
{
  if (! (key instanceof Enum))
    return null;
  Enum<K> e = (Enum<K>) key;
  if (e.getDeclaringClass() != enumClass)
    return null;
  V o = store[e.ordinal()];
  return o == emptySlot ? null : o;
}
 
开发者ID:guilhermehazan,项目名称:TotalCrossSDK,代码行数:11,代码来源:EnumMap4D.java

示例6: remove

import java.lang.Enum; //导入依赖的package包/类
public V remove(Object key)
{
  if (! (key instanceof Enum))
    return null;
  Enum<K> e = (Enum<K>) key;
  if (!e.getDeclaringClass().equals(enumClass))
    return null;
  V result = store[e.ordinal()];
  if (result == emptySlot)
    result = null;
  else
    --cardinality;
  store[e.ordinal()] = (V) emptySlot;
  return result;
}
 
开发者ID:guilhermehazan,项目名称:TotalCrossSDK,代码行数:16,代码来源:EnumMap4D.java

示例7: complementOf

import java.lang.Enum; //导入依赖的package包/类
/**
 * Returns a set which is the inverse of the supplied set.
 * If a constant is present in the current set, it will not be
 * present in the new set and vice versa.
 *
 * @param other the set to provide the complement of.
 * @return an {@link EnumSet} which is the inverse of the current one.
 * @throws NullPointerException if <code>other</code> is <code>null</code>.
 */
public static <T extends Enum<T>> EnumSet4D<T> complementOf(EnumSet4D<T> other)
{
  EnumSet4D<T> r = other.clone();
  int numConstants = r.enumClass.getEnumConstants().length;
  r.store.flip(0, numConstants);
  r.cardinality = numConstants - other.cardinality;
  return r;
}
 
开发者ID:guilhermehazan,项目名称:TotalCrossSDK,代码行数:18,代码来源:EnumSet4D.java

示例8: allOf

import java.lang.Enum; //导入依赖的package包/类
/**
 * Returns a set for the given enumeration type where
 * all the constants are present.
 *
 * @param eltType the type of enumeration to use for the set.
 * @return an {@link EnumSet} with all the bits set.
 * @throws NullPointerException if the element type is <code>null</code>.
 */
public static <T extends Enum<T>> EnumSet4D<T> allOf(Class<T> eltType)
{
  // create an EnumSet from the list of values of the type
  return copyOf(Arrays.asList(eltType.getEnumConstants()));
}
 
开发者ID:guilhermehazan,项目名称:TotalCrossSDK,代码行数:14,代码来源:EnumSet4D.java

示例9: noneOf

import java.lang.Enum; //导入依赖的package包/类
/**
 * Returns a set for the given enumeration type where
 * none of the constants are present.
 *
 * @param eltType the type of enumeration to use for the set.
 * @return an {@link EnumSet} with none of the bits set.
 * @throws NullPointerException if the element type is <code>null</code>.
 */
public static <T extends Enum<T>> EnumSet4D<T> noneOf(Class<T> eltType)
{
  return complementOf(allOf(eltType));
}
 
开发者ID:guilhermehazan,项目名称:TotalCrossSDK,代码行数:13,代码来源:EnumSet4D.java

示例10: eq

import java.lang.Enum; //导入依赖的package包/类
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @model valueRequired="true" EBounds="org.asup.fw.java.JavaEnum"
 * @generated
 */
<E extends Enum<E>> boolean eq(E value);
 
开发者ID:asupdev,项目名称:asup,代码行数:8,代码来源:QIndicator.java

示例11: ne

import java.lang.Enum; //导入依赖的package包/类
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @model valueRequired="true" EBounds="org.asup.fw.java.JavaEnum"
 * @generated
 */
<E extends Enum<E>> boolean ne(E value);
 
开发者ID:asupdev,项目名称:asup,代码行数:8,代码来源:QIndicator.java

示例12: move

import java.lang.Enum; //导入依赖的package包/类
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @model EBounds="org.asup.fw.java.JavaEnum"
 * @generated
 */
<E extends Enum<E>> void move(E value);
 
开发者ID:asupdev,项目名称:asup,代码行数:8,代码来源:QMoveable.java

示例13: movel

import java.lang.Enum; //导入依赖的package包/类
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @model EBounds="org.asup.fw.java.JavaEnum"
 * @generated
 */
<E extends Enum<E>> void movel(E value);
 
开发者ID:asupdev,项目名称:asup,代码行数:8,代码来源:QMoveable.java

示例14: eq

import java.lang.Enum; //导入依赖的package包/类
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @model EBounds="org.asup.fw.java.JavaEnum"
 * @generated
 */
<E extends Enum<E>> boolean eq(E value);
 
开发者ID:asupdev,项目名称:asup,代码行数:8,代码来源:QNumeric.java

示例15: ge

import java.lang.Enum; //导入依赖的package包/类
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @model EBounds="org.asup.fw.java.JavaEnum"
 * @generated
 */
<E extends Enum<E>> boolean ge(E value);
 
开发者ID:asupdev,项目名称:asup,代码行数:8,代码来源:QNumeric.java


注:本文中的java.lang.Enum类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。