Ejemplo 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()));
 }
Ejemplo 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();
 }
Ejemplo 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;
 }
Ejemplo 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);
 }
Ejemplo 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;
 }