Skip to content

Commit

Permalink
! update after release v0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
oldratlee committed Mar 27, 2024
1 parent 968adcb commit a4b0c6f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 12 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,20 +295,20 @@ For `Maven` projects:
<dependency>
<groupId>io.foldright</groupId>
<artifactId>inspectable-wrappers</artifactId>
<version>0.4.0</version>
<version>0.5.0</version>
</dependency>
```

For `Gradle` projects:

```groovy
// Gradle Kotlin DSL
implementation("io.foldright:inspectable-wrappers:0.4.0")
implementation("io.foldright:inspectable-wrappers:0.5.0")
```

```groovy
// Gradle Groovy DSL
implementation 'io.foldright:inspectable-wrappers:0.4.0'
implementation 'io.foldright:inspectable-wrappers:0.5.0'
```

`inspectable-wrappers` has published to maven central, find the latest version at [central.sonatype.com](https://central.sonatype.com/artifact/io.foldright/inspectable-wrappers/0.3.0/versions).
24 changes: 24 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,30 @@
<organization>FoldRight</organization>
<organizationUrl>https://foldright.io</organizationUrl>
</developer>
<developer>
<name>Zava Xu</name>
<id>zavakid</id>
<email>zava.kid(AT)gmail(DOT)com</email>
<roles>
<role>Developer</role>
</roles>
<timezone>+8</timezone>
<url>https://github.com/zavakid</url>
<organization>FoldRight</organization>
<organizationUrl>https://foldright.io</organizationUrl>
</developer>
<developer>
<name>Yang Fang</name>
<id>driventokill</id>
<email>snoop(DOT)fy(AT)gmail(DOT)com</email>
<roles>
<role>Developer</role>
</roles>
<timezone>+8</timezone>
<url>https://github.com/driventokill</url>
<organization>FoldRight</organization>
<organizationUrl>https://foldright.io</organizationUrl>
</developer>
</developers>

<properties>
Expand Down
20 changes: 11 additions & 9 deletions src/main/java/io/foldright/inspectablewrappers/Inspector.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* <ul>
* <li>Reports whether any instance on the wrapper chain satisfy the given {@link Predicate}
* by static method {@link #inspect(Object, Predicate)}
* <li>Traverses the wrapper chain, and applies the given {@link Function} to each instance on the wrapper chain,
* <li>Traverses the wrapper chain and applies the given {@link Function} to each instance on the wrapper chain
* by static method {@link #travel(Object, Function)}
* </ul>
* <p>
Expand Down Expand Up @@ -122,8 +122,8 @@ public static <W> boolean inspect(final W wrapper, final Predicate<? super W> pr
}

/**
* Traverses the wrapper chain, and applies the given {@code process} function to
* each instance on the wrapper chain, and returns the first non-empty({@link Optional#empty()}) result
* Traverses the wrapper chain and applies the given {@code process} function to
* each instance on the wrapper chain, returns the first non-empty({@link Optional#empty()}) result
* of the process function, otherwise returns {@link Optional#empty()}.
* <p>
* The wrapper chain consists of wrapper itself, followed by the wrappers
Expand All @@ -150,7 +150,7 @@ public static <W, T> Optional<T> travel(final W wrapper, final Function<? super
Optional<T> result = process.apply((W) w);
if (result.isPresent()) return result;

// also process the adaptee if it's a WrapperAdapter
// also process the adaptee for WrapperAdapter
if (w instanceof WrapperAdapter) {
Optional<T> r = process.apply((W) adapteeNonWrapper(w));
if (r.isPresent()) return r;
Expand All @@ -164,16 +164,18 @@ public static <W, T> Optional<T> travel(final W wrapper, final Function<? super
/**
* Gets adaptee of the given WrapperAdapter instance with {@code null} check and non-{@link Wrapper} type check.
*/
private static Object adapteeNonWrapper(Object w) {
final Object adaptee = ((WrapperAdapter<?>) w).adaptee();
Supplier<String> msg = () -> "adaptee of WrapperAdapter(" + w.getClass().getName() + ") is null";
private static Object adapteeNonWrapper(final Object wrapper) {
final Object adaptee = ((WrapperAdapter<?>) wrapper).adaptee();

Supplier<String> msg = () -> "adaptee of WrapperAdapter(" + wrapper.getClass().getName() + ") is null";
requireNonNull(adaptee, msg);

if (adaptee instanceof Wrapper) {
throw new IllegalStateException("adaptee(" + adaptee.getClass().getName() +
") of WrapperAdapter(" + w.getClass().getName() +
") of WrapperAdapter(" + wrapper.getClass().getName() +
") is type Wrapper, adapting a Wrapper to a Wrapper is unnecessary!");
}

return adaptee;
}

Expand All @@ -187,7 +189,7 @@ private static Object unwrapNonNull(final Object wrapper) {
}

/**
* no need to create instance at all
* NO need to create instance at all
*/
private Inspector() {
}
Expand Down

0 comments on commit a4b0c6f

Please sign in to comment.