77import org .lfenergy .compas .scl2007b4 .model .TDAI ;
88import org .lfenergy .compas .scl2007b4 .model .TDOI ;
99import org .lfenergy .compas .scl2007b4 .model .TPrivate ;
10- import org .lfenergy .compas .scl2007b4 .model .TVal ;
1110import org .lfenergy .compas .sct .commons .exception .ScdException ;
1211import org .lfenergy .compas .sct .commons .scl .SclElementAdapter ;
1312import org .lfenergy .compas .sct .commons .util .CommonConstants ;
1413
1514import java .util .Map ;
1615
16+ import static org .lfenergy .compas .sct .commons .util .SclConstructorHelper .newVal ;
17+
1718/**
1819 * A representation of the model object
1920 * <em><b>{@link org.lfenergy.compas.sct.commons.scl.ied.AbstractDAIAdapter AbstractDAIAdapter}</b></em>.
2021 * <p>
2122 * The following features are supported:
2223 * </p>
2324 * <ol>
24- * <li>Adapter</li>
25- * <ul>
26- * <li>{@link AbstractDAIAdapter#getStructuredDataAdapterByName(String) <em>Returns the value of the <b>Child Adapter </b>object reference</em>}</li>
27- * <li>{@link AbstractDAIAdapter#getDataAdapterByName(String) <em>Returns the value of the <b>Child Adapter </b>object reference By Name</em>}</li>
28- * </ul>
2925 * <li>Principal functions</li>
3026 * <ul>
31- * <li>{@link AbstractDAIAdapter#addDAI(String) <em>Add <b>TDAI </b> under this object</em>}</li>
32- * <li>{@link AbstractDAIAdapter#addSDOI(String) <em>Add <b>TSDI </b> under this object</em>}</li>
3327 * <li>{@link AbstractDAIAdapter#update(Long, String) <em>Update <b>TDAI</b> (sGroup, value)</em>}</li>
3428 * <li>{@link AbstractDAIAdapter#update(Map) <em>Update Many <b>TDAI</b> (sGroup, value)</em>}</li>
3529 * <li>{@link AbstractDAIAdapter#addPrivate(TPrivate) <em>Add <b>TPrivate </b> under this object</em>}</li>
@@ -52,30 +46,6 @@ protected AbstractDAIAdapter(P parentAdapter, TDAI currentElem) {
5246 super (parentAdapter , currentElem );
5347 }
5448
55- /**
56- * Gets SDI from DAI by name
57- *
58- * @param sName SDI name
59- * @param <S> expected class type
60- * @return <em>IDataAdapter</em> related object
61- * @throws ScdException throws when specified SDI not present in DAI
62- */
63- public <S extends IDataAdapter > S getStructuredDataAdapterByName (String sName ) throws ScdException {
64- throw new UnsupportedOperationException ("DAI doesn't have any SDI" );
65- }
66-
67- /**
68- * Gets DataAdapter by DAI
69- *
70- * @param sName DAI name
71- * @param <S> expected class type
72- * @return <em>IDataAdapter</em> related object
73- * @throws ScdException throws when specified DAI unknown
74- */
75- public <S extends IDataAdapter > S getDataAdapterByName (String sName ) throws ScdException {
76- throw new UnsupportedOperationException ("DAI doesn't have any DAI" );
77- }
78-
7949 /**
8050 * Sets <em>ValImport</em> value
8151 *
@@ -104,7 +74,7 @@ public AbstractDAIAdapter<? extends SclElementAdapter> update(Map<Long, String>
10474 }
10575
10676 /**
107- * Updates DAI SGroup value
77+ * Updates DAI SGroup value. This method checks if DAI is updatable.
10878 *
10979 * @param sGroup SGroup to update
11080 * @param val value
@@ -118,42 +88,31 @@ public void update(Long sGroup, String val) throws ScdException {
11888 throw new ScdException (msg );
11989 }
12090 if (sGroup != null && sGroup != 0 ) {
121- updateSGroupVal (sGroup , val );
91+ setSGroupVal (sGroup , val );
12292 } else {
123- updateVal (val );
93+ setVal (val );
12494 }
12595 }
12696
127- private void updateSGroupVal (Long sGroup , String val ) {
97+ private void setSGroupVal (Long sGroup , String value ) {
12898 currentElem .getVal ().stream ()
12999 .filter (tValElem -> tValElem .isSetSGroup () && sGroup .equals (tValElem .getSGroup ()))
130100 .findFirst ()
131- .orElseGet (
132- () -> {
133- TVal newTVal = new TVal ();
134- newTVal .setSGroup (sGroup );
135- currentElem .getVal ().add (newTVal );
136- return newTVal ;
137- })
138- .setValue (val );
101+ .ifPresentOrElse (
102+ tVal -> tVal .setValue (value ),
103+ () -> currentElem .getVal ().add (newVal (value , sGroup )));
139104 }
140105
141- public void updateVal (String s ) {
106+ /**
107+ * Set Val (without sGroup) for DAI without checking if DAI is updatable
108+ * @param value new value
109+ */
110+ public void setVal (String value ) {
142111 currentElem .getVal ().stream ().findFirst ()
143- .orElseGet (
144- () -> {
145- TVal newTVal = new TVal ();
146- currentElem .getVal ().add (newTVal );
147- return newTVal ;
148- })
149- .setValue (s );
150- }
112+ .ifPresentOrElse (
113+ tVal -> tVal .setValue (value ),
114+ () -> currentElem .getVal ().add (newVal (value )));
151115
152- public IDataAdapter addDAI (String name ) {
153- throw new UnsupportedOperationException ("DAI cannot contain an SDI" );
154116 }
155117
156- public IDataAdapter addSDOI (String sdoName ) {
157- throw new UnsupportedOperationException ("DAI cannot contain an DAI" );
158- }
159118}
0 commit comments