All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.regnosys.rosetta.translate.datamodel.json.JsonEntity Maven / Gradle / Ivy

There is a newer version: 11.25.1
Show newest version
package com.regnosys.rosetta.translate.datamodel.json;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.google.common.collect.Sets;
import com.regnosys.rosetta.translate.datamodel.Attribute;
import com.regnosys.rosetta.translate.datamodel.Entity;
import com.regnosys.rosetta.translate.datamodel.NamespaceName;

public class JsonEntity implements Entity {

	private static final String HASH = "#";

	// unsure of multi should be here
	private static final Set DATA_TYPES = Sets.newHashSet("editor", "datePicker", "radio", "text", "selectGroup", "time", "string", "integer", "boolean");

	private final NamespaceName name;
	private final List attributes;
	private final String type;

	public JsonEntity(String name, String type, List attributes) {
		this.name = new NamespaceName("", name);
		this.type = type;
		this.attributes = attributes;
	}

	public JsonEntity(String name, String type) {
		this(name, type, new ArrayList<>());
	}

	public JsonEntity(JsonEntity otherEntity) {
		this(otherEntity.name.getName(), otherEntity.type, otherEntity.getAttributes());
	}

	@Override
	public NamespaceName getName() {
		return name;
	}

	@Override
	public List getAttributes() {
		return attributes;
	}

	public String getType() {
		return type;
	}

	public boolean containsReferences() {
		return type.startsWith(HASH);
	}

	@Override
	public void addAttribute(Attribute att) {
		attributes.add(att);
	}

	@Override
	public Entity getExtendedEntity() {
		return null;
	}

	@Override
	public List getKnownExtendingEntities() {
		return Collections.emptyList();
	}

	@Override
	public boolean hasChild() {
		return attributes.size() > 0;
	}

	@Override
	public boolean hasData() {
		return DATA_TYPES.contains(type);
	}

	@Override
	public String toString(Set alreadyWritten) {
		StringBuilder builder = new StringBuilder();
		builder	.append(name)
				.append("\t")
				.append("[" + type + "]");
		builder.append("\n");
		for (Attribute attr : attributes) {
			builder.append("  ");
			builder.append(attr	.toString(alreadyWritten)
								.replace("\n", "\n  "));
			builder.append("\n");
		}
		return builder.toString();
	}

	@Override
	public String toString() {
		return toString(new HashSet<>());
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy