Skip to content

Commit

Permalink
Remove the RekordType interface. It gets in the way of some use cases.
Browse files Browse the repository at this point in the history
Resolves #1.
  • Loading branch information
SamirTalwar committed Sep 29, 2013
1 parent b980714 commit a2bea01
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 24 deletions.
6 changes: 3 additions & 3 deletions src/main/java/com/noodlesandwich/rekord/Rekord.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.Set;

public final class Rekord<T extends RekordType> {
public final class Rekord<T> {
private final String name;
private final Properties properties;

Expand All @@ -11,11 +11,11 @@ public Rekord(String name, Properties properties) {
this.properties = properties;
}

public static <T extends RekordType> Rekord<T> of(Class<T> type) {
public static <T> Rekord<T> of(Class<T> type) {
return create(type.getSimpleName());
}

public static <T extends RekordType> Rekord<T> create(String name) {
public static <T> Rekord<T> create(String name) {
return new Rekord<>(name, new Properties());
}

Expand Down
4 changes: 0 additions & 4 deletions src/main/java/com/noodlesandwich/rekord/RekordType.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,23 @@
import org.pcollections.PMap;
import com.noodlesandwich.rekord.Key;
import com.noodlesandwich.rekord.Rekord;
import com.noodlesandwich.rekord.RekordType;

import static org.hamcrest.Matchers.equalTo;

public final class RekordMatchers {
public static <T extends RekordType> RekordMatcher<T> aRekordOf(Class<T> type) {
public static <T> RekordMatcher<T> aRekordOf(Class<T> type) {
return aRekordNamed(type.getSimpleName());
}

public static <T extends RekordType> RekordMatcher<T> aRekordNamed(String name) {
public static <T> RekordMatcher<T> aRekordNamed(String name) {
return new RekordMatcher<>(name);
}

public static <T extends RekordType> Matcher<Rekord<T>> hasKey(Key<T, ?> key) {
public static <T> Matcher<Rekord<T>> hasKey(Key<T, ?> key) {
return new RekordKeyMatcher<>(key);
}

public static final class RekordMatcher<T extends RekordType> extends TypeSafeDiagnosingMatcher<Rekord<T>> {
public static final class RekordMatcher<T> extends TypeSafeDiagnosingMatcher<Rekord<T>> {
private final String name;
private PMap<Key<? super T, ?>, Matcher<?>> expectedProperties = HashTreePMap.empty();

Expand Down Expand Up @@ -67,7 +66,7 @@ protected boolean matchesSafely(Rekord<T> actualRekord, Description mismatchDesc
}
}

private static final class RekordKeyMatcher<T extends RekordType> extends TypeSafeDiagnosingMatcher<Rekord<T>> {
private static final class RekordKeyMatcher<T> extends TypeSafeDiagnosingMatcher<Rekord<T>> {
private final Key<T, ?> key;

public RekordKeyMatcher(Key<T, ?> key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.junit.rules.ExpectedException;
import com.noodlesandwich.rekord.Key;
import com.noodlesandwich.rekord.Rekord;
import com.noodlesandwich.rekord.RekordType;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.allOf;
Expand Down Expand Up @@ -47,7 +46,7 @@ public final class HamcrestValidatorTest {
box.get(Box.lessThanTen);
}

private static interface Box extends RekordType {
private static interface Box {
Key<Box,Integer> anyNumber = Key.named("any number");
Key<Box, Integer> lessThanTen = anyNumber.that(validatesItsInput(is(lessThan(10))));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.junit.Test;
import com.noodlesandwich.rekord.Key;
import com.noodlesandwich.rekord.Properties;
import com.noodlesandwich.rekord.RekordType;

import static org.hamcrest.Matchers.hasToString;
import static org.hamcrest.Matchers.is;
Expand Down Expand Up @@ -33,7 +32,7 @@ public final class NamedKeyTest {
MatcherAssert.assertThat(Thing.one, hasToString("one"));
}

private static interface Thing extends RekordType {
private static interface Thing {
Key<Thing, Integer> one = Key.named("one");
Key<Thing, Integer> two = Key.named("two");
}
Expand Down
13 changes: 6 additions & 7 deletions src/test/java/com/noodlesandwich/rekord/testobjects/Rekords.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
import java.util.Collection;
import com.noodlesandwich.rekord.Key;
import com.noodlesandwich.rekord.Rekord;
import com.noodlesandwich.rekord.RekordType;

import static com.noodlesandwich.rekord.Transformers.defaultsTo;

public final class Rekords {
private Rekords() { }

public static interface Sandvich extends RekordType {
public static interface Sandvich {
Key<Sandvich, Filling> filling = Key.named("filling");
Key<Sandvich, Bread> bread = Key.named("bread");
Key<Sandvich, Style> style = Key.<Sandvich, Style>named("style").that(defaultsTo(Style.Flat));
Expand All @@ -34,7 +33,7 @@ public static enum Style {
}
}

public static interface Wurst extends RekordType {
public static interface Wurst {
Key<Wurst, Double> curvature = Key.named("curvature");
}

Expand All @@ -47,27 +46,27 @@ public static enum Style {
}
}

public static interface Bier extends RekordType {
public static interface Bier {
Key<Bier, Measurement.Volume> volume = Key.named("volume");
Key<Bier, Measurement.Length> head = Key.named("head");
}

public static interface Person extends RekordType {
public static interface Person {
Key<Person, String> firstName = Key.named("first name");
Key<Person, String> lastName = Key.named("last name");
Key<Person, Integer> age = Key.named("age");
Key<Person, Rekord<Address>> address = Key.named("address");
}

public static interface Address extends RekordType {
public static interface Address {
Key<Address, Integer> houseNumber = Key.named("house number");
Key<Address, String> street = Key.named("street");
Key<Address, String> city = Key.named("city");
Key<Address, String> postalCode = Key.named("postal code");
}

@SuppressWarnings("UnusedDeclaration")
public static final class Jar<T extends Jar.Contents> implements RekordType {
public static final class Jar<T extends Jar.Contents> {
private static final Key contents = Key.named("contents");
@SuppressWarnings("unchecked")
public static <T extends Jar.Contents> Key<Jar<T>, Collection<T>> contents() {
Expand Down

0 comments on commit a2bea01

Please sign in to comment.