public UnsureRekord<T> accepting(Keys<T> keys) { return new UnsureRekord<>(name, keys); } }
public static <T> UnkeyedRekord<T> create(String name) { return new UnkeyedRekord<>(name); }
public static <T> UnkeyedRekord<T> of(Class<T> type) { return create(type.getSimpleName()); }
public ValidRekord<T> fix() throws InvalidRekordException { ValidRekord<T> rekord = new ValidRekord<>(name, acceptedKeys, properties); if (!matcher.matches(rekord)) { StringDescription description = new StringDescription(); description.appendText("Expected that ").appendDescriptionOf(matcher).appendText(", but "); matcher.describeMismatch(rekord, description); description.appendText("."); throw new InvalidRekordException(description.toString()); } return rekord; }
@Override public <V> ValidatingRekord<T> with(V value, Key<T, V> key) { return set(key.set(value, properties)); }
private ValidatingRekord<T> set(Properties<T> newProperties) { PropertyKeys.checkAcceptabilityOf(newProperties, acceptedKeys); return new ValidatingRekord<>(name, acceptedKeys, newProperties, matcher); }
public static <T> RekordMatcher<T> aRekordNamed(String name) { return new RekordMatcher<>(name, HashTreePMap.<Key<T, ?>, Matcher<?>>empty()); }
public static <T> RekordMatcher<T> aRekordOf(Class<T> type) { return aRekordNamed(type.getSimpleName()); }
public <V> RekordMatcher<T> with(Key<T, V> key, V value) { return with(key, equalTo(value)); }
@Override public ValidatingRekord<T> merge(FixedRekord<T> other) { ValidatingRekord<T> result = this; for (Property<T, ?> property : other.properties()) { result = result.with(property); } return result; }
@SuppressWarnings("varargs") @SafeVarargs public final UnsureRekord<T> accepting(Keys<T>... keys) { return accepting(KeySet.from(keys)); } // CHECKSTYLE:ON
@Override public <V> ValidatingRekord<T> with(Key<T, V> key, V value) { return set(key.set(value, properties)); }
public ValidatingRekord<T> expecting(Matcher<FixedRekord<T>> matcher) { return new ValidatingRekord<>(name, acceptedKeys, new PersistentProperties<T>(), matcher); } }
public <V> RekordMatcher<T> with(Key<T, V> key, Matcher<V> valueMatcher) { return new RekordMatcher<>(name, expectedProperties.plus(key, valueMatcher)); }
@Override public ValidatingRekord<T> without(Key<T, ?> key) { return set(properties.remove(key)); }
@Override public <V> ValidatingRekord<T> with(Property<T, V> property) { return set(properties.set(property)); }