| 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.s3.domain.internal; |
| 20 | |
| 21 | import java.util.LinkedHashSet; |
| 22 | import java.util.Set; |
| 23 | |
| 24 | import org.jclouds.s3.domain.ListBucketResponse; |
| 25 | import org.jclouds.s3.domain.ObjectMetadata; |
| 26 | |
| 27 | import com.google.common.collect.Iterables; |
| 28 | |
| 29 | /** |
| 30 | * |
| 31 | * @author Adrian Cole |
| 32 | * |
| 33 | */ |
| 34 | public class ListBucketResponseImpl extends LinkedHashSet<ObjectMetadata> implements ListBucketResponse { |
| 35 | /** The serialVersionUID */ |
| 36 | private static final long serialVersionUID = -4475709781001190244L; |
| 37 | protected final String name; |
| 38 | protected final String prefix; |
| 39 | protected final int maxKeys; |
| 40 | protected final String delimiter; |
| 41 | protected final String marker; |
| 42 | protected final String nextMarker; |
| 43 | protected final Set<String> commonPrefixes; |
| 44 | protected final boolean truncated; |
| 45 | |
| 46 | public ListBucketResponseImpl(String name, Iterable<ObjectMetadata> contents, String prefix, String marker, |
| 47 | String nextMarker, int maxKeys, String delimiter, boolean isTruncated, Set<String> commonPrefixes) { |
| 48 | Iterables.addAll(this, contents); |
| 49 | this.name = name; |
| 50 | this.prefix = prefix; |
| 51 | this.marker = marker; |
| 52 | this.nextMarker = nextMarker; |
| 53 | this.maxKeys = maxKeys; |
| 54 | this.truncated = isTruncated; |
| 55 | this.delimiter = delimiter; |
| 56 | this.commonPrefixes = commonPrefixes; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * {@inheritDoc} |
| 61 | */ |
| 62 | @Override |
| 63 | public Set<String> getCommonPrefixes() { |
| 64 | return commonPrefixes; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * {@inheritDoc} |
| 69 | */ |
| 70 | @Override |
| 71 | public String getDelimiter() { |
| 72 | return delimiter; |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * {@inheritDoc} |
| 77 | */ |
| 78 | @Override |
| 79 | public String getMarker() { |
| 80 | return marker; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * {@inheritDoc} |
| 85 | */ |
| 86 | @Override |
| 87 | public String getNextMarker() { |
| 88 | return nextMarker; |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * {@inheritDoc} |
| 93 | */ |
| 94 | @Override |
| 95 | public int getMaxKeys() { |
| 96 | return maxKeys; |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * {@inheritDoc} |
| 101 | */ |
| 102 | @Override |
| 103 | public String getPrefix() { |
| 104 | return prefix; |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * {@inheritDoc} |
| 109 | */ |
| 110 | @Override |
| 111 | public boolean isTruncated() { |
| 112 | return truncated; |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * {@inheritDoc} |
| 117 | */ |
| 118 | @Override |
| 119 | public String getName() { |
| 120 | return name; |
| 121 | } |
| 122 | |
| 123 | @Override |
| 124 | public int hashCode() { |
| 125 | final int prime = 31; |
| 126 | int result = super.hashCode(); |
| 127 | result = prime * result + ((commonPrefixes == null) ? 0 : commonPrefixes.hashCode()); |
| 128 | result = prime * result + ((delimiter == null) ? 0 : delimiter.hashCode()); |
| 129 | result = prime * result + ((marker == null) ? 0 : marker.hashCode()); |
| 130 | result = prime * result + maxKeys; |
| 131 | result = prime * result + ((name == null) ? 0 : name.hashCode()); |
| 132 | result = prime * result + ((prefix == null) ? 0 : prefix.hashCode()); |
| 133 | result = prime * result + (truncated ? 1231 : 1237); |
| 134 | return result; |
| 135 | } |
| 136 | |
| 137 | @Override |
| 138 | public boolean equals(Object obj) { |
| 139 | if (this == obj) |
| 140 | return true; |
| 141 | if (!super.equals(obj)) |
| 142 | return false; |
| 143 | if (getClass() != obj.getClass()) |
| 144 | return false; |
| 145 | ListBucketResponseImpl other = (ListBucketResponseImpl) obj; |
| 146 | if (commonPrefixes == null) { |
| 147 | if (other.commonPrefixes != null) |
| 148 | return false; |
| 149 | } else if (!commonPrefixes.equals(other.commonPrefixes)) |
| 150 | return false; |
| 151 | if (delimiter == null) { |
| 152 | if (other.delimiter != null) |
| 153 | return false; |
| 154 | } else if (!delimiter.equals(other.delimiter)) |
| 155 | return false; |
| 156 | if (marker == null) { |
| 157 | if (other.marker != null) |
| 158 | return false; |
| 159 | } else if (!marker.equals(other.marker)) |
| 160 | return false; |
| 161 | if (maxKeys != other.maxKeys) |
| 162 | return false; |
| 163 | if (name == null) { |
| 164 | if (other.name != null) |
| 165 | return false; |
| 166 | } else if (!name.equals(other.name)) |
| 167 | return false; |
| 168 | if (prefix == null) { |
| 169 | if (other.prefix != null) |
| 170 | return false; |
| 171 | } else if (!prefix.equals(other.prefix)) |
| 172 | return false; |
| 173 | if (truncated != other.truncated) |
| 174 | return false; |
| 175 | return true; |
| 176 | } |
| 177 | |
| 178 | } |