Example usage for java.util Set iterator

List of usage examples for java.util Set iterator

Introduction

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

Prototype

Iterator<E> iterator();

Source Link

Document

Returns an iterator over the elements in this set.

Usage

From source file:com.beetle.framework.util.ObjectUtil.java

public final static void populate(Object obj, Map<String, Object> map) {
    Set<?> s = map.entrySet();
    Iterator<?> it = s.iterator();
    while (it.hasNext()) {
        String key = "";
        Object o = null;//from   w w  w.  j av  a 2s .  c  o m
        @SuppressWarnings("rawtypes")
        Map.Entry me = (Map.Entry) it.next();
        try {
            key = me.getKey().toString();
            o = me.getValue();
            if (o == null) {
                continue;
            }
            setValue(key, obj, o);
        } catch (IllegalArgumentException e) {
            Class<Object> type = ObjectUtil.getType(key, obj);
            String tstr = type.toString();
            if (tstr.equals(Integer.class.toString())) {
                ObjectUtil.setValue(key, obj, Integer.valueOf(o.toString()));
            } else if (tstr.equals(Long.class.toString())) {
                ObjectUtil.setValue(key, obj, Long.valueOf(o.toString()));
            } else if (tstr.equals(Float.class.toString())) {
                ObjectUtil.setValue(key, obj, Float.valueOf(o.toString()));
            } else if (tstr.equals(Double.class.toString())) {
                ObjectUtil.setValue(key, obj, Double.valueOf(o.toString()));
            } else if (tstr.equals(Short.class.toString())) {
                ObjectUtil.setValue(key, obj, Short.valueOf(o.toString()));
            } else if (tstr.equals(Byte.class.toString())) {
                ObjectUtil.setValue(key, obj, Byte.valueOf(o.toString()));
            } else if (tstr.equals(Date.class.toString())) {
                if (o instanceof Date) {
                    ObjectUtil.setValue(key, obj, (Date) o);
                } else {
                    long time = ((Double) o).longValue();
                    ObjectUtil.setValue(key, obj, new Date(time));
                }
            } else if (tstr.equals(java.sql.Timestamp.class.toString())) {
                if (o instanceof java.sql.Timestamp) {
                    ObjectUtil.setValue(key, obj, (Date) o);
                } else {
                    long time = ((Double) o).longValue();
                    ObjectUtil.setValue(key, obj, new java.sql.Timestamp(time));
                }
            } else {
                throw e;
            }
            tstr = null;
            type = null;
        }
    }
}

From source file:edu.american.student.stonewall.util.Deployer.java

public static void deploy(List<String> packages, File deployDirectory) throws DeployException {
    Class<? extends Index> indexPage = null;
    List<Class<? extends Page>> otherPages = new ArrayList<Class<? extends Page>>();
    for (String pkg : packages) {
        Reflections reflections = new Reflections(pkg);
        Set<Class<? extends Index>> indexClasses = reflections.getSubTypesOf(Index.class);
        if (indexClasses.size() > 1) {
            throw new DeployException("More than 1 class found that extends Index");
        }/*from  ww  w . j a  v  a2s.  co  m*/
        if (indexClasses.size() == 1) {
            if (indexPage != null) {
                throw new DeployException("More than 1 class found that extends Index");
            } else {
                indexPage = indexClasses.iterator().next();
            }
        }
        Set<Class<? extends Page>> pageClasses = reflections.getSubTypesOf(Page.class);
        for (Class<? extends Page> page : pageClasses) {
            otherPages.add(page);
        }
    }
    try {
        deployMe(indexPage, otherPages, deployDirectory);
    } catch (Exception e) {
        throw new DeployException("Unable to deploy ", e);
    }
}

From source file:org.cloudfoundry.reconfiguration.play.Configurer.java

static void configure(ApplicationConfiguration applicationConfiguration, Cloud cloud,
        PropertySetter propertySetter) {
    propertySetter.setCloudProperties();

    Set<String> databaseNames = applicationConfiguration.getDatabaseNames();
    propertySetter.setDatabaseProperties(databaseNames);

    if (databaseNames.isEmpty()) {
        LOGGER.info("No databases found. Skipping auto-reconfiguration.");
    } else if (databaseNames.size() > 1) {
        LOGGER.warning(String.format("Multiple (%d) databases found. Skipping auto-reconfiguration.",
                databaseNames.size()));//w  w  w  . j  a  v  a 2s .co m
    } else {
        processDatabase(applicationConfiguration, cloud, databaseNames.iterator().next());
    }
}

From source file:com.ace.erp.common.inject.support.InjectBaseDependencyHelper.java

