Skip to content

Commit 2c9c7ce

Browse files
committed
Changing to default interface implementations for Theme
Additionally adding test that assert if one can replace a theme with theirs.
1 parent cd87943 commit 2c9c7ce

34 files changed

+229
-471
lines changed

src/main/java/pl/wavesoftware/utils/stringify/impl/DefaultConfiguration.java

100644100755
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import pl.wavesoftware.utils.stringify.api.Configuration;
2020
import pl.wavesoftware.utils.stringify.api.Mode;
2121
import pl.wavesoftware.utils.stringify.impl.beans.BeansModule;
22-
import pl.wavesoftware.utils.stringify.impl.theme.ThemeModule;
2322
import pl.wavesoftware.utils.stringify.spi.BeanFactory;
2423
import pl.wavesoftware.utils.stringify.spi.theme.Theme;
2524

@@ -33,7 +32,7 @@ final class DefaultConfiguration implements Configuration {
3332

3433
private Mode mode = Mode.DEFAULT_MODE;
3534
private BeanFactory beanFactory = DEFAULT_BEAN_FACTORY;
36-
private Theme theme = ThemeModule.INSTANCE.defaultTheme();
35+
private Theme theme = new Theme() {};
3736

3837
@Override
3938
public Configuration mode(Mode mode) {
@@ -57,6 +56,7 @@ DefaultConfiguration dup() {
5756
DefaultConfiguration dup = new DefaultConfiguration();
5857
dup.beanFactory = beanFactory;
5958
dup.mode = mode;
59+
dup.theme = theme;
6060
return dup;
6161
}
6262

src/main/java/pl/wavesoftware/utils/stringify/impl/DefaultInspectionContext.java

100644100755
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import java.util.IdentityHashMap;
2424
import java.util.Map;
25+
import java.util.function.Supplier;
2526

2627
/**
2728
* @author <a href="mailto:krzysztof.suszynski@wavesoftware.pl">Krzysztof Suszynski</a>
@@ -31,11 +32,11 @@ final class DefaultInspectionContext implements InspectionContext {
3132
private static final Object CONTAIN = new Object();
3233

3334
private final Map<Object, Object> resolved = new IdentityHashMap<>();
34-
private final Theme theme;
35+
private final Supplier<Theme> theme;
3536

3637
private RootInpector rootInpector;
3738

38-
DefaultInspectionContext(Theme theme) {
39+
DefaultInspectionContext(Supplier<Theme> theme) {
3940
this.theme = theme;
4041
}
4142

@@ -56,7 +57,7 @@ public RootInpector rootInspector() {
5657

5758
@Override
5859
public Theme theme() {
59-
return theme;
60+
return theme.get();
6061
}
6162

6263
public void rootInpector(RootInpector rootInpector) {

src/main/java/pl/wavesoftware/utils/stringify/impl/DefaultStringify.java

100644100755
File mode changed.

src/main/java/pl/wavesoftware/utils/stringify/impl/InspectorBasedToStringResolver.java

100644100755
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public CharSequence resolve() {
6363
ComplexObjectStyle style = inspectionContext.theme().complexObject();
6464
StringBuilder sb = new StringBuilder();
6565
sb.append(style.begin());
66-
sb.append(style.name(target::getClass, target::hashCode));
66+
sb.append(style.name(target));
6767
CharSequence props = propertiesForToString();
6868
if (props.length() != 0) {
6969
sb.append(style.nameSeparator());
@@ -78,16 +78,17 @@ private CharSequence propertiesForToString() {
7878
props = inspectTargetAsClass(target.getClass());
7979
ComplexObjectStyle style = inspectionContext.theme().complexObject();
8080
StringBuilder sb = new StringBuilder();
81+
CharSequence propertySeparator = style.propertySeparator();
8182
for (Map.Entry<String, CharSequence> entry : props.entrySet()) {
8283
String fieldName = entry.getKey();
8384
CharSequence fieldStringValue = entry.getValue();
8485
sb.append(fieldName);
8586
sb.append(style.propertyEquals());
8687
sb.append(fieldStringValue);
87-
sb.append(style.propertySeparator());
88+
sb.append(propertySeparator);
8889
}
8990
if (!props.isEmpty()) {
90-
for (int i = 0; i < style.propertySeparator().length(); i++) {
91+
for (int i = 0; i < propertySeparator.length(); i++) {
9192
sb.deleteCharAt(sb.length() - 1);
9293
}
9394
}

src/main/java/pl/wavesoftware/utils/stringify/impl/ToStringResolverImpl.java

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ final class ToStringResolverImpl implements ToStringResolver, Configuration {
4343
this(
4444
target,
4545
configuration,
46-
new DefaultInspectionContext(configuration.getTheme()),
46+
new DefaultInspectionContext(configuration::getTheme),
4747
BeansModule.INSTANCE.cachedBeanFactory(
4848
configuration::getBeanFactory, target
4949
),

src/main/java/pl/wavesoftware/utils/stringify/impl/inspector/InspectionContext.java

100644100755
File mode changed.

src/main/java/pl/wavesoftware/utils/stringify/impl/inspector/InspectorModule.java

100644100755
File mode changed.

src/main/java/pl/wavesoftware/utils/stringify/impl/inspector/JpaLazyInspector.java

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ public boolean consentTo(Object candidate, InspectionContext context) {
3434
public CharSequence inspect(Object object, InspectionContext context) {
3535
return context.theme()
3636
.jpaLazy()
37-
.representation(object::hashCode);
37+
.representation(object);
3838
}
3939
}

src/main/java/pl/wavesoftware/utils/stringify/impl/inspector/ObjectInspectors.java

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/main/java/pl/wavesoftware/utils/stringify/impl/inspector/RecursionInspector.java

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ public boolean consentTo(Object candidate, InspectionContext context) {
3030
public CharSequence inspect(Object object, InspectionContext context) {
3131
return context.theme()
3232
.recursion()
33-
.representation(object::getClass, object::hashCode);
33+
.representation(object);
3434
}
3535
}

0 commit comments

Comments
 (0)