@Test void cannotAppendUnsupportedType() { MutableTomlArray array = new MutableTomlArray(); assertThrows(IllegalArgumentException.class, () -> array.append(this, positionAt(1, 1))); assertThrows(NullPointerException.class, () -> array.append(null, positionAt(1, 1))); }
MutableTomlArray append(Object value, TomlPosition position) { requireNonNull(value); if (value instanceof Integer) { value = ((Integer) value).longValue(); } TomlType origType = type; Optional<TomlType> valueType = typeFor(value); if (!valueType.isPresent()) { throw new IllegalArgumentException("Unsupported type " + value.getClass().getSimpleName()); } if (type != null) { if (valueType.get() != type) { throw new TomlInvalidTypeException( "Cannot add a " + typeNameFor(value) + " to an array containing " + type.typeName() + "s"); } } else { type = valueType.get(); } try { elements.add(new Element(value, position)); } catch (Throwable e) { type = origType; throw e; } return this; }
MutableTomlArray implements TomlArray { MutableTomlArray append(Object value, TomlPosition position) { requireNonNull(value); if (value instanceof Integer) { value = ((Integer) value).longValue(); } TomlType origType = type; Optional<TomlType> valueType = typeFor(value); if (!valueType.isPresent()) { throw new IllegalArgumentException("Unsupported type " + value.getClass().getSimpleName()); } if (type != null) { if (valueType.get() != type) { throw new TomlInvalidTypeException( "Cannot add a " + typeNameFor(value) + " to an array containing " + type.typeName() + "s"); } } else { type = valueType.get(); } try { elements.add(new Element(value, position)); } catch (Throwable e) { type = origType; throw e; } return this; } }
MutableTomlArray implements TomlArray { MutableTomlArray append(Object value, TomlPosition position) { requireNonNull(value); if (value instanceof Integer) { value = ((Integer) value).longValue(); } TomlType origType = type; Optional<TomlType> valueType = typeFor(value); if (!valueType.isPresent()) { throw new IllegalArgumentException("Unsupported type " + value.getClass().getSimpleName()); } if (type != null) { if (valueType.get() != type) { throw new TomlInvalidTypeException( "Cannot add a " + typeNameFor(value) + " to an array containing " + type.typeName() + "s"); } } else { type = valueType.get(); } try { elements.add(new Element(value, position)); } catch (Throwable e) { type = origType; throw e; } return this; } MutableTomlArray();   MutableTomlArray(boolean definedAsLiteral); }
MutableTomlArray implements TomlArray { MutableTomlArray append(Object value, TomlPosition position) { requireNonNull(value); if (value instanceof Integer) { value = ((Integer) value).longValue(); } TomlType origType = type; Optional<TomlType> valueType = typeFor(value); if (!valueType.isPresent()) { throw new IllegalArgumentException("Unsupported type " + value.getClass().getSimpleName()); } if (type != null) { if (valueType.get() != type) { throw new TomlInvalidTypeException( "Cannot add a " + typeNameFor(value) + " to an array containing " + type.typeName() + "s"); } } else { type = valueType.get(); } try { elements.add(new Element(value, position)); } catch (Throwable e) { type = origType; throw e; } return this; } MutableTomlArray();   MutableTomlArray(boolean definedAsLiteral); @Override int size(); @Override boolean isEmpty(); @Override boolean containsStrings(); @Override boolean containsLongs(); @Override boolean containsDoubles(); @Override boolean containsBooleans(); @Override boolean containsOffsetDateTimes(); @Override boolean containsLocalDateTimes(); @Override boolean containsLocalDates(); @Override boolean containsLocalTimes(); @Override boolean containsArrays(); @Override boolean containsTables(); @Override Object get(int index); @Override TomlPosition inputPositionOf(int index); @Override List<Object> toList(); }
MutableTomlArray implements TomlArray { MutableTomlArray append(Object value, TomlPosition position) { requireNonNull(value); if (value instanceof Integer) { value = ((Integer) value).longValue(); } TomlType origType = type; Optional<TomlType> valueType = typeFor(value); if (!valueType.isPresent()) { throw new IllegalArgumentException("Unsupported type " + value.getClass().getSimpleName()); } if (type != null) { if (valueType.get() != type) { throw new TomlInvalidTypeException( "Cannot add a " + typeNameFor(value) + " to an array containing " + type.typeName() + "s"); } } else { type = valueType.get(); } try { elements.add(new Element(value, position)); } catch (Throwable e) { type = origType; throw e; } return this; } MutableTomlArray();   MutableTomlArray(boolean definedAsLiteral); @Override int size(); @Override boolean isEmpty(); @Override boolean containsStrings(); @Override boolean containsLongs(); @Override boolean containsDoubles(); @Override boolean containsBooleans(); @Override boolean containsOffsetDateTimes(); @Override boolean containsLocalDateTimes(); @Override boolean containsLocalDates(); @Override boolean containsLocalTimes(); @Override boolean containsArrays(); @Override boolean containsTables(); @Override Object get(int index); @Override TomlPosition inputPositionOf(int index); @Override List<Object> toList();  }