Esempio n. 1
0
 /**
  * Order non-idempotent RuleKeys as less than all idempotent RuleKeys.
  *
  * <p>non-idempotent < idempotent
  */
 @Override
 public int compareTo(RuleKey other) {
   if (!isIdempotent()) {
     if (!other.isIdempotent()) {
       return 0;
     }
     return -1;
   } else if (!other.isIdempotent()) {
     return 1;
   }
   return ByteBuffer.wrap(hashCode.asBytes()).compareTo(ByteBuffer.wrap(other.hashCode.asBytes()));
 }
Esempio n. 2
0
 private Builder setVal(@Nullable RuleKey ruleKey) {
   if (ruleKey != null) {
     if (logElms != null) {
       logElms.add(
           String.format(
               "%sruleKey(sha1=%s):",
               ruleKey.isIdempotent() ? "" : "non-idempotent ", ruleKey.toString()));
     }
     feed(ruleKey.toString().getBytes()).mergeIdempotence(ruleKey.isIdempotent());
   }
   return separate();
 }
Esempio n. 3
0
 /** Helper method used to avoid memoizing non-idempotent RuleKeys. */
 @Nullable
 public static RuleKey filter(RuleKey ruleKey) {
   if (!ruleKey.isIdempotent()) {
     return null;
   }
   return ruleKey;
 }
Esempio n. 4
0
 /**
  * Treat non-idempotent RuleKeys as unequal to everything, including other non-idempotent
  * RuleKeys.
  */
 @Override
 public boolean equals(Object that) {
   if (!(that instanceof RuleKey)) {
     return false;
   }
   RuleKey other = (RuleKey) that;
   if (!isIdempotent() || !other.isIdempotent()) {
     return false;
   }
   return (compareTo(other) == 0);
 }
Esempio n. 5
0
 public RuleKey build() {
   RuleKey ruleKey = idempotent ? new RuleKey(hasher.hash()) : new RuleKey(null);
   if (logElms != null) {
     logger.info(
         String.format(
             "%sRuleKey %s=%s",
             ruleKey.isIdempotent() ? "" : "non-idempotent ",
             ruleKey.toString(),
             Joiner.on("").join(logElms)));
   }
   return ruleKey;
 }