Home | History | Annotate | Download | only in generator
      1 // Copyright 2016 Google Inc. All rights reserved.
      2 //
      3 // Licensed under the Apache License, Version 2.0 (the "License");
      4 // you may not use this file except in compliance with the License.
      5 // You may obtain a copy of the License at
      6 //
      7 //     http://www.apache.org/licenses/LICENSE-2.0
      8 //
      9 // Unless required by applicable law or agreed to in writing, software
     10 // distributed under the License is distributed on an "AS IS" BASIS,
     11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 // See the License for the specific language governing permissions and
     13 // limitations under the License.
     14 
     15 package com.google.archivepatcher.generator;
     16 
     17 /**
     18  * A fully qualified recommendation, consisting of an {@link MinimalZipEntry} from the old file,
     19  * a {@link MinimalZipEntry} from the new file, a {@link Recommendation} for how to proceed and a
     20  * {@link RecommendationReason} for that recommendation.
     21  */
     22 public class QualifiedRecommendation {
     23   /**
     24    * The entry in the old file.
     25    */
     26   private final MinimalZipEntry oldEntry;
     27 
     28   /**
     29    * The entry in the new file.
     30    */
     31   private final MinimalZipEntry newEntry;
     32 
     33   /**
     34    * The recommendation for how to proceed on the pair of entries.
     35    */
     36   private final Recommendation recommendation;
     37 
     38   /**
     39    * The reason for the recommendation.
     40    */
     41   private final RecommendationReason reason;
     42 
     43   /**
     44    * Construct a new qualified recommendation with the specified data.
     45    * @param oldEntry the entry in the old file
     46    * @param newEntry the entry in the new file
     47    * @param recommendation the recommendation for this tuple of entries
     48    * @param reason the reason for the recommendation
     49    */
     50   public QualifiedRecommendation(
     51       MinimalZipEntry oldEntry,
     52       MinimalZipEntry newEntry,
     53       Recommendation recommendation,
     54       RecommendationReason reason) {
     55     super();
     56     this.oldEntry = oldEntry;
     57     this.newEntry = newEntry;
     58     this.recommendation = recommendation;
     59     this.reason = reason;
     60   }
     61 
     62   /**
     63    * Returns the entry in the old file.
     64    * @return as described
     65    */
     66   public MinimalZipEntry getOldEntry() {
     67     return oldEntry;
     68   }
     69 
     70   /**
     71    * Returns the entry in the new file.
     72    * @return as described
     73    */
     74   public MinimalZipEntry getNewEntry() {
     75     return newEntry;
     76   }
     77 
     78   /**
     79    * Returns the recommendation for how to proceed for this tuple of entries.
     80    * @return as described
     81    */
     82   public Recommendation getRecommendation() {
     83     return recommendation;
     84   }
     85 
     86   /**
     87    * Returns the reason for the recommendation.
     88    * @return as described
     89    */
     90   public RecommendationReason getReason() {
     91     return reason;
     92   }
     93 
     94   @Override
     95   public int hashCode() {
     96     final int prime = 31;
     97     int result = 1;
     98     result = prime * result + ((newEntry == null) ? 0 : newEntry.hashCode());
     99     result = prime * result + ((oldEntry == null) ? 0 : oldEntry.hashCode());
    100     result = prime * result + ((reason == null) ? 0 : reason.hashCode());
    101     result = prime * result + ((recommendation == null) ? 0 : recommendation.hashCode());
    102     return result;
    103   }
    104 
    105   @Override
    106   public boolean equals(Object obj) {
    107     if (this == obj) {
    108       return true;
    109     }
    110     if (obj == null) {
    111       return false;
    112     }
    113     if (getClass() != obj.getClass()) {
    114       return false;
    115     }
    116     QualifiedRecommendation other = (QualifiedRecommendation) obj;
    117     if (newEntry == null) {
    118       if (other.newEntry != null) {
    119         return false;
    120       }
    121     } else if (!newEntry.equals(other.newEntry)) {
    122       return false;
    123     }
    124     if (oldEntry == null) {
    125       if (other.oldEntry != null) {
    126         return false;
    127       }
    128     } else if (!oldEntry.equals(other.oldEntry)) {
    129       return false;
    130     }
    131     if (reason != other.reason) {
    132       return false;
    133     }
    134     if (recommendation != other.recommendation) {
    135       return false;
    136     }
    137     return true;
    138   }
    139 
    140   @Override
    141   public String toString() {
    142     return "QualifiedRecommendation [oldEntry="
    143         + oldEntry.getFileName()
    144         + ", newEntry="
    145         + newEntry.getFileName()
    146         + ", recommendation="
    147         + recommendation
    148         + ", reason="
    149         + reason
    150         + "]";
    151   }
    152 
    153 }