@Override public C findCounter(String counterName, boolean create) { try { return findCounter(valueOf(counterName)); } catch (Exception e) { if (create) throw new IllegalArgumentException(e); return null; } }
@SuppressWarnings("unchecked") private C findCounter(T key) { int i = key.ordinal(); if (counters[i] == null) { counters[i] = newCounter(key); } return (C) counters[i]; }
@Override public C findCounter(String counterName, String displayName) { return findCounter(counterName); }
@Override public void readFields(DataInput in) throws IOException { clear(); int len = WritableUtils.readVInt(in); T[] enums = enumClass.getEnumConstants(); for (int i = 0; i < len; ++i) { int ord = WritableUtils.readVInt(in); Counter counter = newCounter(enums[ord]); counter.setValue(WritableUtils.readVLong(in)); counters[ord] = counter; } }
@Override public boolean equals(Object genericRight) { if (genericRight instanceof CounterGroupBase<?>) { @SuppressWarnings("unchecked") CounterGroupBase<C> right = (CounterGroupBase<C>) genericRight; return Iterators.elementsEqual(iterator(), right.iterator()); } return false; }
/** * FrameworkGroup ::= #counter (key value)* */ @Override @SuppressWarnings("unchecked") public void write(DataOutput out) throws IOException { WritableUtils.writeVInt(out, size()); for (int i = 0; i < counters.length; ++i) { Counter counter = (C) counters[i]; if (counter != null) { WritableUtils.writeVInt(out, i); WritableUtils.writeVLong(out, counter.getValue()); } } }
@Override public C findCounter(String counterName, String displayName) { return findCounter(counterName); }
@Override public void readFields(DataInput in) throws IOException { clear(); int len = WritableUtils.readVInt(in); T[] enums = enumClass.getEnumConstants(); for (int i = 0; i < len; ++i) { int ord = WritableUtils.readVInt(in); Counter counter = newCounter(enums[ord]); counter.setValue(WritableUtils.readVLong(in)); counters[ord] = counter; } }
@Override public boolean equals(Object genericRight) { if (genericRight instanceof CounterGroupBase<?>) { @SuppressWarnings("unchecked") CounterGroupBase<C> right = (CounterGroupBase<C>) genericRight; return Iterators.elementsEqual(iterator(), right.iterator()); } return false; }
/** * FrameworkGroup ::= #counter (key value)* */ @Override @SuppressWarnings("unchecked") public void write(DataOutput out) throws IOException { WritableUtils.writeVInt(out, size()); for (int i = 0; i < counters.length; ++i) { Counter counter = (C) counters[i]; if (counter != null) { WritableUtils.writeVInt(out, i); WritableUtils.writeVLong(out, counter.getValue()); } } }
@Override public C findCounter(String counterName, boolean create) { try { return findCounter(valueOf(counterName)); } catch (Exception e) { if (create) throw new IllegalArgumentException(e); return null; } }
@Override public C findCounter(String counterName, String displayName) { return findCounter(counterName); }
@Override public void readFields(DataInput in) throws IOException { clear(); int len = WritableUtils.readVInt(in); T[] enums = enumClass.getEnumConstants(); for (int i = 0; i < len; ++i) { int ord = WritableUtils.readVInt(in); Counter counter = newCounter(enums[ord]); counter.setValue(WritableUtils.readVLong(in)); counters[ord] = counter; } }
@SuppressWarnings("unchecked") private C findCounter(T key) { int i = key.ordinal(); if (counters[i] == null) { counters[i] = newCounter(key); } return (C) counters[i]; }
@Override public boolean equals(Object genericRight) { if (genericRight instanceof CounterGroupBase<?>) { @SuppressWarnings("unchecked") CounterGroupBase<C> right = (CounterGroupBase<C>) genericRight; return Iterators.elementsEqual(iterator(), right.iterator()); } return false; }
/** * FrameworkGroup ::= #counter (key value)* */ @Override @SuppressWarnings("unchecked") public void write(DataOutput out) throws IOException { WritableUtils.writeVInt(out, size()); for (int i = 0; i < counters.length; ++i) { Counter counter = (C) counters[i]; if (counter != null) { WritableUtils.writeVInt(out, i); WritableUtils.writeVLong(out, counter.getValue()); } } }
@Override public C findCounter(String counterName) { try { T enumValue = valueOf(counterName); return findCounter(enumValue); } catch (IllegalArgumentException e) { LOG.warn(counterName + " is not a recognized counter."); return null; } }
@Override public C findCounter(String counterName, String displayName) { return findCounter(counterName); }