View Javadoc
1   package org.apache.maven.wagon.resource;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.wagon.WagonConstants;
23  
24  /**
25   * Describes resources which can be downloaded from the repository
26   * or uploaded to repository.
27   * <p/>
28   * This class contains minimal set of informations, which
29   * are needed to reuse wagon in maven 1.
30   *
31   * @author <a href="michal@codehaus.org">Michal Maczka</a>
32   *
33   */
34  
35  public class Resource
36  {
37      private String name;
38  
39      private long lastModified;
40  
41      private long contentLength = WagonConstants.UNKNOWN_LENGTH;
42  
43      public Resource()
44      {
45  
46      }
47  
48      public Resource( String name )
49      {
50          this.name = name;
51      }
52  
53      public String getName()
54      {
55          return name;
56      }
57  
58      public void setName( String name )
59      {
60          this.name = name;
61      }
62  
63      /**
64       * Returns the value of the last-modified header field.
65       * The result is the number of milliseconds since January 1, 1970 GMT.
66       *
67       * @return the date the resource  was last modified, or WagonConstants.UNKNOWN_LENGTH
68       *         if not known.
69       */
70      public long getLastModified()
71      {
72          return lastModified;
73      }
74  
75      public void setLastModified( long lastModified )
76      {
77          this.lastModified = lastModified;
78      }
79  
80      public long getContentLength()
81      {
82          return contentLength;
83      }
84  
85      public void setContentLength( long contentLength )
86      {
87          this.contentLength = contentLength;
88      }
89  
90      public String toString()
91      {
92          return name;
93      }
94      
95      public String inspect()
96      {
97          return name + "[len = " + contentLength + "; mod = " + lastModified + "]";
98      }
99  
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 }