
com.codurance.lightaccess.mapping.OneToMany Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of light-access Show documentation
Show all versions of light-access Show documentation
Non-intrusive JDBC library supporting lambdas
The newest version!
package com.codurance.lightaccess.mapping;
import java.util.*;
import java.util.function.BiFunction;
import static org.apache.commons.lang3.builder.EqualsBuilder.reflectionEquals;
public class OneToMany {
private Map> data = new HashMap<>();
public void put(KeyValue> keyValue) {
if (keyValue.getValue().isPresent()) {
this.put(keyValue.getKey(), keyValue.getValue());
} else {
this.put(keyValue.getKey(), Optional.empty());
}
}
public void put(K key, Optional value) {
List children = data.getOrDefault(key, new ArrayList<>());
value.ifPresent(children::add);
data.put(key, children);
}
public List collect(BiFunction, T> collect) {
List list = new ArrayList<>();
data.forEach((key, value) -> list.add(collect.apply(key, value)));
return list;
}
@Override
public boolean equals(Object other) {
return reflectionEquals(this, other);
}
@Override
public String toString() {
return "OneToMany{" +
"data=" + data +
'}';
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy