Skip to content

Commit 63fec4a

Browse files
committed
DATACMNS-1251 - Polishing.
Made methods static where possible. Original pull request: #270.
1 parent 139e098 commit 63fec4a

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

src/main/java/org/springframework/data/history/AnnotationRevisionMetadata.java

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,37 @@ public Optional<N> getRevisionNumber() {
7676
@Deprecated
7777
public Optional<LocalDateTime> getRevisionDate() {
7878

79-
return revisionDate.get().map(this::convertToLocalDateTime);
79+
return revisionDate.get().map(AnnotationRevisionMetadata::convertToLocalDateTime);
8080
}
8181

8282
/*
8383
* (non-Javadoc)
8484
* @see org.springframework.data.history.RevisionMetadata#getRevisionDate()
8585
*/
8686
public Optional<Instant> getRevisionInstant() {
87-
return revisionDate.get().map(this::convertToInstant);
87+
return revisionDate.get().map(AnnotationRevisionMetadata::convertToInstant);
8888
}
8989

90-
private LocalDateTime convertToLocalDateTime(TemporalAccessor temporalAccessor) {
90+
/*
91+
* (non-Javadoc)
92+
* @see org.springframework.data.repository.history.RevisionMetadata#getDelegate()
93+
*/
94+
@SuppressWarnings("unchecked")
95+
public <T> T getDelegate() {
96+
return (T) entity;
97+
}
98+
99+
private static <T> Lazy<Optional<T>> detectAnnotation(Object entity, Class<? extends Annotation> annotationType) {
100+
101+
return Lazy.of(() -> {
102+
103+
AnnotationDetectionFieldCallback callback = new AnnotationDetectionFieldCallback(annotationType);
104+
ReflectionUtils.doWithFields(entity.getClass(), callback);
105+
return Optional.ofNullable(callback.getValue(entity));
106+
});
107+
}
108+
109+
private static LocalDateTime convertToLocalDateTime(TemporalAccessor temporalAccessor) {
91110

92111
if (temporalAccessor instanceof LocalDateTime) {
93112
return (LocalDateTime) temporalAccessor;
@@ -97,10 +116,10 @@ private LocalDateTime convertToLocalDateTime(TemporalAccessor temporalAccessor)
97116
return LocalDateTime.ofInstant((Instant) temporalAccessor, ZoneOffset.systemDefault());
98117
}
99118

100-
throw new IllegalArgumentException(String.format("Can't convert %s to LocalDateTime", temporalAccessor));
119+
throw new IllegalArgumentException(String.format("Can't convert %s to LocalDateTime!", temporalAccessor));
101120
}
102121

103-
private Instant convertToInstant(TemporalAccessor temporalAccessor) {
122+
private static Instant convertToInstant(TemporalAccessor temporalAccessor) {
104123

105124
if (temporalAccessor instanceof Instant) {
106125
return (Instant) temporalAccessor;
@@ -110,25 +129,6 @@ private Instant convertToInstant(TemporalAccessor temporalAccessor) {
110129
return ((LocalDateTime) temporalAccessor).atZone(ZoneOffset.systemDefault()).toInstant();
111130
}
112131

113-
throw new IllegalArgumentException(String.format("Can't convert %s to LocalDateTime", temporalAccessor));
114-
}
115-
116-
/*
117-
* (non-Javadoc)
118-
* @see org.springframework.data.repository.history.RevisionMetadata#getDelegate()
119-
*/
120-
@SuppressWarnings("unchecked")
121-
public <T> T getDelegate() {
122-
return (T) entity;
123-
}
124-
125-
private static <T> Lazy<Optional<T>> detectAnnotation(Object entity, Class<? extends Annotation> annotationType) {
126-
127-
return Lazy.of(() -> {
128-
129-
AnnotationDetectionFieldCallback callback = new AnnotationDetectionFieldCallback(annotationType);
130-
ReflectionUtils.doWithFields(entity.getClass(), callback);
131-
return Optional.ofNullable(callback.getValue(entity));
132-
});
132+
throw new IllegalArgumentException(String.format("Can't convert %s to LocalDateTime!", temporalAccessor));
133133
}
134134
}

0 commit comments

Comments
 (0)