Home | History | Annotate | Download | only in distro
      1 /*
      2  * Copyright (C) 2017 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.timezone.distro;
     18 
     19 /**
     20  * Information about a staged time zone distro operation.
     21  */
     22 public class StagedDistroOperation {
     23 
     24     private static final StagedDistroOperation UNINSTALL_STAGED =
     25             new StagedDistroOperation(true /* isUninstall */, null /* stagedVersion */);
     26 
     27     public final boolean isUninstall;
     28     public final DistroVersion distroVersion;
     29 
     30     private StagedDistroOperation(boolean isUninstall, DistroVersion distroVersion) {
     31         this.isUninstall = isUninstall;
     32         this.distroVersion = distroVersion;
     33     }
     34 
     35     public static StagedDistroOperation install(DistroVersion distroVersion) {
     36         if (distroVersion == null) {
     37             throw new NullPointerException("distroVersion==null");
     38         }
     39         return new StagedDistroOperation(false /* isUninstall */, distroVersion);
     40     }
     41 
     42     public static StagedDistroOperation uninstall() {
     43         return UNINSTALL_STAGED;
     44     }
     45 
     46     @Override
     47     public boolean equals(Object o) {
     48         if (this == o) {
     49             return true;
     50         }
     51         if (o == null || getClass() != o.getClass()) {
     52             return false;
     53         }
     54 
     55         StagedDistroOperation that = (StagedDistroOperation) o;
     56 
     57         if (isUninstall != that.isUninstall) {
     58             return false;
     59         }
     60         return distroVersion != null ? distroVersion.equals(that.distroVersion)
     61                 : that.distroVersion == null;
     62     }
     63 
     64     @Override
     65     public int hashCode() {
     66         int result = (isUninstall ? 1 : 0);
     67         result = 31 * result + (distroVersion != null ? distroVersion.hashCode() : 0);
     68         return result;
     69     }
     70 
     71     @Override
     72     public String toString() {
     73         return "StagedDistroOperation{" +
     74                 "isUninstall=" + isUninstall +
     75                 ", distroVersion=" + distroVersion +
     76                 '}';
     77     }
     78 }
     79