public Rekord<T> accepting(Keys<T> keys) { return new LimitedRekord<>(name, keys, new PersistentProperties<T>()); } }
@Override public boolean equals(Object o) { return o instanceof FixedRekord && FixedRekordHelpers.equals(this, o); }
@Override public int hashCode() { return FixedRekordHelpers.hashCode(this); }
@SuppressWarnings("varargs") @SafeVarargs public static <T> Keys<T> from(Keys<T>... keys) { return from(Arrays.asList(keys)); }
public LimitedRekord(String name, Keys<T> acceptedKeys, Properties<T> properties) { this.delegate = new PropertyBackedFixedRekord<>(name, acceptedKeys, properties); this.acceptedKeys = acceptedKeys; this.properties = properties; }
public ValidatingRekord<T> expecting(Matcher<FixedRekord<T>> matcher) { return new ValidatingRekord<>(name, acceptedKeys, new PersistentProperties<T>(), matcher); } }
private Rekord<T> set(Properties<T> newProperties) { PropertyKeys.checkAcceptabilityOf(newProperties, acceptedKeys); return new LimitedRekord<>(name(), acceptedKeys, newProperties); }
@Override public <V> Rekord<T> with(Property<T, V> property) { return set(properties.set(property)); }
@Override public final String toString() { return name(); } }
@Override public String toString() { return serialize(new StringSerializer()); } }
@SuppressWarnings("unchecked") @Override public <V> V get(Key<T, V> key) { if (!has(key)) { return null; } return (V) properties.get(key).value(); }
@Override public boolean equals(Object other) { return other instanceof ValidRekord && FixedRekordHelpers.equals(this, other); }
@Override public int hashCode() { return FixedRekordHelpers.hashCode(this); }
ValidRekord(String name, Keys<T> acceptedKeys, Properties<T> properties) { this.delegate = new PropertyBackedFixedRekord<>(name, acceptedKeys, properties); }
@Override public PersistentProperties<T> remove(Key<T, ?> key) { return new PersistentProperties<>( properties.minus(key) ); }
@Override public <V> Rekord<T> with(Key<T, V> key, V value) { return set(key.set(value, properties)); }
@Override public boolean equals(Object other) { return other instanceof Rekord && FixedRekordHelpers.equals(this, other); }
@Override public int hashCode() { return FixedRekordHelpers.hashCode(this); }
@Override public Rekord<T> without(Key<T, ?> key) { return set(properties.remove(key)); }
@Override public <V> Rekord<T> with(V value, Key<T, V> key) { return set(key.set(value, properties)); }