Skip to content

Commit

Permalink
refactor(injector): Co-locate class binding methods
Browse files Browse the repository at this point in the history
  • Loading branch information
mrwilson committed Oct 15, 2020
1 parent 7c356d3 commit 3937afc
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/main/java/uk/co/probablyfine/inject/FemtoInjector.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,6 @@ public <T> void bind(Class<T> klass) {
bind(klass, klass);
}

public <T> void bindInstance(Class<T> klass, T instance) {
if (klass == null) {
throw new IllegalArgumentException("Binding class must not be null");
}

if (instance == null) {
throw new IllegalArgumentException("Binding instance must not be null");
}

if (boundClasses.getOrDefault(klass, null) != null) {
throw new InjectionException("Binding already exists for [" + klass.getName() + "]");
}

boundClasses.put(klass, instance);
}

public <T, U extends T> void bind(Class<T> original, Class<U> implementation) {
if (original == null) {
throw new IllegalArgumentException("Binding superclass must not be null");
Expand All @@ -97,6 +81,22 @@ public <T, U extends T> void bind(Class<T> original, Class<U> implementation) {
boundClasses.put(implementation, null);
}

public <T> void bindInstance(Class<T> klass, T instance) {
if (klass == null) {
throw new IllegalArgumentException("Binding class must not be null");
}

if (instance == null) {
throw new IllegalArgumentException("Binding instance must not be null");
}

if (boundClasses.getOrDefault(klass, null) != null) {
throw new InjectionException("Binding already exists for [" + klass.getName() + "]");
}

boundClasses.put(klass, instance);
}

private <T> Class<?> implementingClass(Class<T> originalClass) {
return boundClassToClass.getOrDefault(originalClass, originalClass);
}
Expand Down

0 comments on commit 3937afc

Please sign in to comment.