-
Notifications
You must be signed in to change notification settings - Fork 215
/
PolicyImports.java
150 lines (133 loc) · 5.51 KB
/
PolicyImports.java
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.ditto.policies.model;
import java.util.Optional;
import java.util.stream.Stream;
import org.eclipse.ditto.base.model.json.FieldType;
import org.eclipse.ditto.base.model.json.JsonSchemaVersion;
import org.eclipse.ditto.base.model.json.Jsonifiable;
import org.eclipse.ditto.json.JsonField;
import org.eclipse.ditto.json.JsonFieldSelector;
import org.eclipse.ditto.json.JsonObject;
/**
* A collection of {@link PolicyImport}s contained in a {@link Policy}.
*
* @since 3.x.0 TODO ditto#298
*/
public interface PolicyImports extends Iterable<PolicyImport>, Jsonifiable.WithFieldSelectorAndPredicate<JsonField> {
/**
* Returns a new {@code PolicyImports} containing no policyImports.
*
* @return the new {@code PolicyImports}.
*/
static PolicyImports emptyInstance() {
return PoliciesModelFactory.emptyPolicyImports();
}
/**
* Returns a new {@code PolicyImports} containing the given policyImports.
*
* @param policyImports the {@link PolicyImport}s to be contained in the new PolicyImports.
* @return the new {@code PolicyImports}.
* @throws NullPointerException if {@code policyImports} is {@code null}.
*/
static PolicyImports newInstance(final Iterable<PolicyImport> policyImports) {
return PoliciesModelFactory.newPolicyImports(policyImports);
}
/**
* Returns a new {@code PolicyImports} containing the given policyImport.
*
* @param policyImport the {@link PolicyImport} to be contained in the new PolicyImports.
* @param furtherPolicyImports further {@link PolicyImport}s to be contained in the new PolicyImports.
* @return the new {@code PolicyImports}.
* @throws NullPointerException if any argument is {@code null}.
*/
static PolicyImports newInstance(final PolicyImport policyImport, final PolicyImport... furtherPolicyImports) {
return PoliciesModelFactory.newPolicyImports(policyImport, furtherPolicyImports);
}
/**
* Returns the supported JSON schema version of this resources. <em>PolicyImports support only
* {@link JsonSchemaVersion#V_2}.</em>
*
* @return the supported schema version.
*/
@Override
default JsonSchemaVersion[] getSupportedSchemaVersions() {
return new JsonSchemaVersion[]{JsonSchemaVersion.V_2};
}
/**
* Returns the PolicyImport with the given {@code importedPolicyId} or an empty optional.
*
* @param importedPolicyId the path of the PolicyImport to be retrieved.
* @return the PolicyImport or an empty optional.
* @throws NullPointerException if {@code importedPolicyId} is {@code null}.
* @throws IllegalArgumentException if {@code importedPolicyId} is empty.
*/
Optional<PolicyImport> getPolicyImport(CharSequence importedPolicyId);
/**
* Sets the given PolicyImport to a copy of this PolicyImports. A previous PolicyImport with the same identifier will be
* overwritten.
*
* @param policyImport the PolicyImport to be set.
* @return a copy of this PolicyImports with {@code policyImport} set.
* @throws NullPointerException if {@code policyImport} is {@code null}.
*/
PolicyImports setPolicyImport(PolicyImport policyImport);
/**
* Merges all given policyImports with self into a copy of this policy. A previous PolicyImport with the same identifier will be
* overwritten.
*
* @param policyImports the PolicyImports to be set.
* @return a copy of this PolicyImports with {@code policyImport} set.
* @throws NullPointerException if {@code policyImport} is {@code null}.
*/
PolicyImports setPolicyImports(PolicyImports policyImports);
/**
* Removes the PolicyImport with the given imported Policy ID.
*
* @param importedPolicyId the Policy ID identifying the PolicyImport to remove.
* @return a copy of this PolicyImports with {@code importedPolicyId} removed.
* @throws NullPointerException if {@code importedPolicyId} is {@code null}.
*/
PolicyImports removePolicyImport(CharSequence importedPolicyId);
/**
* Returns the size of this PolicyImports, i.e. the number of contained values.
*
* @return the size.
*/
int getSize();
/**
* Indicates whether this PolicyImports is empty.
*
* @return {@code true} if this PolicyImports does not contain any values, {@code false} else.
*/
boolean isEmpty();
/**
* Returns a sequential {@code Stream} with the values of this PolicyImports as its source.
*
* @return a sequential stream of the PolicyImports of this container.
*/
Stream<PolicyImport> stream();
/**
* Returns all non hidden marked fields of this PolicyImports.
*
* @return a JSON object representation of this PolicyImports including only non hidden marked fields.
*/
@Override
default JsonObject toJson() {
return toJson(FieldType.notHidden());
}
@Override
default JsonObject toJson(final JsonSchemaVersion schemaVersion, final JsonFieldSelector fieldSelector) {
return toJson(schemaVersion, FieldType.regularOrSpecial()).get(fieldSelector);
}
}