Пример #1
0
 @Override
 public boolean contains(Object o) {
   if (!(o instanceof Entry)) {
     return false;
   }
   Entry<?, ?> entry = (Entry<?, ?>) o;
   Object entryKey = entry.getKey();
   Object entryValue = entry.getValue();
   V2 mapValue = TransformingMap.this.get(entryKey);
   if (mapValue != null) {
     return mapValue.equals(entryValue);
   }
   return entryValue == null && containsKey(entryKey);
 }
Пример #2
0
 /**
  * Find the highest key that corresponds to a record that is the oldest (or first) of a read-only
  * log file and where value mapped from the record is lower or equals to provided limit value.
  *
  * <p>Example<br>
  * Given a log with 3 log files, with Record<Int, String> and Mapper<String, Long> mapping a
  * string to its long value
  *
  * <ul>
  *   <li>1_10.log where oldest record is (key=1, value="50")
  *   <li>11_20.log where oldest record is (key=11, value="150")
  *   <li>head.log where oldest record is (key=25, value="250")
  * </ul>
  *
  * Then
  *
  * <ul>
  *   <li>findBoundaryKeyFromRecord(mapper, 20) => null
  *   <li>findBoundaryKeyFromRecord(mapper, 50) => 1
  *   <li>findBoundaryKeyFromRecord(mapper, 100) => 1
  *   <li>findBoundaryKeyFromRecord(mapper, 150) => 11
  *   <li>findBoundaryKeyFromRecord(mapper, 200) => 11
  *   <li>findBoundaryKeyFromRecord(mapper, 250) => 25
  *   <li>findBoundaryKeyFromRecord(mapper, 300) => 25
  * </ul>
  *
  * @param <V2> Type of the value extracted from the record
  * @param mapper The mapper to extract a value from a record. It is expected that extracted values
  *     are ordered according to an order consistent with this log ordering, i.e. for two records,
  *     if key(R1) > key(R2) then extractedValue(R1) > extractedValue(R2).
  * @param limitValue The limit value to search for
  * @return the key or {@code null} if no key corresponds
  * @throws ChangelogException If a problem occurs
  */
 <V2 extends Comparable<V2>> K findBoundaryKeyFromRecord(
     Record.Mapper<V, V2> mapper, V2 limitValue) throws ChangelogException {
   sharedLock.lock();
   try {
     K key = null;
     for (LogFile<K, V> logFile : logFiles.values()) {
       final Record<K, V> record = logFile.getOldestRecord();
       final V2 oldestValue = mapper.map(record.getValue());
       if (oldestValue.compareTo(limitValue) > 0) {
         return key;
       }
       key = record.getKey();
     }
     return key;
   } finally {
     sharedLock.unlock();
   }
 }
Пример #3
0
  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;

    Tuple tuple = (Tuple) o;

    if (v1 != null ? !v1.equals(tuple.v1) : tuple.v1 != null) return false;
    if (v2 != null ? !v2.equals(tuple.v2) : tuple.v2 != null) return false;

    return true;
  }
Пример #4
0
 @Override
 public int hashCode() {
   int result = v1 != null ? v1.hashCode() : 0;
   result = 31 * result + (v2 != null ? v2.hashCode() : 0);
   return result;
 }