iterator ( )源码实例Demo

java.util.EnumSet#iterator ( )源码实例Demo

下面列出了java.util.EnumSet#iterator ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: alfresco-data-model   文件: EnumFactory.java
/**
 * @param caseSensitive  case-sensitive lookup for Enum label
 */
public EnumFactory(Class<E> enumClass, E defaultEnum, boolean caseSensitive)
{
    this.defaultEnum = defaultEnum;

    // setup label map
    labelMap = caseSensitive ? new HashMap<String, E>(10) : new TreeMap<String, E>(String.CASE_INSENSITIVE_ORDER);
    EnumSet<E> enumSet = EnumSet.allOf(enumClass);
    Iterator<E> iter = enumSet.iterator();
    while(iter.hasNext())
    {
        E e = iter.next();
        if (e instanceof EnumLabel)
        {
            labelMap.put(((EnumLabel)e).getLabel(), e);
        }
    }
}
 
源代码2 项目: hadoop   文件: TestEnumSetWritable.java
/** 
 * test {@code EnumSetWritable.write(DataOutputBuffer out)} 
 *  and iteration by TestEnumSet through iterator().
 */
public void testEnumSetWritableWriteRead() throws Exception {
  EnumSetWritable<TestEnumSet> srcSet = new EnumSetWritable<TestEnumSet>(
      EnumSet.of(TestEnumSet.APPEND, TestEnumSet.CREATE), TestEnumSet.class);
  DataOutputBuffer out = new DataOutputBuffer();
  srcSet.write(out);

  EnumSetWritable<TestEnumSet> dstSet = new EnumSetWritable<TestEnumSet>();
  DataInputBuffer in = new DataInputBuffer();
  in.reset(out.getData(), out.getLength());
  dstSet.readFields(in);

  EnumSet<TestEnumSet> result = dstSet.get();
  Iterator<TestEnumSet> dstIter = result.iterator();
  Iterator<TestEnumSet> srcIter = srcSet.iterator();
  while (dstIter.hasNext() && srcIter.hasNext()) {
    assertEquals("testEnumSetWritableWriteRead error !!!", dstIter.next(),
        srcIter.next());
  }
}
 
源代码3 项目: big-c   文件: TestEnumSetWritable.java
/** 
 * test {@code EnumSetWritable.write(DataOutputBuffer out)} 
 *  and iteration by TestEnumSet through iterator().
 */
public void testEnumSetWritableWriteRead() throws Exception {
  EnumSetWritable<TestEnumSet> srcSet = new EnumSetWritable<TestEnumSet>(
      EnumSet.of(TestEnumSet.APPEND, TestEnumSet.CREATE), TestEnumSet.class);
  DataOutputBuffer out = new DataOutputBuffer();
  srcSet.write(out);

  EnumSetWritable<TestEnumSet> dstSet = new EnumSetWritable<TestEnumSet>();
  DataInputBuffer in = new DataInputBuffer();
  in.reset(out.getData(), out.getLength());
  dstSet.readFields(in);

  EnumSet<TestEnumSet> result = dstSet.get();
  Iterator<TestEnumSet> dstIter = result.iterator();
  Iterator<TestEnumSet> srcIter = srcSet.iterator();
  while (dstIter.hasNext() && srcIter.hasNext()) {
    assertEquals("testEnumSetWritableWriteRead error !!!", dstIter.next(),
        srcIter.next());
  }
}
 
源代码4 项目: j2objc   文件: EnumSetTest.java
public void testRemoveIteratorRemoveFromHugeEnumSet() {
    EnumSet<HugeEnumCount> set = EnumSet.noneOf(HugeEnumCount.class);
    set.add(HugeEnumCount.NO64);
    set.add(HugeEnumCount.NO65);
    set.add(HugeEnumCount.NO128);
    Iterator<HugeEnumCount> iterator = set.iterator();
    assertTrue(iterator.hasNext());
    assertEquals(HugeEnumCount.NO64, iterator.next());
    assertTrue(iterator.hasNext());
    iterator.remove();
    assertEquals(HugeEnumCount.NO65, iterator.next());
    assertTrue(iterator.hasNext());
    assertEquals(HugeEnumCount.NO128, iterator.next());
    assertFalse(iterator.hasNext());
    assertEquals(EnumSet.of(HugeEnumCount.NO65, HugeEnumCount.NO128), set);
    iterator.remove();
    assertEquals(EnumSet.of(HugeEnumCount.NO65), set);
}
 
源代码5 项目: lams   文件: EnumSetConverter.java
private String joinEnumValues(EnumSet set) {
    boolean seenFirst = false;
    StringBuffer result = new StringBuffer();
    for (Iterator iterator = set.iterator(); iterator.hasNext();) {
        Enum value = (Enum) iterator.next();
        if (seenFirst) {
            result.append(',');
        } else {
            seenFirst = true;
        }
        result.append(value.name());
    }
    return result.toString();
}
 
源代码6 项目: hadoop   文件: EnumSetParam.java
/** Convert an EnumSet to a string of comma separated values. */
public static <E extends Enum<E>> String toString(EnumSet<E> set) {
  if (set == null || set.isEmpty()) {
    return "";
  } else {
    final StringBuilder b = new StringBuilder();
    final Iterator<E> i = set.iterator();
    b.append(i.next());
    while (i.hasNext()) {
      b.append(',').append(i.next());
    }
    return b.toString();
  }
}
 