public static void findAndInjectBaseRepositoryDependency(GenericService<?, ?> genericService) {
    final Set<Object> candidates = findDependencies(genericService, BaseComponent.class);

    if (candidates.size() == 0 || candidates.size() > 1) {
        throw new IllegalStateException(
                "expect 1 @BaseComponent anntation BaseRepository subclass bean, but found " + candidates.size()
                        + ", please check class [" + genericService.getClass()
                        + "] @BaseComponent annotation.");
    }/*  w  w w. jav  a  2s. co m*/

    Object baserMapper = candidates.iterator().next();

    if (baserMapper.getClass().isAssignableFrom(BaseComponent.class)) {
        throw new IllegalStateException("[" + genericService.getClass() + "] @BaseComponent annotation bean "
                + "must be BaseRepository subclass");
    }
    genericService.setBaseMapper((BaseMapper) baserMapper);
}

From source file:com.nulli.openam.plugins.NeoUniversalCondition.java

private static String getInitStringValue(Set<String> set) {
    return ((set == null) || set.isEmpty()) ? "" : set.iterator().next();
}

From source file:com.nulli.openam.plugins.NeoUniversalCondition.java

private static String getStringValue(Set<String> set) {
    return ((set == null) || set.isEmpty()) ? null : set.iterator().next();
}

From source file:com.gemstone.gemfire.internal.security.GeodeSecurityUtil.java

/**
 * It first looks the shiro subject in AccessControlContext since JMX will
 * use multiple threads to process operations from the same client, then it
 * looks into Shiro's thead context.//from   ww  w . j  ava  2  s.  co m
 *
 * @return the shiro subject, null if security is not enabled
 */
public static Subject getSubject() {
    if (!isIntegratedSecurity) {
        return null;
    }

    Subject currentUser = null;

    // First try get the principal out of AccessControlContext instead of Shiro's Thread context
    // since threads can be shared between JMX clients.
    javax.security.auth.Subject jmxSubject = javax.security.auth.Subject
            .getSubject(AccessController.getContext());

    if (jmxSubject != null) {
        Set<ShiroPrincipal> principals = jmxSubject.getPrincipals(ShiroPrincipal.class);
        if (principals.size() > 0) {
            ShiroPrincipal principal = principals.iterator().next();
            currentUser = principal.getSubject();
            ThreadContext.bind(currentUser);
            return currentUser;
        }
    }

    // in other cases like admin rest call or pulse authorization
    currentUser = SecurityUtils.getSubject();

    if (currentUser == null || currentUser.getPrincipal() == null) {
        throw new GemFireSecurityException("Error: Anonymous User");
    }

    return currentUser;
}

From source file:de.alpharogroup.collections.ListExtensions.java

/**
 * Splits the Set to Parts to the specified times.
 *
 * @param <T>//from  ww  w.  ja va2 s  .  co  m
 *            the generic type
 * @param set
 *            The Set to Split
 * @param times
 *            How to split.
 * @return An ArrayList with the Splitted Parts
 */
public static <T> List<List<T>> splitSetToParts(final Set<T> set, final int times) {
    final List<List<T>> returnList = new ArrayList<>();
    ArrayList<T> tmp = new ArrayList<>();
    final Iterator<T> it = set.iterator();
    int count = 0;
    while (it.hasNext()) {
        if (count == times) {
            returnList.add(tmp);
            tmp = new ArrayList<>();
            tmp.add(it.next());
            count = 1;
        } else {
            tmp.add(it.next());
            count++;
        }
    }
    if (!tmp.isEmpty()) {
        returnList.add(tmp);
    }
    return returnList;
}

From source file:com.floragunn.searchguard.util.SecurityUtil.java

public static String getSearchGuardSessionIdFromCookie(final RestRequest request) {

    final String cookies = request.header("Cookie");

    if (cookies != null) {

        final Set<Cookie> cookiesAsSet = new CookieDecoder().decode(cookies);

        log.trace("Cookies {}", cookiesAsSet);

        for (final Iterator iterator = cookiesAsSet.iterator(); iterator.hasNext();) {
            final Cookie cookie = (Cookie) iterator.next();
            if ("es_searchguard_session".equals(cookie.getName())) {
                return cookie.getValue();
            }// www  .  j  a  va 2 s  .  c om
        }

    }
    return null;
}

From source file:com.qualogy.qafe.core.application.ApplicationContextLoader.java

/**
 * 1) collect all the original file locations
 * 2) clear the cluster// w  ww .  j  ava 2  s  .com
 * 3)a. read the original file locations
 * 3)b. reload the contexts
 * 4) add all re-read/loaded contexts 
 */
public synchronized static void reload() {

    Set<URI> fileLocations = new HashSet<URI>();
    for (Iterator<ApplicationContext> iter = ApplicationCluster.getInstance().iterator(); iter.hasNext();) {
        ApplicationContext context = (ApplicationContext) iter.next();
        fileLocations.add(context.getOriginAppConfigFileLocation());
    }

    ApplicationCluster.getInstance().clear();

    for (Iterator<URI> iter = fileLocations.iterator(); iter.hasNext();) {
        URI fileLocation = (URI) iter.next();
        ApplicationStack contexts = read(fileLocation);

        load(contexts, fileLocation);

        ApplicationCluster.getInstance().putAll(contexts);
    }
}