From 08ae76afb4bbf188965a1ecd63f148020920ca62 Mon Sep 17 00:00:00 2001 From: Jerry Lee Date: Sat, 13 Apr 2024 21:10:40 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20rename=20wrapper=20spec=20methods?= =?UTF-8?q?=20with=20postfix=20`=5F`,=20=20avoid=20naming=20conflict=20wit?= =?UTF-8?q?h=20biz=20methods=20=F0=9F=91=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 30 +++++----- .../inspectablewrappers/Attachable.java | 4 +- .../inspectablewrappers/Inspector.java | 60 +++++++++---------- .../inspectablewrappers/Wrapper.java | 4 +- .../inspectablewrappers/WrapperAdapter.java | 2 +- .../utils/AttachableDelegate.java | 4 +- .../utils/WrapperAdapterUtils.java | 44 +++++++------- .../foldright/demo/ChattyExecutorWrapper.java | 2 +- src/test/java/io/foldright/demo/Demo.java | 2 +- .../foldright/demo/LazyExecutorWrapper.java | 10 ++-- .../demo/integration/IntegrationDemo.java | 14 ++--- ...tegrationDemoUsingWrapperAdapterUtils.java | 2 +- .../SpecificationContractsTest.java | 8 +-- .../inspectablewrappers/WrapperAdapterTest.kt | 10 ++-- .../inspectablewrappers/WrapperTest.kt | 10 ++-- .../utils/WrapperAdapterUtilsTest.kt | 8 +-- 16 files changed, 107 insertions(+), 107 deletions(-) diff --git a/README.md b/README.md index 7274ace..fa39006 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ public class ChattyExecutorWrapper implements Executor, Wrapper { } @Override - public Executor unwrap() { + public Executor unwrap_() { return executor; } } @@ -102,20 +102,20 @@ public class LazyExecutorWrapper implements Executor, Wrapper, Attacha } @Override - public Executor unwrap() { + public Executor unwrap_() { return executor; } private final Attachable attachable = new AttachableDelegate<>(); @Override - public void setAttachment(String key, String value) { - attachable.setAttachment(key, value); + public void setAttachment_(String key, String value) { + attachable.setAttachment_(key, value); } @Override - public String getAttachment(String key) { - return attachable.getAttachment(key); + public String getAttachment_(String key) { + return attachable.getAttachment_(key); } } ``` @@ -154,7 +154,7 @@ public class Demo { final Executor base = Runnable::run; final LazyExecutorWrapper lazy = new LazyExecutorWrapper(base); - lazy.setAttachment("busy", "very, very busy!"); + lazy.setAttachment_("busy", "very, very busy!"); return new ChattyExecutorWrapper(lazy); } @@ -231,7 +231,7 @@ public class IntegrationDemo { private static ExistedExecutorWrapperAdapter createExistedExecutorWrapperAdapter(Executor base) { final ExistedExecutorWrapper existed = new ExistedExecutorWrapper(base); final ExistedExecutorWrapperAdapter adapter = new ExistedExecutorWrapperAdapter(base, existed); - adapter.setAttachment("adapted-existed-executor-wrapper-msg", "I'm an adapter of an existed executor which have nothing to do with ~inspectable~wrappers~."); + adapter.setAttachment_("adapted-existed-executor-wrapper-msg", "I'm an adapter of an existed executor which have nothing to do with ~inspectable~wrappers~."); return adapter; } @@ -248,12 +248,12 @@ public class IntegrationDemo { } @Override - public Executor unwrap() { + public Executor unwrap_() { return base; } @Override - public Executor adaptee() { + public Executor adaptee_() { return adaptee; } @@ -265,14 +265,14 @@ public class IntegrationDemo { private final Attachable attachable = new AttachableDelegate<>(); @Override - public void setAttachment(String key, String value) { - attachable.setAttachment(key, value); + public void setAttachment_(String key, String value) { + attachable.setAttachment_(key, value); } @Nullable @Override - public String getAttachment(String key) { - return attachable.getAttachment(key); + public String getAttachment_(String key) { + return attachable.getAttachment_(key); } } } @@ -329,7 +329,7 @@ public class IntegrationDemoUsingWrapperAdapterUtils { final Executor existed = new ExistedExecutorWrapper(base); Attachable attachable = new AttachableDelegate<>(); - attachable.setAttachment("adapted-existed-executor-wrapper-msg", "I'm an adapter of an existed executor which have nothing to do with ~inspectable~wrappers~."); + attachable.setAttachment_("adapted-existed-executor-wrapper-msg", "I'm an adapter of an existed executor which have nothing to do with ~inspectable~wrappers~."); return WrapperAdapterUtils.createWrapperAdapter(Executor.class, base, existed, attachable); } diff --git a/src/main/java/io/foldright/inspectablewrappers/Attachable.java b/src/main/java/io/foldright/inspectablewrappers/Attachable.java index 5445713..00ef0c1 100644 --- a/src/main/java/io/foldright/inspectablewrappers/Attachable.java +++ b/src/main/java/io/foldright/inspectablewrappers/Attachable.java @@ -29,7 +29,7 @@ public interface Attachable { * @param value the attachment value * @throws NullPointerException if any arguments is null */ - void setAttachment(@NonNull K key, @NonNull V value); + void setAttachment_(@NonNull K key, @NonNull V value); /** * Gets the attachment value for the given key. @@ -41,5 +41,5 @@ public interface Attachable { * @see Inspector#getAttachmentFromWrapperChain(Object, Object) */ @Nullable - V getAttachment(@NonNull K key); + V getAttachment_(@NonNull K key); } diff --git a/src/main/java/io/foldright/inspectablewrappers/Inspector.java b/src/main/java/io/foldright/inspectablewrappers/Inspector.java index 4fd77eb..e224f89 100644 --- a/src/main/java/io/foldright/inspectablewrappers/Inspector.java +++ b/src/main/java/io/foldright/inspectablewrappers/Inspector.java @@ -78,7 +78,7 @@ public final class Inspector { * Reports whether any instance on the wrapper chain matches the given type. *

* The wrapper chain consists of wrapper itself, followed by the wrappers - * obtained by repeatedly calling {@link Wrapper#unwrap()}. + * obtained by repeatedly calling {@link Wrapper#unwrap_()}. * * @param wrapper wrapper instance/wrapper chain * @param instanceType target type @@ -86,7 +86,7 @@ public final class Inspector { * @return return {@code false} if no wrapper on the wrapper chain matches the given type, * otherwise return {@code true} * @throws NullPointerException if any arguments is null, - * or any wrapper {@link Wrapper#unwrap()} returns null, + * or any wrapper {@link Wrapper#unwrap_()} returns null, * or the adaptee of {@link WrapperAdapter} is null * @throws IllegalStateException if the adaptee of {@link WrapperAdapter} is an instance of {@link Wrapper} * or CYCLIC wrapper chain @@ -104,10 +104,10 @@ private static boolean isInstanceOf(final Object o, final Class clazz) { /** * Retrieves the attachment of instance on the wrapper chain for the given key - * by calling {@link Attachable#getAttachment(Object)}. + * by calling {@link Attachable#getAttachment_(Object)}. *

* The wrapper chain consists of wrapper itself, followed by the wrappers - * obtained by repeatedly calling {@link Wrapper#unwrap()}. + * obtained by repeatedly calling {@link Wrapper#unwrap_()}. *

* If the same key exists in multiple wrappers, outer wrapper win. * @@ -119,12 +119,12 @@ private static boolean isInstanceOf(final Object o, final Class clazz) { * @return the attachment value of wrapper for given key on the wrapper chain, * or null if the attachment is absent * @throws NullPointerException if any arguments is null, - * or any wrapper {@link Wrapper#unwrap()} returns null, + * or any wrapper {@link Wrapper#unwrap_()} returns null, * or the adaptee of {@link WrapperAdapter} is null * @throws ClassCastException if the return value is not type {@code } * @throws IllegalStateException if the adaptee of {@link WrapperAdapter} is an instance of {@link Wrapper} * or CYCLIC wrapper chain - * @see Attachable#getAttachment(Object) + * @see Attachable#getAttachment_(Object) */ @Nullable @Contract(pure = true) @@ -134,7 +134,7 @@ public static V getAttachmentFromWrapperChain(final W wrapper, final K requireNonNull(key, "key is null"); return travelWrapperChain(wrapper, w -> { if (w instanceof Attachable) { - V value = ((Attachable) w).getAttachment(key); + V value = ((Attachable) w).getAttachment_(key); return Optional.ofNullable(value); } else { return Optional.empty(); @@ -146,12 +146,12 @@ public static V getAttachmentFromWrapperChain(final W wrapper, final K * Gets the wrapper chain, aka. the list of all instances on the wrapper chain. *

* The wrapper chain consists of wrapper itself, followed by the wrappers - * obtained by repeatedly calling {@link Wrapper#unwrap()}. + * obtained by repeatedly calling {@link Wrapper#unwrap_()}. * * @param wrapper wrapper instance * @param the type of instances that be wrapped * @throws NullPointerException if wrapped argument is null, - * or any wrapper {@link Wrapper#unwrap()} returns null, + * or any wrapper {@link Wrapper#unwrap_()} returns null, * or the adaptee of {@link WrapperAdapter} is null * @throws IllegalStateException if the adaptee of {@link WrapperAdapter} is an instance of {@link Wrapper} * or CYCLIC wrapper chain @@ -168,12 +168,12 @@ public static List getInstancesOfWrapperChain(final W wrapper) { * Gets the base of the wrapper chain, aka. the last instance of the wrapper chain. *

* The wrapper chain consists of wrapper itself, followed by the wrappers - * obtained by repeatedly calling {@link Wrapper#unwrap()}. + * obtained by repeatedly calling {@link Wrapper#unwrap_()}. * * @param wrapper wrapper instance * @param the type of instances that be wrapped * @throws NullPointerException if wrapped argument is null, - * or any wrapper {@link Wrapper#unwrap()} returns null, + * or any wrapper {@link Wrapper#unwrap_()} returns null, * or the adaptee of {@link WrapperAdapter} is null * @throws IllegalStateException if the adaptee of {@link WrapperAdapter} is an instance of {@link Wrapper} * or CYCLIC wrapper chain @@ -193,12 +193,12 @@ public static W getBaseOfWrapperChain(final W wrapper) { * This method is {@code null}-safe, return {@code null} iff input parameter is {@code null}; * If input parameter is not a {@link Wrapper} just return input. *

- * A convenience method for {@link Wrapper#unwrap()} + * A convenience method for {@link Wrapper#unwrap_()} * * @param obj wrapper instance * @param the type of instances that be wrapped - * @throws NullPointerException if {@link Wrapper#unwrap()} returns null - * @see Wrapper#unwrap() + * @throws NullPointerException if {@link Wrapper#unwrap_()} returns null + * @see Wrapper#unwrap_() * @see #isWrapper(Object) */ @Nullable @@ -226,18 +226,18 @@ public static boolean isWrapper(@Nullable Object obj) { * Verifies the compliance of wrapper chain with the specification contracts. *

* The wrapper chain consists of wrapper itself, followed by the wrappers - * obtained by repeatedly calling {@link Wrapper#unwrap()}. + * obtained by repeatedly calling {@link Wrapper#unwrap_()}. *

* more about the specification contracts see the doc of below methods: *

    - *
  • {@link Wrapper#unwrap()} - *
  • {@link WrapperAdapter#adaptee()} + *
  • {@link Wrapper#unwrap_()} + *
  • {@link WrapperAdapter#adaptee_()} *
* * @param wrapper wrapper instance * @param the type of instances that be wrapped * @throws NullPointerException if wrapped argument is null, - * or any wrapper {@link Wrapper#unwrap()} returns null, + * or any wrapper {@link Wrapper#unwrap_()} returns null, * or the adaptee of {@link WrapperAdapter} is null * @throws IllegalStateException if the adaptee of {@link WrapperAdapter} is an instance of {@link Wrapper} * or CYCLIC wrapper chain @@ -251,18 +251,18 @@ public static void verifyWrapperChainContracts(final W wrapper) { * and checks all instances on wrapper chain is an instance of the given {@code bizInterface}. *

* The wrapper chain consists of wrapper itself, followed by the wrappers - * obtained by repeatedly calling {@link Wrapper#unwrap()}. + * obtained by repeatedly calling {@link Wrapper#unwrap_()}. *

* more about the specification contracts see the doc of below methods: *

    - *
  • {@link Wrapper#unwrap()} - *
  • {@link WrapperAdapter#adaptee()} + *
  • {@link Wrapper#unwrap_()} + *
  • {@link WrapperAdapter#adaptee_()} *
* * @param wrapper wrapper instance * @param the type of instances that be wrapped * @throws NullPointerException if any arguments is null, - * or any wrapper {@link Wrapper#unwrap()} returns null, + * or any wrapper {@link Wrapper#unwrap_()} returns null, * or the adaptee of {@link WrapperAdapter} is null * @throws IllegalStateException if any instance on the wrapper chain is not an instance of {@code bizInterface}, * or the adaptee of {@link WrapperAdapter} is an instance of {@link Wrapper} @@ -284,7 +284,7 @@ public static void verifyWrapperChainContracts(final W wrapper, final Class< * Exceptions thrown by the {@code predicate} are relayed to the caller. *

* The wrapper chain consists of wrapper itself, followed by the wrappers - * obtained by repeatedly calling {@link Wrapper#unwrap()}. + * obtained by repeatedly calling {@link Wrapper#unwrap_()}. * * @param wrapper wrapper instance/wrapper chain * @param predicate inspect logic @@ -292,7 +292,7 @@ public static void verifyWrapperChainContracts(final W wrapper, final Class< * @return return {@code false} if no wrapper on the wrapper chain satisfy the given {@code predicate}, * otherwise return {@code true} * @throws NullPointerException if any arguments is null, - * or any wrapper {@link Wrapper#unwrap()} returns null, + * or any wrapper {@link Wrapper#unwrap_()} returns null, * or the adaptee of {@link WrapperAdapter} is null * @throws IllegalStateException if the adaptee of {@link WrapperAdapter} is an instance of {@link Wrapper} * or CYCLIC wrapper chain @@ -312,13 +312,13 @@ public static boolean testWrapperChain(final W wrapper, final Predicate * The wrapper chain consists of wrapper itself, followed by the wrappers - * obtained by repeatedly calling {@link Wrapper#unwrap()}. + * obtained by repeatedly calling {@link Wrapper#unwrap_()}. * * @param wrapper wrapper instance/wrapper chain * @param action The action to be performed for each instance * @param the type of instances that be wrapped * @throws NullPointerException if any arguments is null, - * or any wrapper {@link Wrapper#unwrap()} returns null, + * or any wrapper {@link Wrapper#unwrap_()} returns null, * or the adaptee of {@link WrapperAdapter} is null * @throws IllegalStateException if the adaptee of {@link WrapperAdapter} is an instance of {@link Wrapper} * or CYCLIC wrapper chain @@ -340,7 +340,7 @@ public static void forEachOnWrapperChain(final W wrapper, final Consumer * The wrapper chain consists of wrapper itself, followed by the wrappers - * obtained by repeatedly calling {@link Wrapper#unwrap()}. + * obtained by repeatedly calling {@link Wrapper#unwrap_()}. * * @param wrapper wrapper instance * @param process process function @@ -349,7 +349,7 @@ public static void forEachOnWrapperChain(final W wrapper, final Consumer Optional travelWrapperChain( */ @Contract(pure = true) private static Object adapteeNonWrapper(final Object wrapper) { - final Object adaptee = ((WrapperAdapter) wrapper).adaptee(); + final Object adaptee = ((WrapperAdapter) wrapper).adaptee_(); Supplier msg = () -> "adaptee of WrapperAdapter(" + wrapper.getClass().getName() + ") is null"; requireNonNull(adaptee, msg); @@ -410,7 +410,7 @@ private static Object adapteeNonWrapper(final Object wrapper) { */ @Contract(pure = true) private static Object unwrapNonNull(final Object wrapper) { - Object unwrap = ((Wrapper) wrapper).unwrap(); + Object unwrap = ((Wrapper) wrapper).unwrap_(); Supplier msg = () -> "unwrap of Wrapper(" + wrapper.getClass().getName() + ") is null"; return requireNonNull(unwrap, msg); } diff --git a/src/main/java/io/foldright/inspectablewrappers/Wrapper.java b/src/main/java/io/foldright/inspectablewrappers/Wrapper.java index 85d10d6..9945aa0 100644 --- a/src/main/java/io/foldright/inspectablewrappers/Wrapper.java +++ b/src/main/java/io/foldright/inspectablewrappers/Wrapper.java @@ -10,7 +10,7 @@ * Note about wrapper chain: *

    *
  • The wrapper chain consists of wrapper itself, followed by the wrappers - * obtained by repeatedly calling {@link Wrapper#unwrap()}
    + * obtained by repeatedly calling {@link Wrapper#unwrap_()}
    * Wrapper Chain *
  • The last instance of wrapper chain is NEVER an instance of {@link Wrapper} @@ -43,5 +43,5 @@ public interface Wrapper { *
*/ @NonNull - T unwrap(); + T unwrap_(); } diff --git a/src/main/java/io/foldright/inspectablewrappers/WrapperAdapter.java b/src/main/java/io/foldright/inspectablewrappers/WrapperAdapter.java index 77fe406..b983c35 100644 --- a/src/main/java/io/foldright/inspectablewrappers/WrapperAdapter.java +++ b/src/main/java/io/foldright/inspectablewrappers/WrapperAdapter.java @@ -44,5 +44,5 @@ public interface WrapperAdapter extends Wrapper { * @see Inspector */ @NonNull - T adaptee(); + T adaptee_(); } diff --git a/src/main/java/io/foldright/inspectablewrappers/utils/AttachableDelegate.java b/src/main/java/io/foldright/inspectablewrappers/utils/AttachableDelegate.java index b42dbc7..ebae687 100644 --- a/src/main/java/io/foldright/inspectablewrappers/utils/AttachableDelegate.java +++ b/src/main/java/io/foldright/inspectablewrappers/utils/AttachableDelegate.java @@ -35,7 +35,7 @@ public class AttachableDelegate implements Attachable { * @throws NullPointerException if any arguments is null */ @Override - public void setAttachment(@NonNull K key, @NonNull V value) { + public void setAttachment_(@NonNull K key, @NonNull V value) { requireNonNull(key, "key is null"); requireNonNull(value, "value is null"); attachments.put(key, value); @@ -52,7 +52,7 @@ public void setAttachment(@NonNull K key, @NonNull V value) { */ @Nullable @Override - public V getAttachment(@NonNull K key) { + public V getAttachment_(@NonNull K key) { requireNonNull(key, "key is null"); return attachments.get(key); } diff --git a/src/main/java/io/foldright/inspectablewrappers/utils/WrapperAdapterUtils.java b/src/main/java/io/foldright/inspectablewrappers/utils/WrapperAdapterUtils.java index 4fba719..f647481 100644 --- a/src/main/java/io/foldright/inspectablewrappers/utils/WrapperAdapterUtils.java +++ b/src/main/java/io/foldright/inspectablewrappers/utils/WrapperAdapterUtils.java @@ -27,12 +27,12 @@ public final class WrapperAdapterUtils { /** * Creates a {@link WrapperAdapter} instance of the given biz interface type by - * the underlying({@link Wrapper#unwrap()}) and adaptee({@link WrapperAdapter#adaptee()}) instances. + * the underlying({@link Wrapper#unwrap_()}) and adaptee({@link WrapperAdapter#adaptee_()}) instances. * * @param the type of instances that be wrapped * @param bizInterface the class of instances that be wrapped - * @param underlying the underlying instance that be wrapped, more info see {@link Wrapper#unwrap()} - * @param adaptee the adapted/existed wrapper instance, more info see {@link WrapperAdapter#adaptee()} + * @param underlying the underlying instance that be wrapped, more info see {@link Wrapper#unwrap_()} + * @param adaptee the adapted/existed wrapper instance, more info see {@link WrapperAdapter#adaptee_()} * @return the new {@link WrapperAdapter} instance * @throws IllegalArgumentException if {@code bizInterface} is not an interface, * or {@code bizInterface} is {@link Wrapper}/{@link WrapperAdapter}/{@link Attachable}, @@ -40,8 +40,8 @@ public final class WrapperAdapterUtils { * or adaptee is not an instance of {@code bizInterface}, * or adaptee is an instance of {@link Wrapper} * @throws NullPointerException if any argument is null - * @see Wrapper#unwrap() - * @see WrapperAdapter#adaptee() + * @see Wrapper#unwrap_() + * @see WrapperAdapter#adaptee_() */ @NonNull public static T createWrapperAdapter(Class bizInterface, T underlying, T adaptee) { @@ -54,12 +54,12 @@ public static T createWrapperAdapter(Class bizInterface, T underl /** * Creates a {@link WrapperAdapter} instance of the given biz interface type and {@link Attachable} type by - * the underlying({@link Wrapper#unwrap()}), adaptee({@link WrapperAdapter#adaptee()}) and attachable instances. + * the underlying({@link Wrapper#unwrap_()}), adaptee({@link WrapperAdapter#adaptee_()}) and attachable instances. * * @param the type of instances that be wrapped * @param bizInterface the class of instances that be wrapped - * @param underlying the underlying instance that be wrapped, more info see {@link Wrapper#unwrap()} - * @param adaptee the adapted/existed wrapper instance, more info see {@link WrapperAdapter#adaptee()} + * @param underlying the underlying instance that be wrapped, more info see {@link Wrapper#unwrap_()} + * @param adaptee the adapted/existed wrapper instance, more info see {@link WrapperAdapter#adaptee_()} * @param attachable the attachable instance, more info see {@link Attachable} * @return the new {@link WrapperAdapter} instance * @throws IllegalArgumentException if {@code bizInterface} is not an interface, @@ -68,10 +68,10 @@ public static T createWrapperAdapter(Class bizInterface, T underl * or adaptee is not an instance of {@code bizInterface}, * or adaptee is an instance of {@link Wrapper} * @throws NullPointerException if any argument is null - * @see Wrapper#unwrap() - * @see WrapperAdapter#adaptee() - * @see Attachable#getAttachment(Object) - * @see Attachable#setAttachment(Object, Object) + * @see Wrapper#unwrap_() + * @see WrapperAdapter#adaptee_() + * @see Attachable#getAttachment_(Object) + * @see Attachable#setAttachment_(Object, Object) */ @NonNull public static T createWrapperAdapter( @@ -129,10 +129,10 @@ private static T createWrapperAdapter0( if (ADAPTEE.sameSignatureAs(method)) return adaptee; if (attachable != null && GET_ATTACHMENT.sameSignatureAs(method)) { - return ((Attachable) attachable).getAttachment(args[0]); + return ((Attachable) attachable).getAttachment_(args[0]); } if (attachable != null && SET_ATTACHMENT.sameSignatureAs(method)) { - ((Attachable) attachable).setAttachment(args[0], args[1]); + ((Attachable) attachable).setAttachment_(args[0], args[1]); return null; } @@ -219,21 +219,21 @@ private WrapperAdapterUtils() { */ enum WrapperAdapterProxyRelatedMethod { /** - * {@link Wrapper#unwrap()} + * {@link Wrapper#unwrap_()} */ - UNWRAP(() -> Wrapper.class.getMethod("unwrap")), + UNWRAP(() -> Wrapper.class.getMethod("unwrap_")), /** - * {@link WrapperAdapter#adaptee()} + * {@link WrapperAdapter#adaptee_()} */ - ADAPTEE(() -> WrapperAdapter.class.getMethod("adaptee")), + ADAPTEE(() -> WrapperAdapter.class.getMethod("adaptee_")), /** - * {@link Attachable#getAttachment(Object)} + * {@link Attachable#getAttachment_(Object)} */ - GET_ATTACHMENT(() -> Attachable.class.getMethod("getAttachment", Object.class)), + GET_ATTACHMENT(() -> Attachable.class.getMethod("getAttachment_", Object.class)), /** - * {@link Attachable#setAttachment(Object, Object)} + * {@link Attachable#setAttachment_(Object, Object)} */ - SET_ATTACHMENT(() -> Attachable.class.getMethod("setAttachment", Object.class, Object.class)), + SET_ATTACHMENT(() -> Attachable.class.getMethod("setAttachment_", Object.class, Object.class)), /** * {@link Object#toString()} */ diff --git a/src/test/java/io/foldright/demo/ChattyExecutorWrapper.java b/src/test/java/io/foldright/demo/ChattyExecutorWrapper.java index f7cdf3e..d868089 100644 --- a/src/test/java/io/foldright/demo/ChattyExecutorWrapper.java +++ b/src/test/java/io/foldright/demo/ChattyExecutorWrapper.java @@ -19,7 +19,7 @@ public void execute(Runnable command) { } @Override - public Executor unwrap() { + public Executor unwrap_() { return executor; } } diff --git a/src/test/java/io/foldright/demo/Demo.java b/src/test/java/io/foldright/demo/Demo.java index 03aaab2..8bc4a0c 100644 --- a/src/test/java/io/foldright/demo/Demo.java +++ b/src/test/java/io/foldright/demo/Demo.java @@ -37,7 +37,7 @@ private static Executor buildExecutorChain() { final Executor base = Runnable::run; final LazyExecutorWrapper lazy = new LazyExecutorWrapper(base); - lazy.setAttachment("busy", "very, very busy!"); + lazy.setAttachment_("busy", "very, very busy!"); return new ChattyExecutorWrapper(lazy); } diff --git a/src/test/java/io/foldright/demo/LazyExecutorWrapper.java b/src/test/java/io/foldright/demo/LazyExecutorWrapper.java index 87c97b8..41e6a96 100644 --- a/src/test/java/io/foldright/demo/LazyExecutorWrapper.java +++ b/src/test/java/io/foldright/demo/LazyExecutorWrapper.java @@ -32,20 +32,20 @@ private static void sleep() { } @Override - public Executor unwrap() { + public Executor unwrap_() { return executor; } private final Attachable attachable = new AttachableDelegate<>(); @Override - public void setAttachment(String key, String value) { - attachable.setAttachment(key, value); + public void setAttachment_(String key, String value) { + attachable.setAttachment_(key, value); } @Nullable @Override - public String getAttachment(String key) { - return attachable.getAttachment(key); + public String getAttachment_(String key) { + return attachable.getAttachment_(key); } } diff --git a/src/test/java/io/foldright/demo/integration/IntegrationDemo.java b/src/test/java/io/foldright/demo/integration/IntegrationDemo.java index 06f7505..32ea223 100644 --- a/src/test/java/io/foldright/demo/integration/IntegrationDemo.java +++ b/src/test/java/io/foldright/demo/integration/IntegrationDemo.java @@ -44,7 +44,7 @@ private static Executor buildExecutorChain() { private static Executor createExistedExecutorWrapperAdapter(Executor base) { final Executor existed = new ExistedExecutorWrapper(base); final ExistedExecutorWrapperAdapter adapter = new ExistedExecutorWrapperAdapter(base, existed); - adapter.setAttachment("adapted-existed-executor-wrapper-msg", "I'm an adapter of an existed executor which have nothing to do with ~inspectable~wrappers~."); + adapter.setAttachment_("adapted-existed-executor-wrapper-msg", "I'm an adapter of an existed executor which have nothing to do with ~inspectable~wrappers~."); return adapter; } @@ -61,12 +61,12 @@ public ExistedExecutorWrapperAdapter(Executor base, Executor adaptee) { } @Override - public Executor unwrap() { + public Executor unwrap_() { return base; } @Override - public Executor adaptee() { + public Executor adaptee_() { return adaptee; } @@ -78,14 +78,14 @@ public void execute(Runnable command) { private final Attachable attachable = new AttachableDelegate<>(); @Override - public void setAttachment(String key, String value) { - attachable.setAttachment(key, value); + public void setAttachment_(String key, String value) { + attachable.setAttachment_(key, value); } @Nullable @Override - public String getAttachment(String key) { - return attachable.getAttachment(key); + public String getAttachment_(String key) { + return attachable.getAttachment_(key); } } } diff --git a/src/test/java/io/foldright/demo/integration/IntegrationDemoUsingWrapperAdapterUtils.java b/src/test/java/io/foldright/demo/integration/IntegrationDemoUsingWrapperAdapterUtils.java index 7c5e9b0..d339727 100644 --- a/src/test/java/io/foldright/demo/integration/IntegrationDemoUsingWrapperAdapterUtils.java +++ b/src/test/java/io/foldright/demo/integration/IntegrationDemoUsingWrapperAdapterUtils.java @@ -44,7 +44,7 @@ private static Executor createExistedExecutorWrapperAdapter(Executor base) { final Executor existed = new ExistedExecutorWrapper(base); Attachable attachable = new AttachableDelegate<>(); - attachable.setAttachment("adapted-existed-executor-wrapper-msg", "I'm an adapter of an existed executor which have nothing to do with ~inspectable~wrappers~."); + attachable.setAttachment_("adapted-existed-executor-wrapper-msg", "I'm an adapter of an existed executor which have nothing to do with ~inspectable~wrappers~."); return WrapperAdapterUtils.createWrapperAdapter(Executor.class, base, existed, attachable); } diff --git a/src/test/java/io/foldright/inspectablewrappers/SpecificationContractsTest.java b/src/test/java/io/foldright/inspectablewrappers/SpecificationContractsTest.java index afd72bc..148cfb9 100644 --- a/src/test/java/io/foldright/inspectablewrappers/SpecificationContractsTest.java +++ b/src/test/java/io/foldright/inspectablewrappers/SpecificationContractsTest.java @@ -83,7 +83,7 @@ private static class WrapperImpl implements Wrapper, Executor { } @Override - public Executor unwrap() { + public Executor unwrap_() { return instance; } @@ -102,12 +102,12 @@ private static class WrapperAdapterImpl implements WrapperAdapter, Exe } @Override - public Executor unwrap() { + public Executor unwrap_() { return wrapper; } @Override - public Executor adaptee() { + public Executor adaptee_() { return adaptee; } @@ -120,7 +120,7 @@ private static class MutableWrapperImpl implements Wrapper, Executor { Executor instance; @Override - public Executor unwrap() { + public Executor unwrap_() { return instance; } diff --git a/src/test/java/io/foldright/inspectablewrappers/WrapperAdapterTest.kt b/src/test/java/io/foldright/inspectablewrappers/WrapperAdapterTest.kt index 6d79b31..6bc1185 100644 --- a/src/test/java/io/foldright/inspectablewrappers/WrapperAdapterTest.kt +++ b/src/test/java/io/foldright/inspectablewrappers/WrapperAdapterTest.kt @@ -78,14 +78,14 @@ class WrapperAdapterTest : FunSpec({ */ private class ExistedExecutorWrapperAdapter(private val unwrap: Executor, private val adaptee: Executor) : Executor by adaptee, WrapperAdapter, Attachable by AttachableDelegate() { - override fun unwrap(): Executor = unwrap - override fun adaptee(): Executor = adaptee + override fun unwrap_(): Executor = unwrap + override fun adaptee_(): Executor = adaptee companion object { fun createExistedExecutorWrapperAdapter(base: Executor): ExistedExecutorWrapperAdapter { val existed = ExistedExecutorWrapper(base) return ExistedExecutorWrapperAdapter(base, existed).apply { - setAttachment(ADAPTED_MSG_KEY, ADAPTED_MSG_VALUE) + setAttachment_(ADAPTED_MSG_KEY, ADAPTED_MSG_VALUE) } } } @@ -106,6 +106,6 @@ class ExistedExecutorWrapper(private val executor: Executor) : Executor { */ private class ChattyExecutorWrapperAdapter(private val adaptee: ChattyExecutorWrapper) : Executor by adaptee, WrapperAdapter, Attachable by AttachableDelegate() { - override fun unwrap(): Executor = adaptee.unwrap() - override fun adaptee(): Executor = adaptee + override fun unwrap_(): Executor = adaptee.unwrap_() + override fun adaptee_(): Executor = adaptee } diff --git a/src/test/java/io/foldright/inspectablewrappers/WrapperTest.kt b/src/test/java/io/foldright/inspectablewrappers/WrapperTest.kt index e3a1670..4fccfad 100644 --- a/src/test/java/io/foldright/inspectablewrappers/WrapperTest.kt +++ b/src/test/java/io/foldright/inspectablewrappers/WrapperTest.kt @@ -19,7 +19,7 @@ class WrapperTest : FunSpec({ // prepare executor instances/wrappers, build the executor/wrapper chain val baseExecutor = BaseExecutor() val lazyExecutorWrapper = LazyExecutorWrapper(baseExecutor) - .apply { setAttachment("busy", "very, very busy!") } + .apply { setAttachment_("busy", "very, very busy!") } val executorChain: Executor = ChattyExecutorWrapper(lazyExecutorWrapper) test("wrapper chain") { @@ -78,7 +78,7 @@ class WrapperTest : FunSpec({ } test("inspect last instance - getAttachmentFromWrapperChain") { - val attachable = AttachableDelegate().apply { setAttachment("k1", "v1") } + val attachable = AttachableDelegate().apply { setAttachment_("k1", "v1") } getAttachmentFromWrapperChain(attachable, "k1") shouldBe "v1" val base = object : Executor, Attachable by AttachableDelegate() { @@ -86,7 +86,7 @@ class WrapperTest : FunSpec({ command.run() } } - base.setAttachment("k1", "v1") + base.setAttachment_("k1", "v1") getAttachmentFromWrapperChain(base, "k1") shouldBe "v1" val c2 = ChattyExecutorWrapper(base) @@ -106,7 +106,7 @@ class ChattyExecutorWrapper(private val executor: Executor) : Executor, Wrapper< executor.execute(command) } - override fun unwrap(): Executor = executor + override fun unwrap_(): Executor = executor } class LazyExecutorWrapper(private val executor: Executor) : @@ -117,7 +117,7 @@ class LazyExecutorWrapper(private val executor: Executor) : executor.execute(command) } - override fun unwrap(): Executor = executor + override fun unwrap_(): Executor = executor private fun sleep() { Thread.sleep(100) diff --git a/src/test/java/io/foldright/inspectablewrappers/utils/WrapperAdapterUtilsTest.kt b/src/test/java/io/foldright/inspectablewrappers/utils/WrapperAdapterUtilsTest.kt index 81bb80c..c7f9f92 100644 --- a/src/test/java/io/foldright/inspectablewrappers/utils/WrapperAdapterUtilsTest.kt +++ b/src/test/java/io/foldright/inspectablewrappers/utils/WrapperAdapterUtilsTest.kt @@ -31,8 +31,8 @@ class WrapperAdapterUtilsTest : FunSpec({ adapter.toString() shouldStartWith "[WrapperAdapter proxy created by WrapperAdapterUtils] " val attachable = adapter as Attachable - attachable.setAttachment(ADAPTED_MSG_KEY, ADAPTED_MSG_VALUE) - attachable.getAttachment(ADAPTED_MSG_KEY) shouldBe ADAPTED_MSG_VALUE + attachable.setAttachment_(ADAPTED_MSG_KEY, ADAPTED_MSG_VALUE) + attachable.getAttachment_(ADAPTED_MSG_KEY) shouldBe ADAPTED_MSG_VALUE adapter } @@ -163,8 +163,8 @@ class WrapperAdapterUtilsTest : FunSpec({ }) class WrongWrapperAdapter(private val executor: Executor) : WrapperAdapter, Executor by executor { - override fun unwrap(): Executor = executor - override fun adaptee(): Executor = executor + override fun unwrap_(): Executor = executor + override fun adaptee_(): Executor = executor } interface Tag1