源代码7 项目: hadoop   文件: EnumSetParam.java
/** Convert an EnumSet to a string of comma separated values. */
static <E extends Enum<E>> String toString(EnumSet<E> set) {
  if (set == null || set.isEmpty()) {
    return "";
  } else {
    final StringBuilder b = new StringBuilder();
    final Iterator<E> i = set.iterator();
    b.append(i.next());
    for(; i.hasNext(); ) {
      b.append(',').append(i.next());
    }
    return b.toString();
  }
}
 
源代码8 项目: hadoop   文件: EnumSetWritable.java
/**
 * reset the EnumSetWritable with specified
 * <tt>value</value> and <tt>elementType</tt>. If the <tt>value</tt> argument
 * is null or its size is zero, the <tt>elementType</tt> argument must not be
 * null. If the argument <tt>value</tt>'s size is bigger than zero, the
 * argument <tt>elementType</tt> is not be used.
 * 
 * @param value
 * @param elementType
 */
public void set(EnumSet<E> value, Class<E> elementType) {
  if ((value == null || value.size() == 0)
      && (this.elementType == null && elementType == null)) {
    throw new IllegalArgumentException(
        "The EnumSet argument is null, or is an empty set but with no elementType provided.");
  }
  this.value = value;
  if (value != null && value.size() > 0) {
    Iterator<E> iterator = value.iterator();
    this.elementType = iterator.next().getDeclaringClass();
  } else if (elementType != null) {
    this.elementType = elementType;
  }
}
 
源代码9 项目: big-c   文件: EnumSetParam.java
/** Convert an EnumSet to a string of comma separated values. */
public static <E extends Enum<E>> String toString(EnumSet<E> set) {
  if (set == null || set.isEmpty()) {
    return "";
  } else {
    final StringBuilder b = new StringBuilder();
    final Iterator<E> i = set.iterator();
    b.append(i.next());
    while (i.hasNext()) {
      b.append(',').append(i.next());
    }
    return b.toString();
  }
}
 
源代码10 项目: big-c   文件: EnumSetParam.java
/** Convert an EnumSet to a string of comma separated values. */
static <E extends Enum<E>> String toString(EnumSet<E> set) {
  if (set == null || set.isEmpty()) {
    return "";
  } else {
    final StringBuilder b = new StringBuilder();
    final Iterator<E> i = set.iterator();
    b.append(i.next());
    for(; i.hasNext(); ) {
      b.append(',').append(i.next());
    }
    return b.toString();
  }
}
 
源代码11 项目: big-c   文件: EnumSetWritable.java
/**
 * reset the EnumSetWritable with specified
 * <tt>value</value> and <tt>elementType</tt>. If the <tt>value</tt> argument
 * is null or its size is zero, the <tt>elementType</tt> argument must not be
 * null. If the argument <tt>value</tt>'s size is bigger than zero, the
 * argument <tt>elementType</tt> is not be used.
 * 
 * @param value
 * @param elementType
 */
public void set(EnumSet<E> value, Class<E> elementType) {
  if ((value == null || value.size() == 0)
      && (this.elementType == null && elementType == null)) {
    throw new IllegalArgumentException(
        "The EnumSet argument is null, or is an empty set but with no elementType provided.");
  }
  this.value = value;
  if (value != null && value.size() > 0) {
    Iterator<E> iterator = value.iterator();
    this.elementType = iterator.next().getDeclaringClass();
  } else if (elementType != null) {
    this.elementType = elementType;
  }
}
 
public static long getSlotIndexForMutationContextPreparedStatement(
    final EnumSet<AbstractUpsertOutputOperator.OperationContext> context)
{
  Iterator<AbstractUpsertOutputOperator.OperationContext> itrForContexts = context.iterator();
  long indexValue = 0;
  while (itrForContexts.hasNext()) {
    AbstractUpsertOutputOperator.OperationContext aContext = itrForContexts.next();
    indexValue += Math.pow(10, aContext.ordinal());
  }
  return indexValue;
}
 
源代码13 项目: j60870   文件: IeBinaryCounterReading.java
private static Set<Flag> flagsFor(byte b) {
    EnumSet<Flag> s = EnumSet.allOf(Flag.class);

    Iterator<Flag> iter = s.iterator();

    while (iter.hasNext()) {
        int mask2 = iter.next().mask;
        if ((mask2 & b) != mask2) {
            iter.remove();
        }
    }

    return s;
}
 
源代码14 项目: android-app   文件: QueueItem.java
public static String enumSetToString(EnumSet<ArticleChangeType> enumSet) {
    if(enumSet.isEmpty()) return "";
    if(enumSet.size() == 1) return enumSet.iterator().next().name();

    Iterator<ArticleChangeType> it = enumSet.iterator();
    StringBuilder sb = new StringBuilder(it.next().name());
    while(it.hasNext()) {
        sb.append(STRING_DELIMITER).append(it.next().name());
    }

    return sb.toString();
}