stack.push(attributes.getNumber(name) != 0); } else if (type == Boolean.class) { stack.push(attributes.getBoolean(name)); } else { stack.push(false);
private Comparable getValue(FilterParser.ValueContext context) { if (context.IDENTIFIER() != null) { // identifier final String identifier = context.IDENTIFIER().getText(); final Class<?> type = attributes.getType(identifier); if (type == String.class) { return attributes.getString(identifier); } else if (type == Long.class) { return attributes.getNumber(identifier); } else if (type == Boolean.class) { return attributes.getBoolean(identifier); } return null; } else { // constant final FilterParser.ConstantContext constant = context.constant(); if (constant.STRING() != null) { final String value = constant.STRING().getText(); return value.length() == 2 ? "" : value.substring(1, value.length() - 1); } else if (constant.NUMBER() != null) { return Long.parseLong(constant.NUMBER().getText()); } else if (constant.BOOLEAN() != null) { return Boolean.parseBoolean(constant.BOOLEAN().getText()); } return null; } }
/** * generates a hash code used to assign identity to treatment * @param seed a seed value to randomize the resulting hash from experiment to experiment for the same identity * @param hashAttributes a set of attributes that should be used to compute the hash code * @param attributes a map of attribute values */ public long computeHash(int seed, Set<String> hashAttributes, AttributesMap attributes) { final IdentityBuilder builder = IdentityBuilder.seed(seed); final Iterable<String> names = hashAttributes.isEmpty() ? attributes.keySet() : hashAttributes; for (String name : names) { final Class<?> type = attributes.getType(name); if (type == String.class) { builder.putString(attributes.getString(name)); } else if (type == Long.class) { builder.putLong(attributes.getNumber(name)); } else if (type == Boolean.class) { builder.putBoolean(attributes.getBoolean(name)); } } return builder.hash(); }