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 15package com.google.archivepatcher.applier; 16 17import com.google.archivepatcher.shared.PatchConstants; 18import com.google.archivepatcher.shared.PatchConstants.DeltaFormat; 19 20import com.google.archivepatcher.shared.TypedRange; 21 22/** 23 * Describes all of the information needed to apply a single delta operation - the format of the 24 * delta, the ranges in the delta-friendly old and new files that serve as inputs and outputs, and 25 * the number of bytes that the delta comprises in the patch stream. 26 */ 27public class DeltaDescriptor { 28 /** 29 * The format of the delta. 30 */ 31 private final PatchConstants.DeltaFormat format; 32 33 /** 34 * The work range for the delta-friendly old file. 35 */ 36 private final TypedRange<Void> deltaFriendlyOldFileRange; 37 38 /** 39 * The work range for the delta-friendly new file. 40 */ 41 private final TypedRange<Void> deltaFriendlyNewFileRange; 42 43 /** 44 * The number of bytes of delta data in the patch stream. 45 */ 46 private final long deltaLength; 47 48 /** 49 * Constructs a new descriptor having the specified data. 50 * @param format the format of the delta 51 * @param deltaFriendlyOldFileRange the work range for the delta-friendly old file 52 * @param deltaFriendlyNewFileRange the work range for the delta-friendly new file 53 * @param deltaLength the number of bytes of delta data in the patch stream 54 */ 55 public DeltaDescriptor( 56 DeltaFormat format, 57 TypedRange<Void> deltaFriendlyOldFileRange, 58 TypedRange<Void> deltaFriendlyNewFileRange, 59 long deltaLength) { 60 this.format = format; 61 this.deltaFriendlyOldFileRange = deltaFriendlyOldFileRange; 62 this.deltaFriendlyNewFileRange = deltaFriendlyNewFileRange; 63 this.deltaLength = deltaLength; 64 } 65 66 /** 67 * Returns the format of the delta. 68 * @return as described 69 */ 70 public PatchConstants.DeltaFormat getFormat() { 71 return format; 72 } 73 74 /** 75 * Returns the work range for the delta-friendly old file. 76 * @return as described 77 */ 78 public TypedRange<Void> getDeltaFriendlyOldFileRange() { 79 return deltaFriendlyOldFileRange; 80 } 81 82 /** 83 * Returns the work range for the delta-friendly new file. 84 * @return as described 85 */ 86 public TypedRange<Void> getDeltaFriendlyNewFileRange() { 87 return deltaFriendlyNewFileRange; 88 } 89 90 /** 91 * Returns the number of bytes of delta data in the patch stream. 92 * @return as described 93 */ 94 public long getDeltaLength() { 95 return deltaLength; 96 } 97 98 @Override 99 public int hashCode() { 100 final int prime = 31; 101 int result = 1; 102 result = 103 prime * result 104 + ((deltaFriendlyNewFileRange == null) ? 0 : deltaFriendlyNewFileRange.hashCode()); 105 result = 106 prime * result 107 + ((deltaFriendlyOldFileRange == null) ? 0 : deltaFriendlyOldFileRange.hashCode()); 108 result = prime * result + (int) (deltaLength ^ (deltaLength >>> 32)); 109 result = prime * result + ((format == null) ? 0 : format.hashCode()); 110 return result; 111 } 112 113 @Override 114 public boolean equals(Object obj) { 115 if (this == obj) return true; 116 if (obj == null) return false; 117 if (getClass() != obj.getClass()) return false; 118 DeltaDescriptor other = (DeltaDescriptor) obj; 119 if (deltaFriendlyNewFileRange == null) { 120 if (other.deltaFriendlyNewFileRange != null) return false; 121 } else if (!deltaFriendlyNewFileRange.equals(other.deltaFriendlyNewFileRange)) return false; 122 if (deltaFriendlyOldFileRange == null) { 123 if (other.deltaFriendlyOldFileRange != null) return false; 124 } else if (!deltaFriendlyOldFileRange.equals(other.deltaFriendlyOldFileRange)) return false; 125 if (deltaLength != other.deltaLength) return false; 126 if (format != other.format) return false; 127 return true; 128 } 129} 130