1 | /** |
2 | * |
3 | * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com> |
4 | * |
5 | * ==================================================================== |
6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
7 | * you may not use this file except in compliance with the License. |
8 | * You may obtain a copy of the License at |
9 | * |
10 | * http://www.apache.org/licenses/LICENSE-2.0 |
11 | * |
12 | * Unless required by applicable law or agreed to in writing, software |
13 | * distributed under the License is distributed on an "AS IS" BASIS, |
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15 | * See the License for the specific language governing permissions and |
16 | * limitations under the License. |
17 | * ==================================================================== |
18 | */ |
19 | package org.jclouds.openstack.swift.domain.internal; |
20 | |
21 | import java.util.Arrays; |
22 | import java.util.Date; |
23 | |
24 | import org.jclouds.openstack.swift.domain.ObjectInfo; |
25 | |
26 | public class ObjectInfoImpl implements ObjectInfo { |
27 | String name; |
28 | byte[] hash; |
29 | long bytes; |
30 | String content_type; |
31 | Date last_modified; |
32 | |
33 | ObjectInfoImpl() { |
34 | |
35 | } |
36 | |
37 | public int compareTo(ObjectInfoImpl o) { |
38 | return (this == o) ? 0 : name.compareTo(o.name); |
39 | } |
40 | |
41 | public Long getBytes() { |
42 | return bytes; |
43 | } |
44 | |
45 | public String getContentType() { |
46 | return content_type; |
47 | } |
48 | |
49 | public byte[] getHash() { |
50 | return hash; |
51 | } |
52 | |
53 | public Date getLastModified() { |
54 | return last_modified; |
55 | } |
56 | |
57 | public String getName() { |
58 | return name; |
59 | } |
60 | |
61 | @Override |
62 | public int hashCode() { |
63 | final int prime = 31; |
64 | int result = 1; |
65 | result = prime * result + (int) (bytes ^ (bytes >>> 32)); |
66 | result = prime * result |
67 | + ((content_type == null) ? 0 : content_type.hashCode()); |
68 | result = prime * result + Arrays.hashCode(hash); |
69 | result = prime * result |
70 | + ((last_modified == null) ? 0 : last_modified.hashCode()); |
71 | result = prime * result + ((name == null) ? 0 : name.hashCode()); |
72 | return result; |
73 | } |
74 | |
75 | @Override |
76 | public boolean equals(Object obj) { |
77 | if (this == obj) |
78 | return true; |
79 | if (obj == null) |
80 | return false; |
81 | if (getClass() != obj.getClass()) |
82 | return false; |
83 | ObjectInfoImpl other = (ObjectInfoImpl) obj; |
84 | if (bytes != other.bytes) |
85 | return false; |
86 | if (content_type == null) { |
87 | if (other.content_type != null) |
88 | return false; |
89 | } else if (!content_type.equals(other.content_type)) |
90 | return false; |
91 | if (!Arrays.equals(hash, other.hash)) |
92 | return false; |
93 | if (last_modified == null) { |
94 | if (other.last_modified != null) |
95 | return false; |
96 | } else if (!last_modified.equals(other.last_modified)) |
97 | return false; |
98 | if (name == null) { |
99 | if (other.name != null) |
100 | return false; |
101 | } else if (!name.equals(other.name)) |
102 | return false; |
103 | return true; |
104 | } |
105 | |
106 | public int compareTo(ObjectInfo o) { |
107 | return (this == o) ? 0 : getName().compareTo(o.getName()); |
108 | } |
109 | |
110 | @Override |
111 | public String toString() { |
112 | return "ObjectInfoImpl [bytes=" + bytes + ", content_flavor=" |
113 | + content_type + ", hash=" + Arrays.asList(hash) |
114 | + ", last_modified=" + last_modified.getTime() + ", name=" + name |
115 | + "]"; |
116 | } |
117 | } |