/// <summary>Convert an EnumSet to a string of comma separated values.</summary> internal static string ToString <E>(EnumSet <E> set) where E : Enum <E> { if (set == null || set.IsEmpty()) { return(string.Empty); } else { StringBuilder b = new StringBuilder(); IEnumerator <E> i = set.GetEnumerator(); b.Append(i.Next()); for (; i.HasNext();) { b.Append(',').Append(i.Next()); } return(b.ToString()); } }
/// <summary> /// reset the EnumSetWritable with specified /// <tt>value</value> and <tt>elementType</tt>. /// </summary> /// <remarks> /// 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. /// </remarks> /// <param name="value"/> /// <param name="elementType"/> public virtual void Set(EnumSet <E> value, Type elementType) { if ((value == null || value.Count == 0) && (this._elementType == null && elementType == null)) { throw new ArgumentException("The EnumSet argument is null, or is an empty set but with no elementType provided." ); } this.value = value; if (value != null && value.Count > 0) { IEnumerator <E> iterator = value.GetEnumerator(); this._elementType = iterator.Next().GetDeclaringClass(); } else { if (elementType != null) { this._elementType = elementType; } } }
/// <summary> /// test /// <c>EnumSetWritable.write(DataOutputBuffer out)</c> /// /// and iteration by TestEnumSet through iterator(). /// </summary> /// <exception cref="System.Exception"/> public virtual void TestEnumSetWritableWriteRead() { EnumSetWritable <TestEnumSetWritable.TestEnumSet> srcSet = new EnumSetWritable <TestEnumSetWritable.TestEnumSet >(EnumSet.Of(TestEnumSetWritable.TestEnumSet.Append, TestEnumSetWritable.TestEnumSet .Create), typeof(TestEnumSetWritable.TestEnumSet)); DataOutputBuffer @out = new DataOutputBuffer(); srcSet.Write(@out); EnumSetWritable <TestEnumSetWritable.TestEnumSet> dstSet = new EnumSetWritable <TestEnumSetWritable.TestEnumSet >(); DataInputBuffer @in = new DataInputBuffer(); @in.Reset(@out.GetData(), @out.GetLength()); dstSet.ReadFields(@in); EnumSet <TestEnumSetWritable.TestEnumSet> result = dstSet.Get(); IEnumerator <TestEnumSetWritable.TestEnumSet> dstIter = result.GetEnumerator(); IEnumerator <TestEnumSetWritable.TestEnumSet> srcIter = srcSet.GetEnumerator(); while (dstIter.HasNext() && srcIter.HasNext()) { Assert.Equal("testEnumSetWritableWriteRead error !!!", dstIter .Next(), srcIter.Next()); } }