-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathGroup.java
More file actions
102 lines (82 loc) · 2.28 KB
/
Group.java
File metadata and controls
102 lines (82 loc) · 2.28 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
* Copyright 2016-2023 Berry Cloud Ltd. All rights reserved.
*/
package dev.learning.xapi.model;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import dev.learning.xapi.model.validation.constraints.ValidActor;
import jakarta.validation.Valid;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import lombok.experimental.SuperBuilder;
/**
* This class represents the xAPI Group object.
*
* @author Thomas Turrell-Croft
*
* @see <a href="https://github.com/adlnet/xAPI-Spec/blob/master/xAPI-Data.md#group">xAPI Group</a>
*/
@Getter
@SuperBuilder
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class Group extends Actor {
/**
* The members of this Group.
*/
@Valid
@JsonFormat(without = {JsonFormat.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY})
private final List<@ValidActor Agent> member;
// **Warning** do not add fields that are not required by the xAPI specification.
/**
* Returns true if the group is anonymous.
*/
@JsonIgnore
public boolean isAnonymous() {
return account == null && mbox == null && mboxSha1sum == null && openid == null
&& member != null && !member.isEmpty();
}
/**
* Builder for Group.
*/
public abstract static class Builder<C extends Group, B extends Builder<C, B>>
extends Actor.Builder<C, B> {
// This static class extends the lombok builder.
/**
* Consumer Builder for member.
*
* @param member The Consumer Builder for member.
*
* @return This builder
*
* @see Group#member
*/
public Builder<C, B> addMember(Consumer<Agent.Builder<?, ?>> member) {
final Agent.Builder<?, ?> builder = Agent.builder();
member.accept(builder);
return addMember(builder.build());
}
/**
* Adds a member entry.
*
* @param agent The agent to add.
*
* @return This builder
*
* @see Group#member
*/
public Builder<C, B> addMember(Agent agent) {
if (member == null) {
member = new ArrayList<>();
}
member.add(agent);
return self();
}
}
}