public static IdentityBuilder seed(int seed) { return new IdentityBuilder(seed); }
/** * Convenience method for getting an identity builder given a seed */ protected IdentityBuilder identity(int seed) { return IdentityBuilder.seed(seed); }
/** * 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(); }
protected Experiment(Experiments owner, String name) { this.owner = owner; this.name = name; this.filter = FilterExpression.alwaysTrue(); this.hashAttributes = EMPTY_SET; this.allocations = new Allocations(); this.treatments = Maps.newConcurrentMap(); this.overrides = Maps.newConcurrentMap(); this.seed = (int) IdentityBuilder.seed(0).putString(name).hash(); }
public IdentityBuilder putShort(Short value) { if (value == null) { putNull(); } else { hasher.putShort(value); } return this; }
public IdentityBuilder putChar(Character value) { if (value == null) { putNull(); } else { hasher.putChar(value); } return this; }
public IdentityBuilder putInt(Integer value) { if (value == null) { putNull(); } else { hasher.putInt(value); } return this; }
public IdentityBuilder putFloat(Float value) { if (value == null) { putNull(); } else { hasher.putFloat(value); } return this; }
public IdentityBuilder putLong(Long value) { if (value == null) { putNull(); } else { hasher.putLong(value); } return this; }
public IdentityBuilder putBoolean(Boolean value) { if (value == null) { putNull(); } else { hasher.putBoolean(value); } return this; }
public IdentityBuilder putString(CharSequence value) { if (value == null) { putNull(); } else { hasher.putString(value, CHARSET); } return this; }
public IdentityBuilder putByte(Byte value) { if (value == null) { putNull(); } else { hasher.putByte(value); } return this; }
public IdentityBuilder putBytes(byte[] value) { if (value == null) { putNull(); } else { hasher.putBytes(value); } return this; }
public IdentityBuilder putBytes(byte[] value, int start, int length) { if (value == null) { putNull(); } else { hasher.putBytes(value, start, length); } return this; }
public IdentityBuilder putDouble(Double value) { if (value == null) { putNull(); } else { hasher.putDouble(value); } return this; }