/** * Looks up the given key in the given map, converting the result into a {@link Byte}. First, * {@link #getNumber(Map,Object)} is invoked. If the result is null, then null is returned. * Otherwise, the byte 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 Byte} or null */ public static Byte getByte(Map map, Object key) { Number answer = getNumber(map, key); if (answer == null) { return null; } else if (answer instanceof Byte) { return (Byte) answer; } return new Byte(answer.byteValue()); }
public byte getParameter(String key, byte defaultValue) { Number n = getNumbers().get(key); if (n != null) { return n.byteValue(); } String value = getParameter(key); if (value == null || value.length() == 0) { return defaultValue; } byte b = Byte.parseByte(value); getNumbers().put(key, b); return b; }
public byte getMethodParameter(String method, String key, byte defaultValue) { String methodKey = method + "." + key; Number n = getNumbers().get(methodKey); if (n != null) { return n.byteValue(); } String value = getMethodParameter(method, key); if (value == null || value.length() == 0) { return defaultValue; } byte b = Byte.parseByte(value); getNumbers().put(methodKey, b); return b; }
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); }
@Override public boolean getBoolean(final String key) { final Number number = this.extractNumber(this.findLastTag(key)); return number != null && number.byteValue() >= 1; }