Skip to content

Commit ea718e7

Browse files
committed
[Java] Extract getPresence method.
1 parent eaf98b6 commit ea718e7

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/Message.java

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -263,28 +263,13 @@ private Field parseField(final NodeList nodeList, final int nodeIndex)
263263
handleError(node, "could not find type: " + typeName);
264264
}
265265

266-
final String presenceStr = getAttributeValueOrNull(node, "presence");
267-
final Presence presence;
268-
if (null != presenceStr)
269-
{
270-
presence = Presence.get(presenceStr);
271-
}
272-
else if (null != fieldType)
273-
{
274-
presence = fieldType.presence();
275-
}
276-
else
277-
{
278-
presence = Presence.REQUIRED;
279-
}
280-
281266
final Field field = new Field.Builder()
282267
.name(getAttributeValue(node, "name"))
283268
.description(getAttributeValueOrNull(node, "description"))
284269
.id(Integer.parseInt(getAttributeValue(node, "id")))
285270
.offset(Integer.parseInt(getAttributeValue(node, "offset", "0")))
286271
.semanticType(getAttributeValueOrNull(node, "semanticType"))
287-
.presence(presence)
272+
.presence(getPresence(node, fieldType))
288273
.valueRef(getAttributeValueOrNull(node, "valueRef"))
289274
.sinceVersion(Integer.parseInt(getAttributeValue(node, "sinceVersion", "0")))
290275
.deprecated(Integer.parseInt(getAttributeValue(node, "deprecated", "0")))
@@ -298,6 +283,27 @@ else if (null != fieldType)
298283
return field;
299284
}
300285

286+
private static Presence getPresence(final Node node, final Type fieldType)
287+
{
288+
final String presenceStr = getAttributeValueOrNull(node, "presence");
289+
final Presence presence;
290+
291+
if (null != presenceStr)
292+
{
293+
presence = Presence.get(presenceStr);
294+
}
295+
else if (null != fieldType)
296+
{
297+
presence = fieldType.presence();
298+
}
299+
else
300+
{
301+
presence = Presence.REQUIRED;
302+
}
303+
304+
return presence;
305+
}
306+
301307
private Field parseDataField(final NodeList nodeList, final int nodeIndex)
302308
{
303309
final Node node = nodeList.item(nodeIndex);

0 commit comments

Comments
 (0)