From 533d488192723aca693cb8800dfd4b6b4cd51e5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E9=AA=8F=E6=9D=B0?= Date: Tue, 28 Sep 2021 15:10:36 +0800 Subject: [PATCH] =?UTF-8?q?finish=20=E7=BB=84=E5=90=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../github/hcsp/inheritance/CountingSet.java | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/github/hcsp/inheritance/CountingSet.java b/src/main/java/com/github/hcsp/inheritance/CountingSet.java index 9311eaf..a524fff 100644 --- a/src/main/java/com/github/hcsp/inheritance/CountingSet.java +++ b/src/main/java/com/github/hcsp/inheritance/CountingSet.java @@ -4,20 +4,33 @@ import java.util.Collection; import java.util.HashSet; -public class CountingSet extends HashSet { - /** 统计"有史以来"向该集合中添加过的元素个数 */ +public class CountingSet { + /** + * 统计"有史以来"向该集合中添加过的元素个数 + */ + HashSet set = new HashSet<>(); private int count = 0; - @Override + public boolean remove(Object obj) { + return set.remove(obj); + } + public boolean add(Object obj) { count++; - return super.add(obj); + return set.add(obj); } - @Override public boolean addAll(Collection c) { count += c.size(); - return super.addAll(c); + return set.addAll(c); + } + + public int size() { + return set.size(); + } + + public Boolean removeAll(Collection c) { + return set.removeAll(c); } public int getCount() {