Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

finish 组合 #233

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions src/main/java/com/github/hcsp/inheritance/CountingSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,33 @@
import java.util.Collection;
import java.util.HashSet;

public class CountingSet extends HashSet<Object> {
/** 统计"有史以来"向该集合中添加过的元素个数 */
public class CountingSet {
/**
* 统计"有史以来"向该集合中添加过的元素个数
*/
HashSet<Object> 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() {
Expand Down