Ejemplo n.º 1
0
 /** pre-condition: mergeTo and beMerged are isostructural */
 private static void mergeRegularFiles(
     @Nonnull RegularFile mergeTo, @Nonnull RegularFile beMerged) {
   final Map<Hash.Algorithm, Hash> hashesInMergeTo = mergeTo.getHashes();
   for (Map.Entry<Hash.Algorithm, Hash> entry : beMerged.getHashes().entrySet()) {
     final Hash.Algorithm algorithm = entry.getKey();
     final Hash hashInMergeTo = hashesInMergeTo.get(algorithm);
     final Hash hashInBeMerged = entry.getValue();
     if (hashInMergeTo == null) {
       hashesInMergeTo.put(algorithm, hashInBeMerged);
     } else {
       if (!Objects.equals(hashInMergeTo, hashInBeMerged)) {
         throw new IllegalStateException(
             "mergeTo and beMerged have different " + algorithm + " hash value");
       }
     }
   }
 }
Ejemplo n.º 2
0
 static Set<Hash.Algorithm> getUsedAlgorithms1(RegularFile file) {
   Set<Hash.Algorithm> algorithms = EnumSet.noneOf(Hash.Algorithm.class);
   for (Map.Entry<Hash.Algorithm, Hash> entry : file.getHashes().entrySet()) {
     if (entry.getValue() != null) {
       algorithms.add(entry.getKey());
     }
   }
   return algorithms;
 }