Skip to content

Commit 778d011

Browse files
committed
Split main impl package to more specialized ones
1 parent 2496b73 commit 778d011

File tree

65 files changed

+1222
-226
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1222
-226
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ matrix:
1010
env: JACOCO=true
1111
- jdk: openjdk8
1212
env: JACOCO=true SONAR=publish
13-
script: ./mvnw -V clean verify sonar:sonar --fail-at-end -U
1413
notifications:
1514
email:
1615
on_failure: change

pom.xml

100755100644
File mode changed.

src/main/java/pl/wavesoftware/utils/stringify/Stringify.java

100755100644
File mode changed.

src/main/java/pl/wavesoftware/utils/stringify/api/Configuration.java

100755100644
File mode changed.

src/main/java/pl/wavesoftware/utils/stringify/api/Inspect.java

100755100644
File mode changed.

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,16 @@
1818

1919
import pl.wavesoftware.utils.stringify.api.Configuration;
2020
import pl.wavesoftware.utils.stringify.api.Mode;
21+
import pl.wavesoftware.utils.stringify.impl.beans.BeansModule;
2122
import pl.wavesoftware.utils.stringify.spi.BeanFactory;
2223

2324
/**
2425
* @author <a href="mailto:krzysztof.suszynski@wavesoftware.pl">Krzysztof Suszynski</a>
2526
* @since 2.0.0
2627
*/
2728
final class DefaultConfiguration implements Configuration {
28-
static final DefaultBeanFactory DEFAULT_BEAN_FACTORY =
29-
new DefaultBeanFactory();
29+
private static final BeanFactory DEFAULT_BEAN_FACTORY =
30+
BeansModule.INSTANCE.defaultBeanFactory();
3031

3132
private Mode mode = Mode.DEFAULT_MODE;
3233
private BeanFactory beanFactory = DEFAULT_BEAN_FACTORY;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package pl.wavesoftware.utils.stringify.impl;
1818

19+
import pl.wavesoftware.utils.stringify.impl.inspector.InspectionContext;
20+
1921
import java.util.IdentityHashMap;
2022
import java.util.Map;
2123

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

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

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

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

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

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

src/main/java/pl/wavesoftware/utils/stringify/impl/Inspector.java renamed to src/main/java/pl/wavesoftware/utils/stringify/impl/InspectorBasedToStringResolver.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@
1717
package pl.wavesoftware.utils.stringify.impl;
1818

1919
import pl.wavesoftware.utils.stringify.api.InspectionPoint;
20+
import pl.wavesoftware.utils.stringify.impl.beans.BeanFactoryCache;
21+
import pl.wavesoftware.utils.stringify.impl.inspector.InspectionContext;
22+
import pl.wavesoftware.utils.stringify.impl.inspector.InspectorModule;
23+
import pl.wavesoftware.utils.stringify.impl.inspector.ObjectInspector;
2024

2125
import java.lang.reflect.Field;
22-
import java.util.Arrays;
2326
import java.util.LinkedHashMap;
2427
import java.util.Map;
2528
import java.util.function.Function;
@@ -30,16 +33,9 @@
3033
* @author <a href="mailto:krzysztof.suszynski@wavesoftware.pl">Krzysztof Suszynski</a>
3134
* @since 2.0.0
3235
*/
33-
final class Inspector implements ToStringResolver {
34-
private static final Iterable<ObjectInspector> OBJECT_INSPECTORS = Arrays.asList(
35-
new CharSequenceInspector(),
36-
new PrimitiveInspector(),
37-
new CharacterInspector(),
38-
new JpaLazyInspector(),
39-
new MapInspector(),
40-
new IterableInspector(),
41-
new RecursionInspector()
42-
);
36+
final class InspectorBasedToStringResolver implements ToStringResolver {
37+
private static final Iterable<ObjectInspector> OBJECT_INSPECTORS =
38+
InspectorModule.INSTANCE.inspectors();
4339

4440
private final DefaultConfiguration configuration;
4541
private final Object target;
@@ -48,7 +44,7 @@ final class Inspector implements ToStringResolver {
4844
private final BeanFactoryCache beanFactoryCache;
4945
private final InspectingFieldFactory inspectingFieldFactory;
5046

51-
Inspector(
47+
InspectorBasedToStringResolver(
5248
DefaultConfiguration configuration,
5349
Object target,
5450
InspectionContext inspectionContext,

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

100755100644
Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818

1919
import pl.wavesoftware.utils.stringify.api.Configuration;
2020
import pl.wavesoftware.utils.stringify.api.Mode;
21+
import pl.wavesoftware.utils.stringify.impl.beans.BeanFactoryCache;
22+
import pl.wavesoftware.utils.stringify.impl.beans.BeansModule;
23+
import pl.wavesoftware.utils.stringify.impl.inspector.InspectionContext;
2124
import pl.wavesoftware.utils.stringify.spi.BeanFactory;
2225

2326
import java.util.function.Function;
@@ -29,7 +32,7 @@
2932
final class ToStringResolverImpl implements ToStringResolver, Configuration {
3033

3134
private final DefaultConfiguration configuration;
32-
private final Inspector inspector;
35+
private final InspectorBasedToStringResolver delegateResolver;
3336

3437
/**
3538
* A default constructor
@@ -42,10 +45,8 @@ final class ToStringResolverImpl implements ToStringResolver, Configuration {
4245
target,
4346
configuration,
4447
new DefaultInspectionContext(),
45-
new BeanFactoryCache(() ->
46-
new FallbackBootFactory(
47-
new BootAwareBootFactory(configuration.getBeanFactory(), target)
48-
)
48+
BeansModule.INSTANCE.cachedBeanFactory(
49+
configuration::getBeanFactory, target
4950
),
5051
new InspectingFieldFactory(configuration::getMode)
5152
);
@@ -59,34 +60,34 @@ final class ToStringResolverImpl implements ToStringResolver, Configuration {
5960
InspectingFieldFactory inspectingFieldFactory
6061
) {
6162
this.configuration = configuration;
62-
this.inspector = new Inspector(
63+
this.delegateResolver = new InspectorBasedToStringResolver(
6364
configuration, target, inspectionContext, new ObjectInspectorImpl(),
6465
beanFactoryCache, inspectingFieldFactory
6566
);
6667
}
6768

6869
@Override
6970
public CharSequence resolve() {
70-
return inspector.resolve();
71+
return delegateResolver.resolve();
7172
}
7273

7374
@Override
7475
public Configuration mode(Mode mode) {
75-
inspector.clear();
76+
delegateResolver.clear();
7677
return configuration.mode(mode);
7778
}
7879

7980
@Override
8081
public Configuration beanFactory(BeanFactory beanFactory) {
81-
inspector.clear();
82+
delegateResolver.clear();
8283
return configuration.beanFactory(beanFactory);
8384
}
8485

8586
private final class ObjectInspectorImpl implements Function<Object, CharSequence> {
8687

8788
@Override
8889
public CharSequence apply(Object object) {
89-
return inspector.inspectObject(object);
90+
return delegateResolver.inspectObject(object);
9091
}
9192

9293
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2018-2019 Wave Software
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package pl.wavesoftware.utils.stringify.impl.beans;
18+
19+
import pl.wavesoftware.utils.stringify.spi.BeanFactory;
20+
21+
/**
22+
* A cache for bean factory.
23+
*
24+
* @author <a href="mailto:krzysztof.suszynski@wavesoftware.pl">Krzysztof Suszynski</a>
25+
* @since 0.1.0
26+
*/
27+
public interface BeanFactoryCache extends BeanFactory {
28+
/**
29+
* Clears a bean factory.
30+
*/
31+
void clear();
32+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2018-2019 Wave Software
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package pl.wavesoftware.utils.stringify.impl.beans;
18+
19+
import pl.wavesoftware.utils.stringify.spi.BeanFactory;
20+
21+
import java.util.function.Supplier;
22+
23+
/**
24+
* @author <a href="mailto:krzysztof.suszynski@wavesoftware.pl">Krzysztof Suszynski</a>
25+
* @since 2.0.0
26+
*/
27+
public enum BeansModule {
28+
INSTANCE;
29+
30+
public BeanFactory defaultBeanFactory() {
31+
return new DefaultBeanFactory();
32+
}
33+
34+
public BeanFactoryCache cachedBeanFactory(Supplier<BeanFactory> beanFactory, Object target) {
35+
return new DefaultBeanFactoryCache(() ->
36+
new FallbackBootFactory(
37+
new BootAwareBootFactory(beanFactory, target)
38+
)
39+
);
40+
}
41+
}

src/main/java/pl/wavesoftware/utils/stringify/impl/BootAwareBootFactory.java renamed to src/main/java/pl/wavesoftware/utils/stringify/impl/beans/BootAwareBootFactory.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@
1414
* limitations under the License.
1515
*/
1616

17-
package pl.wavesoftware.utils.stringify.impl;
17+
package pl.wavesoftware.utils.stringify.impl.beans;
1818

1919
import org.slf4j.Logger;
2020
import org.slf4j.LoggerFactory;
21+
import pl.wavesoftware.utils.stringify.impl.lang.Inspectable;
22+
import pl.wavesoftware.utils.stringify.impl.lang.LangModule;
2123
import pl.wavesoftware.utils.stringify.spi.BeanFactory;
2224
import pl.wavesoftware.utils.stringify.spi.BootingAware;
2325

24-
import static pl.wavesoftware.utils.stringify.impl.InspectionUtils.safeInspect;
26+
import java.util.function.Supplier;
2527

2628
/**
2729
* @author <a href="mailto:krzysztof.suszynski@wavesoftware.pl">Krzysztof Suszynski</a>
@@ -30,11 +32,11 @@
3032
final class BootAwareBootFactory implements BeanFactory, Inspectable {
3133
private static final Logger LOGGER =
3234
LoggerFactory.getLogger(BootAwareBootFactory.class);
33-
private final BeanFactory delegate;
35+
private final Supplier<BeanFactory> delegateSupplier;
3436
private final Object target;
3537

36-
BootAwareBootFactory(BeanFactory delegate, Object target) {
37-
this.delegate = delegate;
38+
BootAwareBootFactory(Supplier<BeanFactory> delegateSupplier, Object target) {
39+
this.delegateSupplier = delegateSupplier;
3840
this.target = target;
3941
}
4042

@@ -44,6 +46,7 @@ public <T> T create(Class<T> contractClass) {
4446
}
4547

4648
private BeanFactory getBeanFactory(Class<?> contractClass) {
49+
BeanFactory delegate = delegateSupplier.get();
4750
if (delegate instanceof BootingAware) {
4851
BootingAware bootingAware = (BootingAware) delegate;
4952
if (!bootingAware.isReady() && LOGGER.isWarnEnabled()) {
@@ -54,14 +57,18 @@ private BeanFactory getBeanFactory(Class<?> contractClass) {
5457
"fallback for this call.",
5558
safeInspect(delegate), safeInspect(target), contractClass
5659
);
57-
return DefaultConfiguration.DEFAULT_BEAN_FACTORY;
60+
return BeansModule.INSTANCE.defaultBeanFactory();
5861
}
5962
}
6063
return delegate;
6164
}
6265

6366
@Override
6467
public String inspect() {
65-
return safeInspect(delegate);
68+
return safeInspect(delegateSupplier);
69+
}
70+
71+
private static String safeInspect(Object object) {
72+
return LangModule.INSTANCE.safeInspector().inspect(object);
6673
}
6774
}

src/main/java/pl/wavesoftware/utils/stringify/impl/DefaultBeanFactory.java renamed to src/main/java/pl/wavesoftware/utils/stringify/impl/beans/DefaultBeanFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package pl.wavesoftware.utils.stringify.impl;
17+
package pl.wavesoftware.utils.stringify.impl.beans;
1818

1919
import pl.wavesoftware.utils.stringify.spi.BeanFactory;
2020

0 commit comments

Comments
 (0)