public virtual void write(ExtendedDataOutput @out) { if (valueType == DATA_TYPE.DT_DICTIONARY) { throw new IOException("Can't streamlize the dictionary with value type " + valueType.name()); } BasicEntityFactory factory = new BasicEntityFactory(); Vector keys = (Vector)factory.createVectorWithDefaultValue(keyType, dict.Count); Vector values = (Vector)factory.createVectorWithDefaultValue(valueType, dict.Count); int index = 0; try { foreach (KeyValuePair <Scalar, Entity> entry in dict.SetOfKeyValuePairs()) { keys.set(index, entry.Key); values.set(index, (Scalar)entry.Value); ++index; } } catch (Exception ex) { throw new IOException(ex.Message); } int flag = ((int)DATA_FORM.DF_DICTIONARY << 8) + DataType.ordinal(); @out.writeShort(flag); keys.write(@out); values.write(@out); }
public virtual void write(ExtendedDataOutput @out) { if (valueType == DATA_TYPE.DT_DICTIONARY) { throw new IOException("Can't streamlize the dictionary with value type " + valueType.ToString()); } BasicEntityFactory factory = new BasicEntityFactory(); IVector keys = (IVector)factory.createScalarWithDefaultValue(keyType); IVector values = (IVector)factory.createVectorWithDefaultValue(valueType, dict.Count); int index = 0; try { IEnumerator <KeyValuePair <IScalar, IEntity> > itr = dict.GetEnumerator(); while (itr.MoveNext()) { keys.set(index, itr.Current.Key); values.set(index, (IScalar)itr.Current.Value); ++index; } } catch (Exception ex) { throw new IOException(ex.Message); } int flag = ((int)DATA_FORM.DF_DICTIONARY << 8) + (int)getDataType(); @out.writeShort(flag); keys.write(@out); values.write(@out); }
private IVector keys(int top) { BasicEntityFactory factory = new BasicEntityFactory(); int size = Math.Min(top, set.Count); IVector keys = (IVector)factory.createVectorWithDefaultValue(keyType, size); IEnumerator <IScalar> it = set.GetEnumerator(); int count = 0; try { while (count < size) { keys.set(count++, it.Current); it.MoveNext(); } } catch (Exception) { return(null); } return(keys); }