/** * Builds a new {@link MultiAttributeData} instance using the properties as * set by this builder. * @return A new instance. */ public MultiAttributeData build() { checkArgument(!getAttributes().isEmpty() || getLength().isPresent() || getMaxSpeed().isPresent(), "At least length, maxSpeed or another attribute must to be defined."); return new AutoValue_MultiAttributeData(length, maxSpeed, ImmutableMap.copyOf(attributes)); } }
/** * Builds a new {@link MultiAttributeData} instance using the properties as * set by this builder. * @return A new instance. */ public MultiAttributeData build() { checkArgument(!getAttributes().isEmpty() || getLength().isPresent() || getMaxSpeed().isPresent(), "At least length, maxSpeed or another attribute must to be defined."); return new AutoValue_MultiAttributeData(length, maxSpeed, ImmutableMap.copyOf(attributes)); } }
@Override public Optional<MultiAttributeData> read(String data) { final Map<String, String> map = parseDataAsMap(data); final Builder b = MultiAttributeData.builder(); if (map.containsKey(DISTANCE)) { b.setLength(Double.parseDouble(map.get(DISTANCE))); map.remove(DISTANCE); } if (map.containsKey(MAX_SPEED)) { b.setMaxSpeed(Double.parseDouble(map.get(MAX_SPEED))); map.remove(MAX_SPEED); } b.addAllAttributes(map); if (b.getAttributes().isEmpty() && !b.getLength().isPresent() && !b.getMaxSpeed().isPresent()) { return Optional.absent(); } return Optional.of(b.build()); } }
@Override public Optional<MultiAttributeData> read(String data) { final Map<String, String> map = parseDataAsMap(data); final Builder b = MultiAttributeData.builder(); if (map.containsKey(DISTANCE)) { b.setLength(Double.parseDouble(map.get(DISTANCE))); map.remove(DISTANCE); } if (map.containsKey(MAX_SPEED)) { b.setMaxSpeed(Double.parseDouble(map.get(MAX_SPEED))); map.remove(MAX_SPEED); } b.addAllAttributes(map); if (b.getAttributes().isEmpty() && !b.getLength().isPresent() && !b.getMaxSpeed().isPresent()) { return Optional.absent(); } return Optional.of(b.build()); } }