1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.queryable.collections; 18 19 import com.android.queryable.queries.Query; 20 21 import java.util.Collection; 22 import java.util.HashSet; 23 import java.util.Iterator; 24 import java.util.Set; 25 26 /** 27 * Implementation of {@link QueryableSet}. 28 */ 29 public abstract class QueryableHashSet<E, F extends Query<E>, G extends QueryableSet<E, F, ?>> implements QueryableSet<E, F, G> { 30 31 protected Set<E> mSet = new HashSet<>(); 32 QueryableHashSet()33 public QueryableHashSet() { 34 35 } 36 QueryableHashSet(Set<E> existingSet)37 public QueryableHashSet(Set<E> existingSet) { 38 mSet.addAll(existingSet); 39 } 40 41 @Override size()42 public int size() { 43 return mSet.size(); 44 } 45 46 @Override isEmpty()47 public boolean isEmpty() { 48 return mSet.isEmpty(); 49 } 50 51 @Override contains(Object o)52 public boolean contains(Object o) { 53 return mSet.contains(o); 54 } 55 56 @Override iterator()57 public Iterator<E> iterator() { 58 return mSet.iterator(); 59 } 60 61 @Override toArray()62 public Object[] toArray() { 63 return mSet.toArray(); 64 } 65 66 @Override toArray(T[] a)67 public <T> T[] toArray(T[] a) { 68 return mSet.toArray(a); 69 } 70 71 @Override add(E e)72 public boolean add(E e) { 73 return mSet.add(e); 74 } 75 76 @Override remove(Object o)77 public boolean remove(Object o) { 78 return mSet.remove(o); 79 } 80 81 @Override containsAll(Collection<?> c)82 public boolean containsAll(Collection<?> c) { 83 return mSet.containsAll(c); 84 } 85 86 @Override addAll(Collection<? extends E> c)87 public boolean addAll(Collection<? extends E> c) { 88 return mSet.addAll(c); 89 } 90 91 @Override retainAll(Collection<?> c)92 public boolean retainAll(Collection<?> c) { 93 return mSet.retainAll(c); 94 } 95 96 @Override removeAll(Collection<?> c)97 public boolean removeAll(Collection<?> c) { 98 return mSet.removeAll(c); 99 } 100 101 @Override clear()102 public void clear() { 103 mSet.clear(); 104 } 105 } 106