Example usage for java.util Set getClass

List of usage examples for java.util Set getClass

Introduction

In this page you can find the example usage for java.util Set getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:org.openmrs.User.java

/**
 * Returns all roles attributed to this user by expanding the role list to include the parents
 * of the assigned roles/*from w w  w . j  a  v a 2s . c o  m*/
 * 
 * @return all roles (inherited from parents and given) for this user
 */
public Set<Role> getAllRoles() {
    // the user's immediate roles
    Set<Role> baseRoles = new HashSet<Role>();

    // the user's complete list of roles including
    // the parent roles of their immediate roles
    Set<Role> totalRoles = new HashSet<Role>();
    if (getRoles() != null) {
        baseRoles.addAll(getRoles());
        totalRoles.addAll(getRoles());
    }

    if (log.isDebugEnabled()) {
        log.debug("User's base roles: " + baseRoles);
    }

    try {
        for (Role r : baseRoles) {
            totalRoles.addAll(r.getAllParentRoles());
        }
    } catch (ClassCastException e) {
        log.error("Error converting roles for user: " + this);
        log.error("baseRoles.class: " + baseRoles.getClass().getName());
        log.error("baseRoles: " + baseRoles.toString());
        Iterator<Role> iter = baseRoles.iterator();
        while (iter.hasNext()) {
            log.error("baseRole: '" + iter.next() + "'");
        }
    }
    return totalRoles;
}

From source file:uk.gov.gchq.gaffer.function.aggregate.SetAggregator.java

@Override
protected void _aggregate(final Set<T> input) {
    if (null != input) {
        if (null == set) {
            try {
                set = input.getClass().newInstance();
            } catch (InstantiationException | IllegalAccessException e) {
                throw new IllegalArgumentException(
                        "Unable to create new instance of " + input.getClass().getName()
                                + ". This set aggregator can only be used on sets with a default constructor.",
                        e);/*from  w ww .j av  a2s  .  c o  m*/
            }
        }

        set.addAll(input);
    }
}