Package org.openiaml.emf.properties.library

Source Code of org.openiaml.emf.properties.library.DistinctTypes

/**
*
*/
package org.openiaml.emf.properties.library;

import java.util.HashSet;
import java.util.Set;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.openiaml.emf.properties.IEMFElementSelector;
import org.openiaml.emf.properties.IterateOverAll;


/**
* @author jmwright
*
*/
public class DistinctTypes extends IterateOverAll {
  private Set<EClass> types = new HashSet<EClass>();

  /**
   * @param name
   */
  public DistinctTypes(String name, IEMFElementSelector selector) {
    super(name, selector);
  }
 
  public DistinctTypes(IEMFElementSelector selector) {
    this(DistinctTypes.class.getSimpleName(), selector);
  }

  @Override
  public Object evaluate(EObject root) {
    // evaluate as normal
    super.evaluate(root);
    // but return the distinct types
    return types.size();
  }

  @Override
  public int get(EObject obj) {
    EClass type = obj.eClass();
    if (!types.contains(type)) {
      types.add(type);
    }
    return 0// ignored
  }
}
TOP

Related Classes of org.openiaml.emf.properties.library.DistinctTypes

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.