public Clock getClock() { return ConfigHelper.getRequired(_clock); }
/** * The templatized version of the call.. to avoid downcast all the time! * * @param o * @return the object itself after checking that it is defined * @throws MissingConfigParameterException if it is not defined */ public static <T> T getRequired(final T o) throws MissingConfigParameterException { if (o == null) { throw new MissingConfigParameterException("required Object has not been defined"); } return o; } }
/** * @param defaultValue * is returned when the value of the {@code key} is null in the {@code map}. * cannot be null * @return returned type is always the same as the type of {@code defaultValue} */ @SuppressWarnings("unchecked") public static <K, V> V getWithDefault(final Map<K, ? extends Object> map, final K key, final V defaultValue) { if (defaultValue == null) { throw new IllegalArgumentException("received null default value for key = " + key); } return getWithDefault(map, key, defaultValue, (Class<V>) defaultValue.getClass()); }
private void checkDone() { if (_count.decrementAndGet() == 0) { if (_exceptions.isEmpty()) { _callback.onSuccess(None.none()); } else { _callback.onError(new MultiException(_exceptions)); } } } }
public double getGrowthFactor() { return ConfigHelper.getRequired(_growthFactor); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullArgument() { MapUtil.getWithDefault(_subjectMap, "subMap", null); MapUtil.getWithDefault(_subjectMap, "subMap_default", null); }
/** * Returns a new callback which defers invocation of another callback until a specified * number of onSuccess() or onError() calls to the new callback have occured. * * @param callback * the underlying callback * @param count * the number of combined onSuccess()/onError() calls that must be invoked on * the new callback before the underlying callback's onSuccess (if all were * successful) or onError (if any errors occurred) method is invoked. If count * is zero, the underlying callback's onSuccess will be invoked immediately on * the calling thread. * @return the new callback */ public static Callback<None> countDown(final Callback<None> callback, final int count) { if (count == 0) { callback.onSuccess(None.none()); return empty(); } return new MultiCallback(callback, count); }
/** * Given an object object, checks if it is defined. If not throws an exception. * If yes returns the value. * * @param o * @return the object itself after checking that it is defined * @throws MissingConfigParameterException if it is not defined */ public static Object getRequiredObject(final Object o) throws MissingConfigParameterException { if (o == null) { throw new MissingConfigParameterException("required Object has not been defined"); } return o; }
public String getName() { return ConfigHelper.getRequired(_name); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testSiblingCastException() { MapUtil.getWithDefault(_subjectMap, "siblingMap", _probeMap); }
public CallTracker getCallTracker() { return ConfigHelper.getRequired(_callTracker); }
@Test public void testGetWithDefault() { Assert.assertTrue(MapUtil.getWithDefault(_subjectMap, "boolean", false)); Assert.assertFalse(MapUtil.getWithDefault(_subjectMap, "boolean_default", false)); Assert.assertEquals(MapUtil.getWithDefault(_subjectMap, "integer", 11), (Integer) 1); Assert.assertEquals(MapUtil.getWithDefault(_subjectMap, "integer_default", 11), (Integer) 11); Assert.assertEquals(MapUtil.getWithDefault(_subjectMap, "long", 12L), (Long) 2L); Assert.assertEquals(MapUtil.getWithDefault(_subjectMap, "long_default", 12L), (Long) 12L); Assert.assertEquals(MapUtil.getWithDefault(_subjectMap, "float", 13F), 3F); Assert.assertEquals(MapUtil.getWithDefault(_subjectMap, "float_default", 13F), 13F); Assert.assertEquals(MapUtil.getWithDefault(_subjectMap, "double", 14D), 4D); Assert.assertEquals(MapUtil.getWithDefault(_subjectMap, "double_default", 14D), 14D); Assert.assertEquals(MapUtil.getWithDefault(_subjectMap, "string", "Bar"), "Foo"); Assert.assertEquals(MapUtil.getWithDefault(_subjectMap, "string_default", "Bar"), "Bar"); Assert.assertSame(MapUtil.getWithDefault(_subjectMap, "subMap", null, LinkedHashMap.class).getClass(), LinkedHashMap.class); Assert.assertSame(MapUtil.getWithDefault(_subjectMap, "subMap", _probeMap).getClass(), LinkedHashMap.class); Assert.assertSame(MapUtil.getWithDefault(_subjectMap, "subMap_default", _probeMap).getClass(), HashMap.class); Assert.assertNull(MapUtil.getWithDefault(_subjectMap, "subMap_default", null, Object.class)); Assert.assertSame(MapUtil.getWithDefault(_subjectMap, "siblingMap", null, Hashtable.class).getClass(), Hashtable.class); Assert.assertSame(MapUtil.getWithDefault(_subjectMap, "siblingMap", _probeMap, Map.class).getClass(), Hashtable.class); Assert.assertSame(MapUtil.getWithDefault(_subjectMap, "siblingMap_default", _probeMap, Map.class).getClass(), HashMap.class); }
public int getInitialCapacity() { return ConfigHelper.getRequired(_initialCapacity); }
public LatencyToUse getLatencyToUse() { return ConfigHelper.getRequired(_latencyToUse); }
public int getMaxCapacity() { return ConfigHelper.getRequired(_maxCapacity); }
public Clock getClock() { return ConfigHelper.getRequired(_clock); }
public int getMaxCapacity() { return ConfigHelper.getRequired(_maxCapacity); }
public double getGrowthFactor() { return ConfigHelper.getRequired(_growthFactor); }
public LatencyToUse getLatencyToUse() { return ConfigHelper.getRequired(_latencyToUse); }
public String getName() { return ConfigHelper.getRequired(_name); }