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;
18
19 import static java.util.Objects.requireNonNull;
20
21 /**
22 * Immutable class representing a field of an asset in a MAL language.
23 *
24 * @since 1.0.0
25 */
26 public final class Field {
27 private final String name;
28 private final Asset asset;
29 private final Multiplicity multiplicity;
30 private Field target;
31 private Association association;
32
33 Field(String name, Asset asset, Multiplicity multiplicity) {
34 this.name = requireNonNull(name);
35 this.asset = requireNonNull(asset);
36 this.multiplicity = requireNonNull(multiplicity);
37 asset.addField(this);
38 }
39
40 /**
41 * Returns the name of this {@code Field} object.
42 *
43 * @return the name of this {@code Field} object
44 * @since 1.0.0
45 */
46 public String getName() {
47 return this.name;
48 }
49
50 /**
51 * Returns the asset of this {@code Field} object.
52 *
53 * @return the asset of this {@code Field} object
54 * @since 1.0.0
55 */
56 public Asset getAsset() {
57 return this.asset;
58 }
59
60 /**
61 * Returns the multiplicity of this {@code Field} object.
62 *
63 * @return the multiplicity of this {@code Field} object
64 * @since 1.0.0
65 */
66 public Multiplicity getMultiplicity() {
67 return this.multiplicity;
68 }
69
70 /**
71 * Returns the target of this {@code Field} object.
72 *
73 * @return the target of this {@code Field} object
74 * @since 1.0.0
75 */
76 public Field getTarget() {
77 return this.target;
78 }
79
80 void setTarget(Field target) {
81 this.target = requireNonNull(target);
82 }
83
84 /**
85 * Returns the association of this {@code Field} object.
86 *
87 * @return the association of this {@code Field} object
88 * @since 1.0.0
89 */
90 public Association getAssociation() {
91 return this.association;
92 }
93
94 void setAssociation(Association association) {
95 this.association = requireNonNull(association);
96 }
97 }