1 /*
2 * Copyright 2020-2022 Foreseeti AB <https://foreseeti.com>
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package org.mal_lang.langspec.builders.step;
18
19 import static java.util.Objects.requireNonNull;
20
21 import jakarta.json.JsonObject;
22 import java.util.List;
23 import java.util.Map;
24 import org.mal_lang.langspec.Asset;
25 import org.mal_lang.langspec.builders.AssetBuilder;
26
27 /**
28 * A builder for creating {@link org.mal_lang.langspec.step.StepTransitive} objects.
29 *
30 * @since 1.0.0
31 */
32 public final class StepTransitiveBuilder extends StepExpressionBuilder {
33 private final StepExpressionBuilder stepExpression;
34
35 /**
36 * Constructs a new {@code StepTransitiveBuilder} object.
37 *
38 * @param stepExpression the step expression of the transitive step
39 * @throws java.lang.NullPointerException if {@code stepExpression} is {@code null}
40 * @since 1.0.0
41 */
42 public StepTransitiveBuilder(StepExpressionBuilder stepExpression) {
43 this.stepExpression = requireNonNull(stepExpression);
44 }
45
46 /**
47 * Returns the step expression of this {@code StepTransitiveBuilder} object.
48 *
49 * @return the step expression of this {@code StepTransitiveBuilder} object
50 * @since 1.0.0
51 */
52 public StepExpressionBuilder getStepExpression() {
53 return this.stepExpression;
54 }
55
56 @Override
57 public Asset getTarget(
58 Asset sourceAsset, Map<String, Asset> assets, List<AssetBuilder> assetBuilders) {
59 return sourceAsset;
60 }
61
62 /**
63 * Creates a new {@code StepTransitiveBuilder} from a {@link jakarta.json.JsonObject}.
64 *
65 * @param jsonStepTransitive the {@link jakarta.json.JsonObject}
66 * @return a new {@code StepTransitiveBuilder}
67 * @throws java.lang.NullPointerException if {@code jsonStepTransitive} is {@code null}
68 * @since 1.0.0
69 */
70 public static StepTransitiveBuilder fromJson(JsonObject jsonStepTransitive) {
71 requireNonNull(jsonStepTransitive);
72 var stepExpression =
73 StepExpressionBuilder.fromJson(jsonStepTransitive.getJsonObject("stepExpression"));
74 return new StepTransitiveBuilder(stepExpression);
75 }
76 }