-
Notifications
You must be signed in to change notification settings - Fork 276
Expand file tree
/
Copy pathSetBag.java
More file actions
42 lines (32 loc) · 835 Bytes
/
SetBag.java
File metadata and controls
42 lines (32 loc) · 835 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package io.github.dddplus.model;
import lombok.NonNull;
import java.util.Set;
/**
* SetBag is a handy memory Set based {@link IBag}.
*
* @param <Entity> The entity type
*/
public abstract class SetBag<Entity> implements IBag {
protected final Set<Entity> items;
protected SetBag(@NonNull Set<Entity> items) {
this.items = items;
}
public final int size() {
return items.size();
}
public final Set<Entity> items() {
return items;
}
public final boolean isEmpty() {
return size() == 0;
}
/**
* 返回任意一个对象:在与具体对象无关场景使用.
*/
public final Entity anyOne() {
return items.iterator().next();
}
public final boolean contains(Entity entity) {
return items.contains(entity);
}
}