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

com.github.TKnudsen.ComplexDataObject.model.processors.utility.UniqueValuesIdentifier Maven / Gradle / Ivy

Go to download

A library that models real-world objects in Java, referred to as ComplexDataObjects. Other features: IO and preprocessing of ComplexDataObjects.

There is a newer version: 0.2.13
Show newest version
package com.github.TKnudsen.ComplexDataObject.model.processors.utility;

import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * Iterates over the values of a given attribute stored in the supplied ComplexDataContainer and
 * returns a List of all the unique values found.
 * 
 * 

Assumes that the values to be scanned are stored as lists by each ComplexDataObject. * * @author Robert Heimbach * * @see AbstractUniqueValuesIdentifier */ public class UniqueValuesIdentifier extends AbstractUniqueValuesIdentifier { @Override public Set getUniqueValues() { if(!(this.hasAttribute() && this.hasDataContainer())){ return null; } // Get values Map attributeValues = getDataContainer().getAttributeValues(attribute); Set uniqueValues = null; if (attributeValues != null){ uniqueValues = new HashSet(); // it is assumed that each ComplexDataObject has stored its value as a List of Items for(Object itemList : attributeValues.values()){ // cast it to a collection, because we want to iterate over the list if(itemList instanceof List){ List values = (List) itemList; for(Object value : values){ uniqueValues.add(value); } } } } return uniqueValues; } }