/** * Looks up the given key in the given map, converting the result into a {@link Short}. First, * {@link #getNumber(Map,Object)} is invoked. If the result is null, then null is returned. * Otherwise, the short value of the resulting {@link Number} is returned. * * @param map the map whose value to look up * @param key the key whose value to look up in that map * @return a {@link Short} or null */ public static Short getShort(Map map, Object key) { Number answer = getNumber(map, key); if (answer == null) { return null; } else if (answer instanceof Short) { return (Short) answer; } return new Short(answer.shortValue()); }
public short getParameter(String key, short defaultValue) { Number n = getNumbers().get(key); if (n != null) { return n.shortValue(); } String value = getParameter(key); if (value == null || value.length() == 0) { return defaultValue; } short s = Short.parseShort(value); getNumbers().put(key, s); return s; }
public short getMethodParameter(String method, String key, short defaultValue) { String methodKey = method + "." + key; Number n = getNumbers().get(methodKey); if (n != null) { return n.shortValue(); } String value = getMethodParameter(method, key); if (value == null || value.length() == 0) { return defaultValue; } short s = Short.parseShort(value); getNumbers().put(methodKey, s); return s; }
public Number coerceNumber(Object inputArgument, Class<?> paraType) { Number number = (Number) inputArgument; if (paraType == int.class || paraType == Integer.class) { return number.intValue(); } else if (paraType == double.class || paraType == Double.class) { return number.doubleValue(); } else if (paraType == float.class || paraType == Float.class) { return number.floatValue(); } else if (paraType == short.class || paraType == Short.class) { return number.shortValue(); } else if (paraType == byte.class || paraType == Byte.class) { return number.byteValue(); } return null; }
@Override public long hash(Number v) { // have to use a bit of reflection to ensure good hash values since // we don't have truely type specific stats if (v instanceof Long) { return hasher.hashLong(v.longValue()).asLong(); } else if (v instanceof Integer) { return hasher.hashInt(v.intValue()).asLong(); } else if (v instanceof Double) { return hasher.hashLong(Double.doubleToRawLongBits(v.doubleValue())).asLong(); } else if (v instanceof Float) { return hasher.hashInt(Float.floatToRawIntBits(v.floatValue())).asLong(); } else if (v instanceof Byte) { return hasher.newHasher().putByte(v.byteValue()).hash().asLong(); } else if (v instanceof Short) { return hasher.newHasher().putShort(v.shortValue()).hash().asLong(); } // else... throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, "Unsupported Numeric Type (" + v.getClass() + ") for hashing: " + statsField); }