Changeset 54:2060ce1d7b14 in rrlib_serialization-java
- Timestamp:
- 16.02.2021 12:59:18 (2 years ago)
- Branch:
- default
- Phase:
- public
- Tags:
- tip
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
rtti/datatype/PrimitiveTypeList.java
r48 r54 28 28 import org.rrlib.serialization.StringOutputStream; 29 29 import org.rrlib.serialization.StringSerializable; 30 import org.rrlib.serialization.XMLSerializable; 31 import org.rrlib.xml.XMLNode; 30 32 31 33 /** … … 34 36 * Abstract base class for lists of primitive types 35 37 */ 36 public abstract class PrimitiveTypeList extends MemoryBuffer implements ContainsStrings, StringSerializable {38 public abstract class PrimitiveTypeList extends MemoryBuffer implements ContainsStrings, StringSerializable, XMLSerializable { 37 39 38 40 protected PrimitiveTypeList(Channel[] channels) { … … 153 155 protected final Channel[] channels; 154 156 protected final int typeSize; 157 158 @Override 159 public void serialize(XMLNode node) throws Exception { 160 for (int i = 0; i < size(); i++) { 161 node.addChildNode("element").setContent(getString(i).toString()); 162 } 163 } 164 165 @Override 166 public void deserialize(XMLNode node) throws Exception { 167 int size = node.childCount(); 168 this.setSize(size); 169 if (size > 0) { 170 int index = 0; 171 for (XMLNode child : node.children()) { 172 String textContent = child.getTextContent().trim(); 173 // As subclasses are used as adapters for SI unit list types, basic/sufficient trimming of units is supported here 174 if (textContent.length() > 0 && Character.isLetter(textContent.charAt(textContent.length() - 1))) { 175 for (int i = 0; i < textContent.length(); i++) { 176 char c = textContent.charAt(i); 177 if (Character.isLetter(c) && c != 'E' && c != 'e') { 178 textContent = textContent.substring(0, i); 179 break; 180 } 181 } 182 } 183 setString(index, textContent); 184 index++; 185 } 186 } 187 } 188 155 189 }
Note: See TracChangeset
for help on using the changeset viewer.