Skip to content

Commit

Permalink
Inline Field#equals check
Browse files Browse the repository at this point in the history
  • Loading branch information
ferdinand-swoboda committed Nov 9, 2021
1 parent dd12846 commit 25bb5e9
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 34 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,9 @@ decrease. (There are exceptions to this rule, e.g. when more code is deleted tha
[sonarcloud-measure-maintainability]: https://sonarcloud.io/component_measures?id=tech.picnic.jolo%3Ajolo&metric=Maintainability
[travisci-badge]: https://travis-ci.org/PicnicSupermarket/jolo.svg?branch=master
[travisci-builds]: https://travis-ci.org/PicnicSupermarket/jolo

## todo
- make Loader implement Collector
- test against WMS Insight (locally)
- Implement Copyable to replace prototype pattern or use immutables
- Adopt Java modules
12 changes: 7 additions & 5 deletions src/main/java/tech/picnic/jolo/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static java.util.Arrays.stream;
import static java.util.stream.Stream.concat;
import static tech.picnic.jolo.Util.equalFieldNames;
import static tech.picnic.jolo.Util.validate;

import java.util.Arrays;
Expand Down Expand Up @@ -95,7 +94,9 @@ public String toString() {
* the constructor with the extra argument is used to bring it into Java land.
*/
public Entity<T, R> withExtraFields(Field<?>... extraFields) {
fields = concat(stream(fields), stream(extraFields)).toArray(Field<?>[]::new);
fields =
concat(stream(fields), stream(extraFields).filter(Objects::nonNull))
.toArray(Field<?>[]::new);
return this;
}

Expand Down Expand Up @@ -129,7 +130,9 @@ T load(Record record) {
* record contains FOO.ID=1 and BAR.X=1, then without this measure, BAR.X would be used
* instead of FOO.X.
*/
return record.into(resultFields).into(type);
T result = record.into(resultFields).into(type);
Objects.requireNonNull(result);
return result;
}

/**
Expand Down Expand Up @@ -157,8 +160,7 @@ private void check(Record record) {
primaryKey.equals(record.field(primaryKey)),
"Primary key column %s not found in result record",
primaryKey);
resultFields =
stream(fields).filter(f -> equalFieldNames(f, record.field(f))).toArray(Field<?>[]::new);
resultFields = stream(fields).filter(f -> f.equals(record.field(f))).toArray(Field<?>[]::new);
}
}
}
1 change: 0 additions & 1 deletion src/main/java/tech/picnic/jolo/ObjectGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ final class ObjectGraph {
* same entity and with the same ID already exists, the given object is ignored.
*/
<E> void add(Entity<? extends E, ?> entity, long id, E object) {
requireNonNull(object);
if (!entityAndIdToObject.contains(entity, id)) {
entityAndIdToObject.put(entity, id, object);
}
Expand Down
10 changes: 0 additions & 10 deletions src/main/java/tech/picnic/jolo/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,6 @@ static <L extends Record, R extends Record> Optional<TableField<?, Long>> getOpt
return Optional.of(getKey(from, keys.get(0).getFields(), "foreign"));
}

static boolean equalFieldNames(@Nullable Field<?> left, @Nullable Field<?> right) {
if (left == null) {
return right == null;
}
if (right == null) {
return false;
}
return left.equals(right);
}

@FormatMethod
static void validate(boolean condition, String message, @Nullable Object... args) {
if (!condition) {
Expand Down
18 changes: 0 additions & 18 deletions src/test/java/tech/picnic/jolo/UtilTest.java

This file was deleted.

0 comments on commit 25bb5e9

Please sign in to comment.