Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Info {
- private final String name;
- private final String desc;
- private String version = null;
- @Override
- public boolean equals(Object that) {
- if (that == null) {
- return false;
- }
- if (that instanceof Info) {
- Info other = (Info) that;
- return Objects.equals(this.name, other.name) &&
- Objects.equals(this.desc, other.desc) &&
- Objects.equals(this.version, other.version);
- } else {
- return false;
- }
- }
- public boolean equalsWithoutVersion(Object that) {
- if (that == null) {
- return false;
- }
- if (that instanceof Info) {
- Info other = (Info) that;
- return Objects.equals(this.name, other.name) &&
- Objects.equals(this.desc, other.desc);
- } else {
- return false;
- }
- }
- @Override
- public int hashCode() {
- int hash = 13;
- hash = (hash * 7) + name.hashCode();
- hash = (hash * 7) + desc.hashCode();
- if (version != null)
- hash = (hash * 7) + version.hashCode();
- return hash;
- }
- @Override
- public String toString() {
- String versionString = version == null ? "latest" : version;
- return String.format("Name: %s Desc: %s Key Type: %s Version: %s", this.name, this.desc, this.keyType.name(), versionString);
- }
- }
- public class Value implements Comparable<Value> {
- private String data;
- private String version;
- public Value(String version, String data) {
- this.version = version;
- this.data = data;
- }
- @Override
- public int compareTo(Value o) {
- return (Integer.parseInt(this.version) > Integer.parseInt(o.version)) ? -1
- : (Integer.parseInt(this.version) < Integer.parseInt(o.version)) ? 1
- : 0;
- }
- }
- public class Cache {
- private final Map<Info, Value> dataMap = new HashMap<>();
- ...
- private Key getlatestVersionFromCache(Info info) {
- List<Value> values = dataMap.entrySet()
- .filter(p -> p.getKey().equalsWithoutVersion(info))
- .sorted(Map.Entry.comparingByValue())
- .map(x::getValue))
- .collect(Collectors.toList());
- }
- }
- Syntax error on token ")", ElidedSemicolonAndRightBrace expected
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement