| 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.blobstore.domain.internal; |
| 20 | |
| 21 | import java.util.LinkedHashSet; |
| 22 | |
| 23 | import org.jclouds.javax.annotation.Nullable; |
| 24 | |
| 25 | import org.jclouds.blobstore.domain.PageSet; |
| 26 | |
| 27 | import com.google.common.collect.Iterables; |
| 28 | |
| 29 | public class PageSetImpl<T> extends LinkedHashSet<T> implements PageSet<T> { |
| 30 | |
| 31 | /** The serialVersionUID */ |
| 32 | private static final long serialVersionUID = -7133632087734650835L; |
| 33 | protected final String marker; |
| 34 | |
| 35 | public PageSetImpl(Iterable<? extends T> contents, @Nullable String nextMarker) { |
| 36 | Iterables.addAll(this, contents); |
| 37 | this.marker = nextMarker; |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * {@inheritDoc} |
| 42 | */ |
| 43 | @Override |
| 44 | public String getNextMarker() { |
| 45 | return marker; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * {@inheritDoc} |
| 50 | */ |
| 51 | @Override |
| 52 | public int hashCode() { |
| 53 | final int prime = 31; |
| 54 | int result = super.hashCode(); |
| 55 | result = prime * result + ((marker == null) ? 0 : marker.hashCode()); |
| 56 | return result; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * {@inheritDoc} |
| 61 | */ |
| 62 | @Override |
| 63 | public boolean equals(Object obj) { |
| 64 | if (this == obj) |
| 65 | return true; |
| 66 | if (!super.equals(obj)) |
| 67 | return false; |
| 68 | if (getClass() != obj.getClass()) |
| 69 | return false; |
| 70 | PageSetImpl<?> other = (PageSetImpl<?>) obj; |
| 71 | if (marker == null) { |
| 72 | if (other.marker != null) |
| 73 | return false; |
| 74 | } else if (!marker.equals(other.marker)) |
| 75 | return false; |
| 76 | return true; |
| 77 | } |
| 78 | |
| 79 | } |