001package org.apache.maven.scm.provider.accurev; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import java.io.File; 023 024/** 025 * 026 */ 027public class FileDifference 028{ 029 030 private String oldVersionSpec = null; 031 032 private File oldFile = null; 033 034 private String newVersionSpec = null; 035 036 private File newFile = null; 037 038 private long elementId = -1; 039 040 public FileDifference( long elementId, String newPath, String newVersion, String oldPath, String oldVersion ) 041 { 042 setElementId( elementId ); 043 setNewVersion( newPath, newVersion ); 044 setOldVersion( oldPath, oldVersion ); 045 } 046 047 public FileDifference() 048 { 049 050 } 051 052 public String getOldVersionSpec() 053 { 054 return oldVersionSpec; 055 } 056 057 public File getOldFile() 058 { 059 return oldFile; 060 } 061 062 public String getNewVersionSpec() 063 { 064 return newVersionSpec; 065 } 066 067 public File getNewFile() 068 { 069 return newFile; 070 } 071 072 public long getElementId() 073 { 074 return elementId; 075 } 076 077 public void setElementId( long elementId ) 078 { 079 this.elementId = elementId; 080 } 081 082 public void setNewVersion( String path, String version ) 083 { 084 085 this.newFile = 086 ( oldFile != null && oldFile.getPath().equals( path ) ) ? oldFile : path == null ? null : new File( path ); 087 this.newVersionSpec = version; 088 089 } 090 091 public void setOldVersion( String path, String version ) 092 { 093 094 this.oldFile = 095 ( newFile != null && newFile.getPath().equals( path ) ) ? newFile : path == null ? null : new File( path ); 096 this.oldVersionSpec = version; 097 098 } 099 100 @Override 101 public String toString() 102 { 103 return "FileDifference [elementId=" + elementId + ", newFile=" + newFile + ", newVersionSpec=" + newVersionSpec 104 + ", oldFile=" + oldFile + ", oldVersionSpec=" + oldVersionSpec + "]"; 105 } 106 107 @Override 108 public int hashCode() 109 { 110 final int prime = 31; 111 int result = 1; 112 result = prime * result + (int) ( elementId ^ ( elementId >>> 32 ) ); 113 result = prime * result + ( ( newFile == null ) ? 0 : newFile.hashCode() ); 114 result = prime * result + ( ( newVersionSpec == null ) ? 0 : newVersionSpec.hashCode() ); 115 result = prime * result + ( ( oldFile == null ) ? 0 : oldFile.hashCode() ); 116 result = prime * result + ( ( oldVersionSpec == null ) ? 0 : oldVersionSpec.hashCode() ); 117 return result; 118 } 119 120 @Override 121 public boolean equals( Object obj ) 122 { 123 if ( this == obj ) 124 { 125 return true; 126 } 127 if ( obj == null ) 128 { 129 return false; 130 } 131 if ( getClass() != obj.getClass() ) 132 { 133 return false; 134 } 135 FileDifference other = (FileDifference) obj; 136 if ( elementId != other.elementId ) 137 { 138 return false; 139 } 140 if ( newFile == null ) 141 { 142 if ( other.newFile != null ) 143 { 144 return false; 145 } 146 } 147 else if ( !newFile.equals( other.newFile ) ) 148 { 149 return false; 150 } 151 if ( newVersionSpec == null ) 152 { 153 if ( other.newVersionSpec != null ) 154 { 155 return false; 156 } 157 } 158 else if ( !newVersionSpec.equals( other.newVersionSpec ) ) 159 { 160 return false; 161 } 162 if ( oldFile == null ) 163 { 164 if ( other.oldFile != null ) 165 { 166 return false; 167 } 168 } 169 else if ( !oldFile.equals( other.oldFile ) ) 170 { 171 return false; 172 } 173 if ( oldVersionSpec == null ) 174 { 175 if ( other.oldVersionSpec != null ) 176 { 177 return false; 178 } 179 } 180 else if ( !oldVersionSpec.equals( other.oldVersionSpec ) ) 181 { 182 return false; 183 } 184 return true; 185 } 186 187}