Package: ModelBuilder
ModelBuilder
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ModelBuilder(Resource[]) |
|
|
|
|
|
||||||||||||||||||||
lambda$with$0(Resource, IRI, Resource[], Value) |
|
|
|
|
|
||||||||||||||||||||
lambda$with$4(IRI, Value, Resource) |
|
|
|
|
|
||||||||||||||||||||
lambda$with$5(Resource, IRI, Value) |
|
|
|
|
|
||||||||||||||||||||
lambda$with$7(Model) |
|
|
|
|
|
||||||||||||||||||||
lambda$withOptional$1(IRI, Value, Resource) |
|
|
|
|
|
||||||||||||||||||||
lambda$withOptional$2(Resource, IRI, Value) |
|
|
|
|
|
||||||||||||||||||||
lambda$withOptional$3(Optional, IRI, Value) |
|
|
|
|
|
||||||||||||||||||||
lambda$withOptional$6(Optional, IRI, Value) |
|
|
|
|
|
||||||||||||||||||||
static {...} |
|
|
|
|
|
||||||||||||||||||||
toModel() |
|
|
|
|
|
||||||||||||||||||||
with(List) |
|
|
|
|
|
||||||||||||||||||||
with(List, IRI, List) |
|
|
|
|
|
||||||||||||||||||||
with(List, IRI, Value) |
|
|
|
|
|
||||||||||||||||||||
with(Model) |
|
|
|
|
|
||||||||||||||||||||
with(ModelBuilder) |
|
|
|
|
|
||||||||||||||||||||
with(Optional) |
|
|
|
|
|
||||||||||||||||||||
with(Resource, IRI, Optional, Resource[]) |
|
|
|
|
|
||||||||||||||||||||
with(Resource, IRI, Stream) |
|
|
|
|
|
||||||||||||||||||||
with(Resource, IRI, Value, Resource[]) |
|
|
|
|
|
||||||||||||||||||||
with(Statement) |
|
|
|
|
|
||||||||||||||||||||
withOptional(Optional, IRI, Optional) |
|
|
|
|
|
||||||||||||||||||||
withOptional(Optional, IRI, Stream) |
|
|
|
|
|
||||||||||||||||||||
withOptional(Optional, IRI, Value) |
|
|
|
|
|
||||||||||||||||||||
withOptional(Resource, IRI, Optional) |
|
|
|
|
|
Coverage
1: /*
2: * *********************************************************************************************************************
3: *
4: * blueMarine II: Semantic Media Centre
5: * http://tidalwave.it/projects/bluemarine2
6: *
7: * Copyright (C) 2015 - 2021 by Tidalwave s.a.s. (http://tidalwave.it)
8: *
9: * *********************************************************************************************************************
10: *
11: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
12: * the License. You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
17: * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations under the License.
19: *
20: * *********************************************************************************************************************
21: *
22: * git clone https://bitbucket.org/tidalwave/bluemarine2-src
23: * git clone https://github.com/tidalwave-it/bluemarine2-src
24: *
25: * *********************************************************************************************************************
26: */
27: package it.tidalwave.bluemarine2.util;
28:
29: import javax.annotation.Nonnull;
30: import javax.annotation.concurrent.ThreadSafe;
31: import java.util.List;
32: import java.util.Optional;
33: import java.util.stream.Stream;
34: import org.eclipse.rdf4j.model.IRI;
35: import org.eclipse.rdf4j.model.Model;
36: import org.eclipse.rdf4j.model.Resource;
37: import org.eclipse.rdf4j.model.Statement;
38: import org.eclipse.rdf4j.model.Value;
39: import org.eclipse.rdf4j.model.impl.TreeModel;
40:
41: /***********************************************************************************************************************
42: *
43: * Unlike the similar class in RDF4J, this is thread-safe and can merge to similar objects.
44: *
45: * @author Fabrizio Giudici
46: *
47: **********************************************************************************************************************/
48: @ThreadSafe
49: public class ModelBuilder
50: {
51: private final Model model = new TreeModel();
52:
53: @Nonnull private final Resource[] contexts;
54:
55: /*******************************************************************************************************************
56: *
57: *
58: *
59: ******************************************************************************************************************/
60: public ModelBuilder (@Nonnull final Resource ... contexts)
61: {
62: this.contexts = contexts;
63: }
64:
65: /*******************************************************************************************************************
66: *
67: *
68: *
69: ******************************************************************************************************************/
70: @Nonnull
71: public synchronized Model toModel()
72: {
73: return new TreeModel(model);
74: }
75:
76: /*******************************************************************************************************************
77: *
78: *
79: *
80: ******************************************************************************************************************/
81: @Nonnull
82: public synchronized ModelBuilder with (@Nonnull final Resource subject,
83: @Nonnull final IRI predicate,
84: @Nonnull final Value object,
85: @Nonnull final Resource... contexts)
86: {
87: model.add(subject, predicate, object, contexts);
88: return this;
89: }
90:
91: /*******************************************************************************************************************
92: *
93: *
94: *
95: ******************************************************************************************************************/
96: @Nonnull
97: public synchronized ModelBuilder with (@Nonnull final Resource subjext,
98: @Nonnull final IRI predicate,
99: @Nonnull final Optional<Value> optionalObject,
100: @Nonnull final Resource... contexts)
101: {
102: return optionalObject.map(object -> ModelBuilder.this.with(subjext, predicate, object, contexts)).orElse(this);
103: }
104:
105: /*******************************************************************************************************************
106: *
107: *
108: *
109: ******************************************************************************************************************/
110: @Nonnull
111: public synchronized ModelBuilder withOptional (@Nonnull final Optional<? extends Resource> optionalSubject,
112: @Nonnull final IRI predicate,
113: @Nonnull final Value object)
114: {
115: return optionalSubject.map(subject -> ModelBuilder.this.with(subject, predicate, object)).orElse(this);
116: }
117:
118: /*******************************************************************************************************************
119: *
120: *
121: *
122: ******************************************************************************************************************/
123: @Nonnull
124: public synchronized ModelBuilder withOptional (@Nonnull final Resource subject,
125: @Nonnull final IRI predicate,
126: @Nonnull final Optional<? extends Value> optionalObject)
127: {
128: return optionalObject.map(object -> ModelBuilder.this.with(subject, predicate, object)).orElse(this);
129: }
130:
131: /*******************************************************************************************************************
132: *
133: *
134: *
135: ******************************************************************************************************************/
136: @Nonnull
137: public synchronized ModelBuilder withOptional (@Nonnull final Optional<? extends Resource> optionalSubject,
138: @Nonnull final IRI predicate,
139: @Nonnull final Optional<? extends Value> optionalObject)
140: {
141: return optionalObject.map(object -> withOptional(optionalSubject, predicate, object)).orElse(this);
142: }
143:
144: /*******************************************************************************************************************
145: *
146: *
147: *
148: ******************************************************************************************************************/
149: @Nonnull
150: public synchronized ModelBuilder with (@Nonnull final List<? extends Resource> subjects,
151: @Nonnull final IRI predicate,
152: @Nonnull final Value object)
153: {
154: subjects.forEach(subject -> ModelBuilder.this.with(subject, predicate, object)); // FIXME ?? this = withOptional(...)
155: return this;
156: }
157:
158: /*******************************************************************************************************************
159: *
160: *
161: *
162: ******************************************************************************************************************/
163: @Nonnull
164: public synchronized ModelBuilder with (@Nonnull final List<? extends Resource> subjects,
165: @Nonnull final IRI predicate,
166: @Nonnull final List<? extends Value> objects)
167: {
168:• assert subjects.size() == objects.size();
169:
170:• for (int i = 0; i < subjects.size(); i++)
171: {
172: ModelBuilder.this.with(subjects.get(i), predicate, objects.get(i)); // FIXME ?? this = withOptional(...)
173: }
174:
175: return this;
176: }
177:
178: /*******************************************************************************************************************
179: *
180: *
181: *
182: ******************************************************************************************************************/
183: @Nonnull
184: public synchronized ModelBuilder with (@Nonnull final Resource subject,
185: @Nonnull final IRI predicate,
186: @Nonnull final Stream<? extends Value> objects)
187: {
188: objects.forEach(object -> ModelBuilder.this.with(subject, predicate, object)); // FIXME ?? this = withOptional(...)
189: return this;
190: }
191:
192: /*******************************************************************************************************************
193: *
194: *
195: *
196: ******************************************************************************************************************/
197: @Nonnull
198: public synchronized ModelBuilder withOptional (@Nonnull final Optional<? extends Resource> subject,
199: @Nonnull final IRI predicate,
200: @Nonnull final Stream<? extends Value> objects)
201: {
202:• if (subject.isPresent())
203: {
204: objects.forEach(object -> withOptional(subject, predicate, object)); // FIXME ?? this = withOptional(...)
205: }
206:
207: return this;
208: }
209:
210: /*******************************************************************************************************************
211: *
212: *
213: *
214: ******************************************************************************************************************/
215: @Nonnull
216: public synchronized ModelBuilder with (@Nonnull final Statement statement)
217: {
218: model.add(statement);
219: return this;
220: }
221:
222: /*******************************************************************************************************************
223: *
224: *
225: *
226: ******************************************************************************************************************/
227: @Nonnull
228: public synchronized ModelBuilder with (@Nonnull final Optional<ModelBuilder> optionalBuiilder)
229: {
230: optionalBuiilder.ifPresent(ModelBuilder.this::with);
231: return this;
232: }
233:
234: /*******************************************************************************************************************
235: *
236: *
237: *
238: ******************************************************************************************************************/
239: @Nonnull
240: public synchronized ModelBuilder with (@Nonnull final ModelBuilder other)
241: {
242: return ModelBuilder.this.with(other.toModel());
243: }
244:
245: /*******************************************************************************************************************
246: *
247: *
248: *
249: ******************************************************************************************************************/
250: @Nonnull
251: public synchronized ModelBuilder with (@Nonnull final Model other)
252: {
253: other.forEach(model::add);
254: return this;
255: }
256:
257: /*******************************************************************************************************************
258: *
259: *
260: *
261: ******************************************************************************************************************/
262: @Nonnull
263: public synchronized ModelBuilder with (@Nonnull final List<ModelBuilder> others)
264: {
265: others.stream().map(ModelBuilder::toModel).forEach(m -> m.forEach(model::add));
266: return this;
267: }
268: }