) supplier;
+ } else {
+ return new Lazy<>(supplier);
+ }
+ }
+
+ /**
+ * Evaluates this lazy value and caches it, when called the first time.
+ * On subsequent calls, returns the cached value.
+ *
+ * @return the lazy evaluated value
+ */
+ @Override
+ public T get() {
+ return (supplier == null) ? value : computeValue();
+ }
+
+ private synchronized T computeValue() {
+ final Supplier extends T> s = supplier;
+ if (s != null) {
+ value = s.get();
+ supplier = null;
+ }
+ return value;
+ }
+
+ /**
+ * Checks, if this lazy value is evaluated.
+ *
+ * Note: A value is internally evaluated (once) by calling {@link #get()}.
+ *
+ * @return true, if the value is evaluated, false otherwise.
+ * @throws UnsupportedOperationException if this value is undefined
+ */
+ private boolean isEvaluated() {
+ return supplier == null;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ return (obj == this) || (obj instanceof Lazy && Objects.equals(((Lazy>) obj).get(), get()));
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hashCode(get());
+ }
+
+ @Override
+ public String toString() {
+ return "Lazy(" + (!isEvaluated() ? "?" : value) + ")";
+ }
+
+ /**
+ * Ensures that the value is evaluated before serialization.
+ *
+ * @param stream An object serialization stream.
+ * @throws java.io.IOException If an error occurs writing to the stream.
+ */
+ private void writeObject(ObjectOutputStream stream) throws IOException {
+ // evaluates the lazy value if it isn't evaluated yet!
+ get();
+ stream.defaultWriteObject();
+ }
+}
diff --git a/src/main/java/pl/wavesoftware/utils/stringify/impl/lang/SafeInspector.java b/src/main/java/pl/wavesoftware/utils/stringify/impl/lang/SafeInspector.java
new file mode 100644
index 0000000..b1ec6ad
--- /dev/null
+++ b/src/main/java/pl/wavesoftware/utils/stringify/impl/lang/SafeInspector.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2018-2019 Wave Software
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package pl.wavesoftware.utils.stringify.impl.lang;
+
+/**
+ * @author Krzysztof Suszynski
+ * @since 0.1.0
+ */
+public interface SafeInspector {
+ String inspect(Object object);
+}
diff --git a/src/main/java/pl/wavesoftware/utils/stringify/impl/lang/package-info.java b/src/main/java/pl/wavesoftware/utils/stringify/impl/lang/package-info.java
new file mode 100644
index 0000000..fac934e
--- /dev/null
+++ b/src/main/java/pl/wavesoftware/utils/stringify/impl/lang/package-info.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2018-2019 Wave Software
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @author Krzysztof Suszynski
+ * @since 2018-04-18
+ */
+@ReturnTypesAreNonnullByDefault
+@ParametersAreNonnullByDefault
+package pl.wavesoftware.utils.stringify.impl.lang;
+
+import pl.wavesoftware.eid.api.ReturnTypesAreNonnullByDefault;
+
+import javax.annotation.ParametersAreNonnullByDefault;
diff --git a/src/main/java/pl/wavesoftware/utils/stringify/impl/reflect/ClassInfo.java b/src/main/java/pl/wavesoftware/utils/stringify/impl/reflect/ClassInfo.java
new file mode 100644
index 0000000..7411bda
--- /dev/null
+++ b/src/main/java/pl/wavesoftware/utils/stringify/impl/reflect/ClassInfo.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2018-2019 Wave Software
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package pl.wavesoftware.utils.stringify.impl.reflect;
+
+import pl.wavesoftware.eid.exceptions.EidIllegalStateException;
+
+import java.util.Optional;
+
+/**
+ * Represents a information about a given class
+ *
+ * @author Krzysztof Suszynski
+ * @since 2.0.0
+ * @param a type of a class
+ */
+public interface ClassInfo {
+ /**
+ * Provides a optional class reference. Reference is {@link Optional#empty()} if target
+ * class isn't found.
+ *
+ * @return an optional class reference
+ */
+ Optional> maybeClass();
+
+ default Class get() {
+ return maybeClass()
+ .orElseThrow(() -> new EidIllegalStateException("20190712:012032"));
+ }
+
+ default boolean isAvailable() {
+ return maybeClass().isPresent();
+ }
+}
diff --git a/src/main/java/pl/wavesoftware/utils/stringify/impl/ClassLocator.java b/src/main/java/pl/wavesoftware/utils/stringify/impl/reflect/ClassInfoImpl.java
similarity index 52%
rename from src/main/java/pl/wavesoftware/utils/stringify/impl/ClassLocator.java
rename to src/main/java/pl/wavesoftware/utils/stringify/impl/reflect/ClassInfoImpl.java
index fc5c669..ea0a4ae 100644
--- a/src/main/java/pl/wavesoftware/utils/stringify/impl/ClassLocator.java
+++ b/src/main/java/pl/wavesoftware/utils/stringify/impl/reflect/ClassInfoImpl.java
@@ -14,48 +14,30 @@
* limitations under the License.
*/
-package pl.wavesoftware.utils.stringify.impl;
+package pl.wavesoftware.utils.stringify.impl.reflect;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import javax.annotation.Nullable;
-
-import static pl.wavesoftware.eid.utils.EidPreconditions.checkNotNull;
+import java.util.Optional;
/**
* @author Krzysztof Suszynski
- * @since 2018-04-18
+ * @since 2.0.0
*/
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
-final class ClassLocator {
-
- private final String fqcn;
- private Class> targetClass;
- private boolean located;
+final class ClassInfoImpl implements ClassInfo {
- boolean isAvailable() {
- return getTargetClass() != null;
- }
+ @Nullable
+ private final Class cls;
- Class> get() {
- return checkNotNull(getTargetClass(), "20180418:230411");
+ static ClassInfo empty() {
+ return new ClassInfoImpl<>(null);
}
- @SuppressWarnings({"squid:S1166", "squid:S2658"})
- @Nullable
- private Class> getTargetClass() {
- if (!located) {
- ClassLoader cl = Thread
- .currentThread()
- .getContextClassLoader();
- try {
- targetClass = Class.forName(fqcn, false, cl);
- } catch (ClassNotFoundException e) {
- // do nothing
- }
- located = true;
- }
- return targetClass;
+ @Override
+ public Optional> maybeClass() {
+ return Optional.ofNullable(cls);
}
}
diff --git a/src/main/java/pl/wavesoftware/utils/stringify/impl/reflect/ClassLoaderUtils.java b/src/main/java/pl/wavesoftware/utils/stringify/impl/reflect/ClassLoaderUtils.java
new file mode 100644
index 0000000..df2affd
--- /dev/null
+++ b/src/main/java/pl/wavesoftware/utils/stringify/impl/reflect/ClassLoaderUtils.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2018-2019 Wave Software
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package pl.wavesoftware.utils.stringify.impl.reflect;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @author Krzysztof Suszynski
+ * @since 2.0.0
+ */
+final class ClassLoaderUtils {
+
+ private ClassLoaderUtils() {
+ // not reachable
+ }
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(ClassLoaderUtils.class);
+ static ClassLoader getDefaultClassLoader() {
+ try {
+ ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
+ if (contextClassLoader != null) {
+ return contextClassLoader;
+ }
+ } catch (RuntimeException ex) {
+ LOGGER.trace("Silenced", ex);
+ }
+ return ClassLoader.getSystemClassLoader();
+ }
+}
diff --git a/src/main/java/pl/wavesoftware/utils/stringify/impl/reflect/ClassLocator.java b/src/main/java/pl/wavesoftware/utils/stringify/impl/reflect/ClassLocator.java
new file mode 100644
index 0000000..72aea3d
--- /dev/null
+++ b/src/main/java/pl/wavesoftware/utils/stringify/impl/reflect/ClassLocator.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2018-2019 Wave Software
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package pl.wavesoftware.utils.stringify.impl.reflect;
+
+/**
+ * Locates class by their fully qualified class name.
+ *
+ * @author Krzysztof Suszynski
+ * @since 2.0.0
+ */
+public interface ClassLocator {
+ /**
+ * Locates a class by their fully qualified class name.
+ *
+ * @param fqcn a fully qualified class name
+ * @param a type of a class
+ * @return an info about a class
+ */
+ ClassInfo locate(String fqcn);
+}
diff --git a/src/main/java/pl/wavesoftware/utils/stringify/impl/reflect/ClassLocatorImpl.java b/src/main/java/pl/wavesoftware/utils/stringify/impl/reflect/ClassLocatorImpl.java
new file mode 100644
index 0000000..7b5d2b4
--- /dev/null
+++ b/src/main/java/pl/wavesoftware/utils/stringify/impl/reflect/ClassLocatorImpl.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2018-2019 Wave Software
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package pl.wavesoftware.utils.stringify.impl.reflect;
+
+import lombok.AccessLevel;
+import lombok.RequiredArgsConstructor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @author Krzysztof Suszynski
+ * @since 2.0.0
+ */
+@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
+final class ClassLocatorImpl implements ClassLocator {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(ClassLocatorImpl.class);
+
+ private final ClassLoader classLoader;
+
+ @Override
+ @SuppressWarnings({"squid:S1166", "squid:S2658", "unchecked"})
+ public ClassInfo locate(String fqcn) {
+ try {
+ Class targetClass = (Class) Class.forName(fqcn, false, classLoader);
+ return new ClassInfoImpl<>(targetClass);
+ } catch (ClassNotFoundException ex) {
+ LOGGER.trace("Silenced exception", ex);
+ return ClassInfoImpl.empty();
+ }
+ }
+}
diff --git a/src/main/java/pl/wavesoftware/utils/stringify/impl/reflect/MethodInfo.java b/src/main/java/pl/wavesoftware/utils/stringify/impl/reflect/MethodInfo.java
new file mode 100644
index 0000000..40985d3
--- /dev/null
+++ b/src/main/java/pl/wavesoftware/utils/stringify/impl/reflect/MethodInfo.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2018-2019 Wave Software
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package pl.wavesoftware.utils.stringify.impl.reflect;
+
+import javax.annotation.Nullable;
+
+/**
+ * Represents a method that can be invoked
+ *
+ * @author Krzysztof Suszynski
+ * @since 2.0.0
+ * @param a type of method returns
+ */
+public interface MethodInfo {
+ /**
+ * Invokes a method with parameters given.
+ *
+ * @param target a target object, if {@code null} method will be called statically.
+ * @param parameters a parameters for a method
+ * @return a method return value
+ */
+ T invoke(@Nullable Object target, Object... parameters);
+}
diff --git a/src/main/java/pl/wavesoftware/utils/stringify/impl/reflect/MethodInfoImpl.java b/src/main/java/pl/wavesoftware/utils/stringify/impl/reflect/MethodInfoImpl.java
new file mode 100644
index 0000000..71543e1
--- /dev/null
+++ b/src/main/java/pl/wavesoftware/utils/stringify/impl/reflect/MethodInfoImpl.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2018-2019 Wave Software
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package pl.wavesoftware.utils.stringify.impl.reflect;
+
+import lombok.AccessLevel;
+import lombok.RequiredArgsConstructor;
+import pl.wavesoftware.eid.utils.UnsafeSupplier;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.function.Supplier;
+
+import static pl.wavesoftware.eid.utils.EidExecutions.tryToExecute;
+
+/**
+ * @author Krzysztof Suszynski
+ * @since 2.0.0
+ */
+@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
+final class MethodInfoImpl implements MethodInfo {
+
+ private final Supplier methodSupplier;
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public T invoke(@Nullable Object target, Object... parameters) {
+ return tryToExecute(new UnsafeSupplier() {
+ @Override
+ @Nonnull
+ public T get() throws InvocationTargetException, IllegalAccessException {
+ return (T) methodSupplier.get().invoke(target, parameters);
+ }
+ },
+ "20180418:231314"
+ );
+ }
+}
diff --git a/src/main/java/pl/wavesoftware/utils/stringify/impl/reflect/MethodLocator.java b/src/main/java/pl/wavesoftware/utils/stringify/impl/reflect/MethodLocator.java
new file mode 100644
index 0000000..285a9da
--- /dev/null
+++ b/src/main/java/pl/wavesoftware/utils/stringify/impl/reflect/MethodLocator.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2018-2019 Wave Software
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package pl.wavesoftware.utils.stringify.impl.reflect;
+
+/**
+ * Locates a method withing a given class info
+ *
+ * @author Krzysztof Suszynski
+ * @since 2.0.0
+ */
+public interface MethodLocator {
+ /**
+ * Return a method info if described method exists, throws runtime exception otherwise.
+ *
+ * @param classInfo a class info
+ * @param methodName a method name
+ * @param parametersTypes parameter types for a method
+ * @param method return type
+ * @param class info type
+ * @return a method info
+ */
+ MethodInfo locate(ClassInfo classInfo, String methodName, Class>... parametersTypes);
+}
diff --git a/src/main/java/pl/wavesoftware/utils/stringify/impl/reflect/MethodLocatorImpl.java b/src/main/java/pl/wavesoftware/utils/stringify/impl/reflect/MethodLocatorImpl.java
new file mode 100644
index 0000000..1fee634
--- /dev/null
+++ b/src/main/java/pl/wavesoftware/utils/stringify/impl/reflect/MethodLocatorImpl.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2018-2019 Wave Software
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package pl.wavesoftware.utils.stringify.impl.reflect;
+
+import pl.wavesoftware.eid.utils.UnsafeSupplier;
+
+import javax.annotation.Nonnull;
+import java.lang.reflect.Method;
+
+import static pl.wavesoftware.eid.utils.EidExecutions.tryToExecute;
+
+/**
+ * @author Krzysztof Suszynski
+ * @since 2.0.0
+ */
+final class MethodLocatorImpl implements MethodLocator {
+ @Override
+ public MethodInfo locate(
+ ClassInfo classInfo,
+ String methodName,
+ Class>... parametersTypes
+ ) {
+ return new MethodInfoImpl<>(() ->
+ tryToExecute(new UnsafeSupplier() {
+ @Override
+ @Nonnull
+ public Method get() throws NoSuchMethodException {
+ return classInfo.get().getDeclaredMethod(methodName, parametersTypes);
+ }
+ }, "20180418:231029")
+ );
+ }
+}
diff --git a/src/main/java/pl/wavesoftware/utils/stringify/impl/reflect/ReflectModule.java b/src/main/java/pl/wavesoftware/utils/stringify/impl/reflect/ReflectModule.java
new file mode 100644
index 0000000..5a3486a
--- /dev/null
+++ b/src/main/java/pl/wavesoftware/utils/stringify/impl/reflect/ReflectModule.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2018-2019 Wave Software
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package pl.wavesoftware.utils.stringify.impl.reflect;
+
+import static pl.wavesoftware.utils.stringify.impl.reflect.ClassLoaderUtils.getDefaultClassLoader;
+
+/**
+ * Reflect module entry point
+ *
+ * @author Krzysztof Suszynski
+ * @since 2.0.0
+ */
+public enum ReflectModule {
+ INSTANCE;
+
+ /**
+ * Return a class locator
+ *
+ * @return a class locator
+ */
+ public ClassLocator classLocator() {
+ return new ClassLocatorImpl(getDefaultClassLoader());
+ }
+
+ /**
+ * Return a method locator
+ *
+ * @return a method locator
+ */
+ public MethodLocator methodLocator() {
+ return new MethodLocatorImpl();
+ }
+}
diff --git a/src/main/java/pl/wavesoftware/utils/stringify/impl/reflect/package-info.java b/src/main/java/pl/wavesoftware/utils/stringify/impl/reflect/package-info.java
new file mode 100644
index 0000000..5f1ac35
--- /dev/null
+++ b/src/main/java/pl/wavesoftware/utils/stringify/impl/reflect/package-info.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2018-2019 Wave Software
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @author Krzysztof Suszynski
+ * @since 2018-04-18
+ */
+@ReturnTypesAreNonnullByDefault
+@ParametersAreNonnullByDefault
+package pl.wavesoftware.utils.stringify.impl.reflect;
+
+import pl.wavesoftware.eid.api.ReturnTypesAreNonnullByDefault;
+
+import javax.annotation.ParametersAreNonnullByDefault;
diff --git a/src/main/java/pl/wavesoftware/utils/stringify/spi/Configurator.java b/src/main/java/pl/wavesoftware/utils/stringify/spi/Configurator.java
old mode 100755
new mode 100644
diff --git a/src/main/java/pl/wavesoftware/utils/stringify/spi/JpaLazyChecker.java b/src/main/java/pl/wavesoftware/utils/stringify/spi/JpaLazyChecker.java
new file mode 100644
index 0000000..697fe7c
--- /dev/null
+++ b/src/main/java/pl/wavesoftware/utils/stringify/spi/JpaLazyChecker.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2018-2019 Wave Software
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package pl.wavesoftware.utils.stringify.spi;
+
+/**
+ * Checks a field, if it isn't loaded from persistence. If checker returns {@code true},
+ * Stringify shouldn't inspect that field, but will display a lazy indicating
+ * representation, for ex.: {@code "⁂Lazy"}.
+ *
+ * @author Krzysztof Suszynski
+ * @since 1.0.0
+ */
+public interface JpaLazyChecker {
+ /**
+ * Checks if given object is lazy
+ *
+ * @param candidate a candidate to be checked
+ * @return true, if object is lazy
+ */
+ boolean isLazy(Object candidate);
+
+ /**
+ * Returns {@code true}, if this checker is suitable to check given candidate.
+ *
+ * @param candidate a candidate object to be checked.
+ * @return true, if this checker can be used to determine if candidate is lazy.
+ */
+ default boolean isSuitable(Object candidate) {
+ return true;
+ }
+}
diff --git a/src/test/java/pl/wavesoftware/utils/stringify/Acme.java b/src/test/java/pl/wavesoftware/utils/stringify/Acme.java
old mode 100755
new mode 100644
diff --git a/src/test/java/pl/wavesoftware/utils/stringify/StringifyIT.java b/src/test/java/pl/wavesoftware/utils/stringify/StringifyIT.java
old mode 100755
new mode 100644
diff --git a/src/test/java/pl/wavesoftware/utils/stringify/StringifyTest.java b/src/test/java/pl/wavesoftware/utils/stringify/StringifyTest.java
old mode 100755
new mode 100644
index cccee51..431ac9a
--- a/src/test/java/pl/wavesoftware/utils/stringify/StringifyTest.java
+++ b/src/test/java/pl/wavesoftware/utils/stringify/StringifyTest.java
@@ -189,10 +189,10 @@ void onPersonWithCustomPerdicateLogic() {
stringifier.beanFactory(productionBeanFactory);
// when
- String productionResult = stringifier.toString();
+ CharSequence productionResult = stringifier.stringify();
// then
- assertThat(productionResult).isEqualTo(
+ assertThat(productionResult).isEqualToIgnoringWhitespace(
", childs=[], " +
"account=⁂Lazy>"
@@ -237,10 +237,10 @@ private static boolean inspectionPointValue(final InspectionPoint inspectionPoin
);
}
- private StaticBeanFactory getBeanFactory(IsInDevelopment isInDevelopmentFalse) {
+ private StaticBeanFactory getBeanFactory(IsInDevelopment isInDevelopment) {
return new StaticBeanFactory(
new AbstractMap.SimpleImmutableEntry<>(
- IsInDevelopment.class, isInDevelopmentFalse
+ IsInDevelopment.class, isInDevelopment
)
);
}
diff --git a/src/test/java/pl/wavesoftware/utils/stringify/TestBeanFactory.java b/src/test/java/pl/wavesoftware/utils/stringify/TestBeanFactory.java
old mode 100755
new mode 100644
diff --git a/src/test/java/pl/wavesoftware/utils/stringify/TestRepository.java b/src/test/java/pl/wavesoftware/utils/stringify/TestRepository.java
index d067ff6..8d37adb 100644
--- a/src/test/java/pl/wavesoftware/utils/stringify/TestRepository.java
+++ b/src/test/java/pl/wavesoftware/utils/stringify/TestRepository.java
@@ -69,7 +69,7 @@ Person createPerson() {
parent.setIgnored("Ignore it!");
child.setId(15);
child.setParent(parent);
- child.setChilds(new ArrayList());
+ child.setChilds(new ArrayList<>());
child.setAccount(a1);
child.setPassword("rewq1234$#@!");
child.setIgnored("Dump this");
diff --git a/src/test/java/pl/wavesoftware/utils/stringify/TestingConfigurator.java b/src/test/java/pl/wavesoftware/utils/stringify/TestingConfigurator.java
old mode 100755
new mode 100644
diff --git a/src/test/java/pl/wavesoftware/utils/stringify/UnlessContainsSecret.java b/src/test/java/pl/wavesoftware/utils/stringify/UnlessContainsSecret.java
old mode 100755
new mode 100644
diff --git a/src/test/resources/META-INF/services/pl.wavesoftware.utils.stringify.spi.Configurator b/src/test/resources/META-INF/services/pl.wavesoftware.utils.stringify.spi.Configurator
old mode 100755
new mode 100644