Skip to content

Commit

Permalink
Merge branch 'release/1.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
cardil committed Apr 30, 2018
2 parents bb236ec + b99ceb6 commit 8eee552
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 32 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>pl.wavesoftware.utils</groupId>
<artifactId>stringify-object</artifactId>
<version>1.0.1</version>
<version>1.0.2</version>
<packaging>jar</packaging>

<name>Stringify Object for Java</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @author <a href="mailto:krzysztof.suszynski@coi.gov.pl">Krzysztof Suszynski</a>
* @since 27.04.18
*/
public interface InspectingField {
interface InspectingField {
boolean shouldInspect();
boolean showNull();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import lombok.RequiredArgsConstructor;
import pl.wavesoftware.utils.stringify.configuration.BeanFactory;
import pl.wavesoftware.utils.stringify.configuration.DisplayNull;
import pl.wavesoftware.utils.stringify.configuration.InspectionPoint;
import pl.wavesoftware.utils.stringify.configuration.Mode;

Expand All @@ -27,30 +26,4 @@ private InspectFieldPredicate createPredicate(BeanFactory beanFactory) {
}
}

@RequiredArgsConstructor
private class InspectingFieldImpl implements InspectingField {
private final InspectionPoint inspectionPoint;
private final InspectFieldPredicate predicate;

@Override
public boolean shouldInspect() {
return technically() && predicate.shouldInspect(inspectionPoint);
}

private boolean technically() {
return !inspectionPoint.getField().isEnumConstant()
&& !inspectionPoint.getField().isSynthetic();
}

@Override
public boolean showNull() {
DisplayNull displayNull = inspectionPoint.getField()
.getAnnotation(DisplayNull.class);
if (displayNull != null) {
return displayNull.value();
} else {
return DisplayNull.BY_DEFAULT;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package pl.wavesoftware.utils.stringify.impl;

import lombok.RequiredArgsConstructor;
import pl.wavesoftware.utils.stringify.configuration.DisplayNull;
import pl.wavesoftware.utils.stringify.configuration.InspectionPoint;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

/**
* @author <a href="krzysztof.suszynski@wavesoftware.pl">Krzysztof Suszyński</a>
* @since 2018-04-30
*/
@RequiredArgsConstructor
final class InspectingFieldImpl implements InspectingField {
private final InspectionPoint inspectionPoint;
private final InspectFieldPredicate predicate;

@Override
public boolean shouldInspect() {
return technically() && predicate.shouldInspect(inspectionPoint);
}

private boolean technically() {
Field field = inspectionPoint.getField();
int mods = field.getModifiers();
return !Modifier.isStatic(mods)
&& !field.isEnumConstant()
&& !field.isSynthetic();
}

@Override
public boolean showNull() {
DisplayNull displayNull = inspectionPoint.getField()
.getAnnotation(DisplayNull.class);
if (displayNull != null) {
return displayNull.value();
} else {
return DisplayNull.BY_DEFAULT;
}
}
}
3 changes: 3 additions & 0 deletions src/test/java/pl/wavesoftware/utils/stringify/Earth.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
@Data
@EqualsAndHashCode(callSuper = true)
final class Earth extends Planet {

private static final long serialVersionUID = 20180430201544L;

@Inspect
private Moon moon;
@Inspect
Expand Down
3 changes: 3 additions & 0 deletions src/test/java/pl/wavesoftware/utils/stringify/Moon.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
@ToString(exclude = "nullinside")
@EqualsAndHashCode(callSuper = true)
final class Moon extends Planet {

private static final long serialVersionUID = 20180430201602L;

@Inspect
private Phase phase;
@Inspect
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/pl/wavesoftware/utils/stringify/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
*/
@Setter
class Person {
private int id;
private volatile int id;
@DisplayNull
private Person parent;
private transient Person parent;
private List<Person> childs;
private Account account;
@Inspect(conditionally = IsInDevelopment.class)
Expand Down
7 changes: 6 additions & 1 deletion src/test/java/pl/wavesoftware/utils/stringify/Planet.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@
import pl.wavesoftware.utils.stringify.configuration.DoNotInspect;
import pl.wavesoftware.utils.stringify.configuration.Inspect;

import java.io.Serializable;

/**
* @author <a href="krzysztof.suszynski@wavesoftware.pl">Krzysztof Suszyński</a>
* @since 2018-04-18
*/
@Data
abstract class Planet {
abstract class Planet implements Serializable {

private static final long serialVersionUID = 20180430201529L;

@Inspect
private String name;
@Inspect
Expand Down

0 comments on commit 8eee552

Please sign in to comment.