Skip to content

Commit

Permalink
Refactoring (#13)
Browse files Browse the repository at this point in the history
* Major refactoring/simplifying

Signed-off-by: Laird Nelson <ljnelson@gmail.com>

* Refactoring

Signed-off-by: Laird Nelson <ljnelson@gmail.com>

---------

Signed-off-by: Laird Nelson <ljnelson@gmail.com>
  • Loading branch information
ljnelson authored Oct 1, 2024
1 parent fe71dd5 commit a7be161
Show file tree
Hide file tree
Showing 44 changed files with 1,959 additions and 1,518 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ dependency:
<groupId>org.microbean</groupId>
<artifactId>microbean-bean</artifactId>
<!-- Always check https://search.maven.org/artifact/org.microbean/microbean-bean for up-to-date available versions. -->
<version>0.0.8</version>
<version>0.0.9</version>
</dependency>
```

Expand Down
13 changes: 7 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,21 @@
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-core-bom</artifactId>
<version>5.1.2.Final</version>
<version>5.1.3.Final</version>
<type>pom</type>
<scope>import</scope>
</dependency>


<!-- Normal dependencies. -->


<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.10.2</version>
</dependency>


<!-- Normal dependencies. -->

<dependency>
<groupId>org.microbean</groupId>
<artifactId>microbean-constant</artifactId>
Expand All @@ -84,7 +85,7 @@
<dependency>
<groupId>org.microbean</groupId>
<artifactId>microbean-lang</artifactId>
<version>0.0.19</version>
<version>0.0.20</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -387,7 +388,7 @@

<!-- maven-javadoc-plugin properties -->
<detectJavaApiLink>false</detectJavaApiLink>
<links>https://docs.oracle.com/en/java/javase/21/docs/api/,https://microbean.github.io/microbean-lang/apidocs/</links>
<links>https://docs.oracle.com/en/java/javase/21/docs/api/,https://microbean.github.io/microbean-lang/apidocs/,https://microbean.github.io/microbean-qualifier/apidocs/,https://microbean.github.io/microbean-scope/apidocs/</links>

<!-- maven-release-plugin properties; see http://maven.apache.org/maven-release/maven-release-plugin/ -->
<goals>deploy,post-site,scm-publish:publish-scm</goals>
Expand Down
27 changes: 7 additions & 20 deletions src/main/java/org/microbean/bean/AbstractFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
import java.util.Objects;

// TODO: this is mildly fouled up. The spirit is right but the implementation is not so hot.
@Deprecated
@Deprecated(forRemoval = true)
abstract class AbstractFactory<I> implements Factory<I> {

private static final Initializer<?> PASSTHROUGH_INITIALIZER = new AbstractInitializer<Object>();
private static final Initializer<?> PASSTHROUGH_INITIALIZER = (i, r) -> i;

private static final PostInitializer<?> PASSTHROUGH_POSTINITIALIZER = new AbstractPostInitializer<Object>();
private static final PostInitializer<?> PASSTHROUGH_POSTINITIALIZER = (i, r) -> i;

private static final InterceptionsApplicator<?> PASSTHROUGH_INTERCEPTIONSAPPLICATOR = new AbstractInterceptionsApplicator<Object>();
private static final InterceptionsApplicator<?> PASSTHROUGH_INTERCEPTIONSAPPLICATOR = (i, r) -> i;

private static final PreDestructor<?> PASSTHROUGH_PREDESTRUCTOR = new AbstractPreDestructor<Object>();
private static final PreDestructor<?> PASSTHROUGH_PREDESTRUCTOR = (i, r) -> i;

private final Producer<I> producer;

Expand Down Expand Up @@ -68,24 +68,11 @@ public boolean destroys() {
// MUST be idempotent
@Override // Factory<I>
@SuppressWarnings("try")
public void destroy(final I i, final AutoCloseable destructionRegistry, final Request<I> r) {
public void destroy(final I i, final Request<I> r) {
if (this.destroyed) {
return;
}
if (destructionRegistry == null) {
this.producer.dispose(this.preDestructor.preDestroy(i, r), r);
} else {
try (destructionRegistry) {
this.producer.dispose(this.preDestructor.preDestroy(i, r), r);
} catch (final RuntimeException | Error e) {
throw e;
} catch (final InterruptedException e) {
Thread.currentThread().interrupt();
throw new DestructionException(e.getMessage(), e);
} catch (final Exception e) {
throw new DestructionException(e.getMessage(), e);
}
}
this.producer.dispose(this.preDestructor.preDestroy(i, r), r);
this.destroyed = true;
}

Expand Down
63 changes: 0 additions & 63 deletions src/main/java/org/microbean/bean/AbstractInitializer.java

This file was deleted.

This file was deleted.

27 changes: 0 additions & 27 deletions src/main/java/org/microbean/bean/AbstractPostInitializer.java

This file was deleted.

27 changes: 0 additions & 27 deletions src/main/java/org/microbean/bean/AbstractPreDestructor.java

This file was deleted.

22 changes: 0 additions & 22 deletions src/main/java/org/microbean/bean/AbstractProducer.java

This file was deleted.

17 changes: 16 additions & 1 deletion src/main/java/org/microbean/bean/Aggregate.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@
/**
* An object with {@linkplain Dependency dependencies}.
*
* <p>By default, {@link Aggregate}s have no dependencies.</p>
*
* @author <a href="https://about.me/lairdnelson/" target="_top">Laird Nelson</a>
*
* @see #dependencies()
*/
public interface Aggregate {

/**
* An immutable, empty {@link SequencedSet}.
*/
public static final SequencedSet<Dependency> EMPTY_DEPENDENCIES = Collections.unmodifiableSequencedSet(new LinkedHashSet<>(0));

/**
Expand All @@ -41,10 +46,20 @@ public default SequencedSet<Dependency> dependencies() {
return EMPTY_DEPENDENCIES;
}

/**
* Assigns a contextual reference to each of this {@link Aggregate}'s {@link Dependency} instances and returns the
* resulting {@link List} of {@link Assignment}s.
*
* @param r a {@link Request}; must not be {@code null}
*
* @return a {@link List} of {@link Assignment} instances; never {@code null}
*
* @exception NullPointerException if {@code r} is {@code null}
*/
public default List<Assignment> assign(final Request<?> r) {
final Collection<? extends Dependency> ds = this.dependencies();
return ds == null || ds.isEmpty() ? List.of() : ds.stream()
.map(d -> Assignment.of(d, r))
.map(d -> new Assignment(d, r.reference(d.beanSelectionCriteria(), r)))
.toList();
}

Expand Down
58 changes: 26 additions & 32 deletions src/main/java/org/microbean/bean/AmbiguousReductionException.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,56 +16,50 @@
import java.util.Collection;
import java.util.List;

/**
* A {@link ReductionException} indicating that many contextual instances could not be reduced to one.
*
* @author <a href="https://about.me/lairdnelson" target="_top">Laird Nelson</a>
*/
public class AmbiguousReductionException extends ReductionException {

private static final long serialVersionUID = 1L;

private final transient Collection<?> alternates;

public AmbiguousReductionException() {
this(null, null, null, null);
}

public AmbiguousReductionException(final Collection<?> alternates,
final String message) {
this(null, alternates, message, null);
}

public AmbiguousReductionException(final Object criteria,
final Collection<?> alternates,
final String message) {
this(criteria, alternates, message, null);
}

public AmbiguousReductionException(final Collection<?> alternates,
final Throwable cause) {
this(null, alternates, null, cause);
}

public AmbiguousReductionException(final Object criteria,
final Collection<?> alternates,
final Throwable cause) {
this(criteria, alternates, null, cause);
}
/*
* Constructors.
*/

public AmbiguousReductionException(final Collection<?> alternates,
final String message,
final Throwable cause) {
this(null, alternates, message, cause);
}

/**
* Creates a new {@link AmbiguousReductionException}.
*
* @param criteria the criteria by which a reduction was supposed to be effected; may be {@code null}
*
* @param alternates the contextual instances that could not be reduced; may be {@code null}
*
* @param message a detail message describing the exception; may be {@code null}
*/
public AmbiguousReductionException(final Object criteria,
final Collection<?> alternates,
final String message,
final Throwable cause) {
super(criteria, message, cause);
final String message) {
super(criteria, message, null);
if (alternates == null || alternates.isEmpty()) {
this.alternates = List.of();
} else {
this.alternates = List.copyOf(alternates);
}
}

/**
* Returns the contextual instances that could not be reduced.
*
* <p>This method never returns {@code null}.</p>
*
* @return a non-{@code null}, immutable {@link Collection} of contextual instances
*/
public final Collection<?> alternates() {
return this.alternates;
}
Expand Down
Loading

0 comments on commit a7be161

Please sign in to comment.