001package org.apache.maven.wagon.resource; 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 org.apache.maven.wagon.WagonConstants; 023 024/** 025 * Describes resources which can be downloaded from the repository 026 * or uploaded to repository. 027 * <p/> 028 * This class contains minimal set of informations, which 029 * are needed to reuse wagon in maven 1. 030 * 031 * @author <a href="michal@codehaus.org">Michal Maczka</a> 032 * 033 */ 034 035public class Resource 036{ 037 private String name; 038 039 private long lastModified; 040 041 private long contentLength = WagonConstants.UNKNOWN_LENGTH; 042 043 public Resource() 044 { 045 046 } 047 048 public Resource( String name ) 049 { 050 this.name = name; 051 } 052 053 public String getName() 054 { 055 return name; 056 } 057 058 public void setName( String name ) 059 { 060 this.name = name; 061 } 062 063 /** 064 * Returns the value of the last-modified header field. 065 * The result is the number of milliseconds since January 1, 1970 GMT. 066 * 067 * @return the date the resource was last modified, or WagonConstants.UNKNOWN_LENGTH 068 * if not known. 069 */ 070 public long getLastModified() 071 { 072 return lastModified; 073 } 074 075 public void setLastModified( long lastModified ) 076 { 077 this.lastModified = lastModified; 078 } 079 080 public long getContentLength() 081 { 082 return contentLength; 083 } 084 085 public void setContentLength( long contentLength ) 086 { 087 this.contentLength = contentLength; 088 } 089 090 public String toString() 091 { 092 return name; 093 } 094 095 public String inspect() 096 { 097 return name + "[len = " + contentLength + "; mod = " + lastModified + "]"; 098 } 099 100 public int hashCode() 101 { 102 final int prime = 31; 103 int result = 1; 104 result = prime * result + (int) ( contentLength ^ ( contentLength >>> 32 ) ); 105 result = prime * result + (int) ( lastModified ^ ( lastModified >>> 32 ) ); 106 result = prime * result + ( ( name == null ) ? 0 : name.hashCode() ); 107 return result; 108 } 109 110 public boolean equals( Object obj ) 111 { 112 if ( this == obj ) 113 { 114 return true; 115 } 116 if ( obj == null ) 117 { 118 return false; 119 } 120 if ( getClass() != obj.getClass() ) 121 { 122 return false; 123 } 124 final Resource other = (Resource) obj; 125 if ( contentLength != other.contentLength ) 126 { 127 return false; 128 } 129 if ( lastModified != other.lastModified ) 130 { 131 return false; 132 } 133 if ( name == null ) 134 { 135 if ( other.name != null ) 136 { 137 return false; 138 } 139 } 140 else if ( !name.equals( other.name ) ) 141 { 142 return false; 143 } 144 return true; 145 } 146}