@Override public String toString() { return "TCapabilityDefinition{" + "description='" + getDescription() + '\'' + ", occurrences=" + getOccurrences() + ", validSourceTypes=" + getValidSourceTypes() + ", type=" + getType() + ", properties=" + getProperties() + ", attributes=" + getAttributes() + '}'; }
public TCapabilityDefinition build() { return new TCapabilityDefinition(this); } }
/** * Converts TOSCA YAML CapabilityDefinitions to TOSCA XML CapabilityDefinitions Additional TOSCA YAML elements * properties, attributes and valid_source_types are not converted * * @param node TOSCA YAML CapabilityDefinition * @return TOSCA XML CapabilityDefinition */ private TCapabilityDefinition convert(org.eclipse.winery.model.tosca.yaml.TCapabilityDefinition node, String id) { if (Objects.isNull(node)) return null; return new TCapabilityDefinition.Builder(id, node.getType()) .addDocumentation(node.getDescription()) .setLowerBound(node.getLowerBound()) .setUpperBound(node.getUpperBound()) .build(); }
@Override public R visit(TCapabilityDefinition node, P parameter) { return reduce(Stream.of( visitElement(node.getProperties(), parameter, "properties"), visitElement(node.getAttributes(), parameter, "attributes") )); }
@NonNull public String getUpperBound() { if (getOccurrences() == null || getOccurrences().size() <= 1) { return "1"; } else { return getOccurrences().get(1); } }
@NonNull public Integer getLowerBound() { if (getOccurrences() == null || getOccurrences().isEmpty()) { return 1; } else { return Integer.valueOf(getOccurrences().get(0)); } }
@Override public int hashCode() { return Objects.hash(getDescription(), getOccurrences(), getValidSourceTypes(), getType(), getProperties(), getAttributes()); }
@Nullable public TCapabilityDefinition buildCapabilityDefinition(Object object, Parameter<TCapabilityDefinition> parameter) { if (Objects.isNull(object)) return new TCapabilityDefinition(); if (object instanceof String) return new TCapabilityDefinition.Builder(buildQName(stringValue(object))).build(); if (!validate(TCapabilityDefinition.class, object, parameter)) return null; @SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>) object; return new TCapabilityDefinition.Builder(buildQName(stringValue(map.get("type")))) .setDescription(buildDescription(map.get("description"))) .setOccurrences(buildListString(map.get("occurrences"), new Parameter<List<String>>(parameter.getContext()).addContext("occurrences") )) .setValidSourceTypes(buildListQName(buildListString(map.get("valid_source_types"), new Parameter<List<String>>(parameter.getContext()).addContext("valid_source_types") ))) .setProperties(buildMap(map.get("properties"), new Parameter<TPropertyDefinition>(parameter.getContext()).addContext("properties") .setClazz(TPropertyDefinition.class) .setBuilderOO(this::buildPropertyDefinition) )) .setAttributes(buildMap(map, "attributes", this::buildAttributeDefinition, parameter)) .build(); }
@Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof TCapabilityDefinition)) return false; TCapabilityDefinition that = (TCapabilityDefinition) o; return Objects.equals(getDescription(), that.getDescription()) && Objects.equals(getOccurrences(), that.getOccurrences()) && Objects.equals(getValidSourceTypes(), that.getValidSourceTypes()) && Objects.equals(getType(), that.getType()) && Objects.equals(getProperties(), that.getProperties()) && Objects.equals(getAttributes(), that.getAttributes()); }
public Printer visit(TCapabilityDefinition node, Parameter parameter) { return new Printer(parameter.getIndent()) .printKeyValue("description", node.getDescription()) .printKeyValue("occurrences", node.getOccurrences()) .printKeyValue("valid_source_types", node.getValidSourceTypes()) .printKeyValue("type", node.getType()) .print(printMap("properties", node.getProperties(), parameter)) .print(printMap("attributes", node.getAttributes(), parameter)); }