| 1 | /** |
| 2 | * Licensed to jclouds, Inc. (jclouds) under one or more |
| 3 | * contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. jclouds licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. 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, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | package org.jclouds.openstack.swift.domain.internal; |
| 20 | |
| 21 | import java.net.URI; |
| 22 | import java.util.Arrays; |
| 23 | import java.util.Date; |
| 24 | import java.util.Map; |
| 25 | |
| 26 | import javax.ws.rs.core.MediaType; |
| 27 | |
| 28 | import org.jclouds.openstack.swift.domain.MutableObjectInfoWithMetadata; |
| 29 | import org.jclouds.openstack.swift.domain.ObjectInfo; |
| 30 | |
| 31 | import com.google.common.collect.Maps; |
| 32 | |
| 33 | /** |
| 34 | * |
| 35 | * @author Adrian Cole |
| 36 | * |
| 37 | */ |
| 38 | public class MutableObjectInfoWithMetadataImpl implements MutableObjectInfoWithMetadata { |
| 39 | private String name; |
| 40 | private String container; |
| 41 | private URI uri; |
| 42 | private Long bytes; |
| 43 | private byte[] hash; |
| 44 | private String contentType = MediaType.APPLICATION_OCTET_STREAM; |
| 45 | private Date lastModified; |
| 46 | private final Map<String, String> metadata = Maps.newLinkedHashMap(); |
| 47 | |
| 48 | /** |
| 49 | * {@inheritDoc} |
| 50 | */ |
| 51 | @Override |
| 52 | public Map<String, String> getMetadata() { |
| 53 | return metadata; |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * {@inheritDoc} |
| 58 | */ |
| 59 | @Override |
| 60 | public void setBytes(Long bytes) { |
| 61 | this.bytes = bytes; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * {@inheritDoc} |
| 66 | */ |
| 67 | @Override |
| 68 | public void setContentType(String contentType) { |
| 69 | this.contentType = contentType; |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * {@inheritDoc} |
| 74 | */ |
| 75 | @Override |
| 76 | public void setHash(byte[] hash) { |
| 77 | this.hash = hash; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * {@inheritDoc} |
| 82 | */ |
| 83 | @Override |
| 84 | public void setName(String name) { |
| 85 | this.name = name; |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * {@inheritDoc} |
| 90 | */ |
| 91 | @Override |
| 92 | public Long getBytes() { |
| 93 | return bytes; |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * {@inheritDoc} |
| 98 | */ |
| 99 | @Override |
| 100 | public String getContentType() { |
| 101 | return contentType; |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * {@inheritDoc} |
| 106 | */ |
| 107 | @Override |
| 108 | public byte[] getHash() { |
| 109 | return hash; |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * {@inheritDoc} |
| 114 | */ |
| 115 | @Override |
| 116 | public Date getLastModified() { |
| 117 | return lastModified; |
| 118 | } |
| 119 | |
| 120 | @Override |
| 121 | public int hashCode() { |
| 122 | final int prime = 31; |
| 123 | int result = 1; |
| 124 | result = prime * result + ((container == null) ? 0 : container.hashCode()); |
| 125 | result = prime * result + ((name == null) ? 0 : name.hashCode()); |
| 126 | return result; |
| 127 | } |
| 128 | |
| 129 | @Override |
| 130 | public boolean equals(Object obj) { |
| 131 | if (this == obj) |
| 132 | return true; |
| 133 | if (obj == null) |
| 134 | return false; |
| 135 | if (getClass() != obj.getClass()) |
| 136 | return false; |
| 137 | MutableObjectInfoWithMetadataImpl other = (MutableObjectInfoWithMetadataImpl) obj; |
| 138 | if (container == null) { |
| 139 | if (other.container != null) |
| 140 | return false; |
| 141 | } else if (!container.equals(other.container)) |
| 142 | return false; |
| 143 | if (name == null) { |
| 144 | if (other.name != null) |
| 145 | return false; |
| 146 | } else if (!name.equals(other.name)) |
| 147 | return false; |
| 148 | return true; |
| 149 | } |
| 150 | |
| 151 | /** |
| 152 | * {@inheritDoc} |
| 153 | */ |
| 154 | @Override |
| 155 | public String getName() { |
| 156 | return name; |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * {@inheritDoc} |
| 161 | */ |
| 162 | @Override |
| 163 | public int compareTo(ObjectInfo o) { |
| 164 | return (this == o) ? 0 : getName().compareTo(o.getName()); |
| 165 | } |
| 166 | |
| 167 | /** |
| 168 | * {@inheritDoc} |
| 169 | */ |
| 170 | @Override |
| 171 | public void setLastModified(Date lastModified) { |
| 172 | this.lastModified = lastModified; |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * {@inheritDoc} |
| 177 | */ |
| 178 | @Override |
| 179 | public String getContainer() { |
| 180 | return container; |
| 181 | } |
| 182 | |
| 183 | /** |
| 184 | * {@inheritDoc} |
| 185 | */ |
| 186 | @Override |
| 187 | public void setContainer(String container) { |
| 188 | this.container = container; |
| 189 | } |
| 190 | |
| 191 | @Override |
| 192 | public void setUri(URI uri) { |
| 193 | this.uri = uri; |
| 194 | } |
| 195 | |
| 196 | @Override |
| 197 | public URI getUri() { |
| 198 | return uri; |
| 199 | } |
| 200 | |
| 201 | @Override |
| 202 | public String toString() { |
| 203 | return String.format("[name=%s, container=%s, uri=%s, bytes=%s, contentType=%s, lastModified=%s, hash=%s]", name, |
| 204 | container, uri, bytes, contentType, lastModified, Arrays.toString(hash)); |
| 205 | } |
| 206 | |
| 207 | } |