
org.molgenis.data.importer.ParsedMetaData Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of molgenis-data-import Show documentation
Show all versions of molgenis-data-import Show documentation
Entity importer framework and EMX importer.
package org.molgenis.data.importer;
import java.util.List;
import java.util.Map;
import org.molgenis.data.AttributeMetaData;
import org.molgenis.data.Entity;
import org.molgenis.data.EntityMetaData;
import org.molgenis.data.Package;
import org.molgenis.data.semantic.LabeledResource;
import org.molgenis.data.semantic.Tag;
import com.google.common.collect.ImmutableCollection;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSetMultimap;
import com.google.common.collect.SetMultimap;
/**
* Value object to store the result of parsing a source.
*/
public final class ParsedMetaData
{
private final ImmutableMap entities;
private final ImmutableMap packages;
private final ImmutableSetMultimap> attributeTags;
private final ImmutableList> entityTags;
private final ImmutableMap languages;
private final ImmutableMap i18nStrings;
public ParsedMetaData(List extends EntityMetaData> entities, Map packages,
SetMultimap> attributeTags,
List> entityTags, Map languages,
ImmutableMap i18nStrings)
{
if (entities == null)
{
throw new NullPointerException("Null entities");
}
ImmutableMap.Builder builder = ImmutableMap. builder();
for (EntityMetaData emd : entities)
{
builder.put(emd.getName(), emd);
}
this.entities = builder.build();
if (packages == null)
{
throw new NullPointerException("Null packages");
}
this.packages = ImmutableMap.copyOf(packages);
ImmutableSetMultimap.Builder> attrTagBuilder = ImmutableSetMultimap
.> builder();
for (String simpleEntityName : attributeTags.keys())
{
EntityMetaData emd = this.entities.get(simpleEntityName);
if (emd == null)
{
throw new NullPointerException("Unknown entity [" + simpleEntityName + "]");
}
for (Tag tag : attributeTags.get(simpleEntityName))
{
attrTagBuilder.put(emd, tag);
}
}
this.attributeTags = attrTagBuilder.build();
this.entityTags = ImmutableList.copyOf(entityTags);
this.languages = ImmutableMap.copyOf(languages);
this.i18nStrings = ImmutableMap.copyOf(i18nStrings);
}
public ImmutableCollection getEntities()
{
return entities.values();
}
public ImmutableMap getEntityMap()
{
return entities;
}
public ImmutableMap getPackages()
{
return packages;
}
public SetMultimap> getAttributeTags()
{
return attributeTags;
}
public ImmutableList> getEntityTags()
{
return entityTags;
}
public ImmutableMap getLanguages()
{
return languages;
}
public ImmutableMap getI18nStrings()
{
return i18nStrings;
}
@Override
public String toString()
{
return "ParsedMetaData [entities=" + entities + ", packages=" + packages + ", attributeTags=" + attributeTags
+ ", entityTags=" + entityTags + ", languages=" + languages + ", i18nStrings=" + i18nStrings + "]";
}
@Override
public int hashCode()
{
final int prime = 31;
int result = 1;
result = prime * result + ((attributeTags == null) ? 0 : attributeTags.hashCode());
result = prime * result + ((entities == null) ? 0 : entities.hashCode());
result = prime * result + ((entityTags == null) ? 0 : entityTags.hashCode());
result = prime * result + ((i18nStrings == null) ? 0 : i18nStrings.hashCode());
result = prime * result + ((languages == null) ? 0 : languages.hashCode());
result = prime * result + ((packages == null) ? 0 : packages.hashCode());
return result;
}
@Override
public boolean equals(Object obj)
{
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
ParsedMetaData other = (ParsedMetaData) obj;
if (attributeTags == null)
{
if (other.attributeTags != null) return false;
}
else if (!attributeTags.equals(other.attributeTags)) return false;
if (entities == null)
{
if (other.entities != null) return false;
}
else if (!entities.equals(other.entities)) return false;
if (entityTags == null)
{
if (other.entityTags != null) return false;
}
else if (!entityTags.equals(other.entityTags)) return false;
if (i18nStrings == null)
{
if (other.i18nStrings != null) return false;
}
else if (!i18nStrings.equals(other.i18nStrings)) return false;
if (languages == null)
{
if (other.languages != null) return false;
}
else if (!languages.equals(other.languages)) return false;
if (packages == null)
{
if (other.packages != null) return false;
}
else if (!packages.equals(other.packages)) return false;
return true;
}
/**
* Gets a specific package
*
* @param name
* the name of the package
* @return
*/
public org.molgenis.data.Package getPackage(String name)
{
return getPackages().get(name);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy