Refine search
public StatsCollector() { counters = new EnumMap<>(Counter.class); durations = new EnumMap<>(Duration.class); for (Counter counter : Counter.values()) { counters.put(counter, new AtomicInteger(0)); } for (Duration duration : Duration.values()) { durations.put(duration, new AtomicLong(0)); } }
/** * Returns the instance at the given slot. * * @param slot slot number to return instance for. * @return the instance at the given {@code slot}. */ T select( IndexSlot slot ) { if ( !instances.containsKey( slot ) ) { throw new IllegalStateException( "Instance is not instantiated" ); } return instances.get( slot ); }
public void addProposeSequenceNumberDuration(long durationValue, boolean isLastProposeMessage) { if (!shouldCollectStats(durationValue)) { return; } Counter counter = isLastProposeMessage ? Counter.LAST_PROPOSE_MESSAGE_RECEIVED : Counter.PROPOSE_MESSAGE_RECEIVED; Duration duration = isLastProposeMessage ? Duration.LAST_PROPOSE_MESSAGE : Duration.PROPOSE_MESSAGE; counters.get(counter).incrementAndGet(); durations.get(duration).addAndGet(durationValue); }
public void addAnycastSentDuration(long duration, int numberOfUnicasts) { if (!shouldCollectStats(duration)) { return; } counters.get(StatsCollector.Counter.UNICAST_MESSAGE_SENT).addAndGet(numberOfUnicasts); counters.get(Counter.ANYCAST_MESSAGE_SENT).incrementAndGet(); durations.get(Duration.ANYCAST_MESSAGE_SENT).addAndGet(duration); }
public void incrementMessageDeliver() { if (!shouldCollectStats()) { return ; } counters.get(Counter.ANYCAST_MESSAGE_DELIVERED).incrementAndGet(); }
public StoreClientFactoryStats() { counters = new EnumMap<Tracked, AtomicInteger>(Tracked.class); for (Tracked tracked: Tracked.values()) counters.put(tracked, new AtomicInteger(0)); }
@SuppressWarnings("unchecked") @Override <K extends K0, V> Map<K, Collection<V>> createMap() { // K must actually be K0, since enums are effectively final // (their subclasses are inaccessible) return (Map<K, Collection<V>>) new EnumMap<K0, Collection<V>>(keyClass); } };
@Override public V get(Object key) { return delegate.get(key); }
private static <T> EnumMap<TemplateMode, Set<T>> listMapToSetMap(final EnumMap<TemplateMode, List<T>> map) { final EnumMap<TemplateMode, Set<T>> newMap = new EnumMap<TemplateMode, Set<T>>(TemplateMode.class); for (final Map.Entry<TemplateMode, List<T>> entry : map.entrySet()) { newMap.put(entry.getKey(), new LinkedHashSet<T>(entry.getValue())); } return newMap; }
/** * Put a new mapping to this selector */ void put( IndexSlot slot, T instance ) { instances.put( slot, instance ); }
@Test public void testStandardEnumMapWithMultipleValues() { GenericBean<?> gb = new GenericBean<>(); BeanWrapper bw = new BeanWrapperImpl(gb); bw.setConversionService(new DefaultConversionService()); assertNull(gb.getStandardEnumMap()); Map<String, Integer> map = new LinkedHashMap<>(); map.put("VALUE_1", 1); map.put("VALUE_2", 2); bw.setPropertyValue("standardEnumMap", map); assertEquals(2, gb.getStandardEnumMap().size()); assertEquals(new Integer(1), gb.getStandardEnumMap().get(CustomEnum.VALUE_1)); assertEquals(new Integer(2), gb.getStandardEnumMap().get(CustomEnum.VALUE_2)); }
private static void addCurveRule( int... npointValues ) { HilbertCurve2D curve = new HilbertCurve2D( npointValues ); Direction2D name = curve.name(); if ( !curves.containsKey( name ) ) { curves.put( name, curve ); } }
static <K extends Enum<K>, V> ImmutableMap<K, V> asImmutable(EnumMap<K, V> map) { switch (map.size()) { case 0: return ImmutableMap.of(); case 1: Entry<K, V> entry = Iterables.getOnlyElement(map.entrySet()); return ImmutableMap.of(entry.getKey(), entry.getValue()); default: return new ImmutableEnumMap<>(map); } }
@Override UnmodifiableIterator<Entry<K, V>> entryIterator() { return Maps.unmodifiableEntryIterator(delegate.entrySet().iterator()); }
public boolean inFullSnapshot() { return strategies.containsKey(Strategies.FULL_STATE_SCAN_SNAPSHOT); }