SHARE
TWEET

Untitled

a guest Jun 15th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class Info {
  2. private final String name;
  3. private final String desc;
  4. private String version = null;
  5.  
  6. @Override
  7. public boolean equals(Object that) {
  8.     if (that == null) {
  9.         return false;
  10.     }
  11.  
  12.     if (that instanceof Info) {
  13.         Info other = (Info) that;
  14.  
  15.         return Objects.equals(this.name, other.name) &&
  16.                 Objects.equals(this.desc, other.desc) &&
  17.                 Objects.equals(this.version, other.version);
  18.  
  19.     } else {
  20.         return false;
  21.     }
  22. }
  23.  
  24. public boolean equalsWithoutVersion(Object that) {
  25.     if (that == null) {
  26.         return false;
  27.     }
  28.  
  29.     if (that instanceof Info) {
  30.         Info other = (Info) that;
  31.  
  32.         return Objects.equals(this.name, other.name) &&
  33.                 Objects.equals(this.desc, other.desc);
  34.     } else {
  35.         return false;
  36.     }
  37. }
  38.  
  39. @Override
  40. public int hashCode() {
  41.     int hash = 13;
  42.     hash = (hash * 7) + name.hashCode();
  43.     hash = (hash * 7) + desc.hashCode();
  44.  
  45.     if (version != null)
  46.         hash = (hash * 7) + version.hashCode();
  47.  
  48.     return hash;
  49. }
  50.  
  51. @Override
  52. public String toString() {
  53.     String versionString = version == null ? "latest" : version;
  54.     return String.format("Name: %s  Desc: %s  Key Type: %s Version: %s", this.name, this.desc, this.keyType.name(), versionString);
  55. }
  56. }
  57.      
  58. public class Value implements Comparable<Value> {
  59. private String data;
  60. private String version;
  61.  
  62. public Value(String version, String data) {
  63.     this.version = version;
  64.     this.data = data;
  65. }
  66.  
  67. @Override
  68. public int compareTo(Value o) {
  69.     return (Integer.parseInt(this.version) > Integer.parseInt(o.version)) ? -1
  70.             : (Integer.parseInt(this.version) < Integer.parseInt(o.version)) ? 1
  71.             : 0;
  72. }
  73. }
  74.      
  75. public class Cache {
  76.     private final Map<Info, Value> dataMap = new HashMap<>();
  77.  
  78.     ...
  79.     private Key getlatestVersionFromCache(Info info) {
  80.     List<Value> values = dataMap.entrySet()
  81.             .filter(p -> p.getKey().equalsWithoutVersion(info))
  82.             .sorted(Map.Entry.comparingByValue())
  83.             .map(x::getValue))
  84.             .collect(Collectors.toList());
  85. }
  86. }
  87.      
  88. Syntax error on token ")", ElidedSemicolonAndRightBrace expected
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top