o Strengthened cache key

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@903183 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2010-01-26 11:40:44 +00:00
parent 3586158679
commit 459c2e4e03
1 changed files with 14 additions and 3 deletions

View File

@ -44,6 +44,10 @@ public class DefaultExtensionRealmCache
private final List<File> files; private final List<File> files;
private final List<Long> timestamps;
private final List<Long> sizes;
private final List<String> ids; private final List<String> ids;
private final int hashCode; private final int hashCode;
@ -51,15 +55,21 @@ public class DefaultExtensionRealmCache
public CacheKey( List<? extends Artifact> extensionArtifacts ) public CacheKey( List<? extends Artifact> extensionArtifacts )
{ {
this.files = new ArrayList<File>( extensionArtifacts.size() ); this.files = new ArrayList<File>( extensionArtifacts.size() );
this.timestamps = new ArrayList<Long>( extensionArtifacts.size() );
this.sizes = new ArrayList<Long>( extensionArtifacts.size() );
this.ids = new ArrayList<String>( extensionArtifacts.size() ); this.ids = new ArrayList<String>( extensionArtifacts.size() );
for ( Artifact artifact : extensionArtifacts ) for ( Artifact artifact : extensionArtifacts )
{ {
files.add( artifact.getFile() ); File file = artifact.getFile();
files.add( file );
timestamps.add( ( file != null ) ? Long.valueOf( file.lastModified() ) : Long.valueOf( 0 ) );
sizes.add( ( file != null ) ? Long.valueOf( file.length() ) : Long.valueOf( 0 ) );
ids.add( artifact.getVersion() ); ids.add( artifact.getVersion() );
} }
this.hashCode = files.hashCode() * 31 + ids.hashCode(); this.hashCode =
31 * files.hashCode() + 31 * ids.hashCode() + 31 * timestamps.hashCode() + 31 * sizes.hashCode();
} }
@Override @Override
@ -83,7 +93,8 @@ public class DefaultExtensionRealmCache
CacheKey other = (CacheKey) o; CacheKey other = (CacheKey) o;
return files.equals( other.files ) && ids.equals( other.ids ); return ids.equals( other.ids ) && files.equals( other.files ) && timestamps.equals( other.timestamps )
&& sizes.equals( other.sizes );
} }
} }