Example usage for java.util HashSet clone

List of usage examples for java.util HashSet clone

Introduction

In this page you can find the example usage for java.util HashSet clone.

Prototype

@SuppressWarnings("unchecked")
public Object clone() 

Source Link

Document

Returns a shallow copy of this HashSet instance: the elements themselves are not cloned.

Usage

From source file:Main.java

public static void main(String args[]) {
    // create two hash sets      
    HashSet<String> cloneset = new HashSet<String>();

    HashSet<String> newset = new HashSet<String>();

    // populate hash set
    newset.add("Learning");
    newset.add("from");
    newset.add("java2s.com");

    // clone the hash set
    cloneset = (HashSet) newset.clone();

    System.out.println("Hash set values: " + newset);
    System.out.println("Clone Hash set values: " + cloneset);
}

From source file:org.apache.hadoop.hdfs.server.namenode.ha.TestRetryCacheWithHA.java

@SuppressWarnings("unchecked")
private void listCachePools(HashSet<String> poolNames, int active) throws Exception {
    HashSet<String> tmpNames = (HashSet<String>) poolNames.clone();
    RemoteIterator<CachePoolEntry> pools = dfs.listCachePools();
    int poolCount = poolNames.size();
    for (int i = 0; i < poolCount; i++) {
        CachePoolEntry pool = pools.next();
        String pollName = pool.getInfo().getPoolName();
        assertTrue("The pool name should be expected", tmpNames.remove(pollName));
        if (i % 2 == 0) {
            int standby = active;
            active = (standby == 0) ? 1 : 0;
            cluster.shutdownNameNode(standby);
            cluster.waitActive(active);/*from ww w  .  j av  a  2  s .  co  m*/
            cluster.restartNameNode(standby, false);
        }
    }
    assertTrue("All pools must be found", tmpNames.isEmpty());
}

From source file:org.apache.hadoop.hdfs.server.namenode.ha.TestRetryCacheWithHA.java

@SuppressWarnings("unchecked")
private void listCacheDirectives(HashSet<String> poolNames, int active) throws Exception {
    HashSet<String> tmpNames = (HashSet<String>) poolNames.clone();
    RemoteIterator<CacheDirectiveEntry> directives = dfs.listCacheDirectives(null);
    int poolCount = poolNames.size();
    for (int i = 0; i < poolCount; i++) {
        CacheDirectiveEntry directive = directives.next();
        String pollName = directive.getInfo().getPool();
        assertTrue("The pool name should be expected", tmpNames.remove(pollName));
        if (i % 2 == 0) {
            int standby = active;
            active = (standby == 0) ? 1 : 0;
            cluster.shutdownNameNode(standby);
            cluster.waitActive(active);//  w  w  w  . j  a  v a2s  . co  m
            cluster.restartNameNode(standby, false);
        }
    }
    assertTrue("All pools must be found", tmpNames.isEmpty());
}

From source file:org.apache.james.mailrepository.file.FileMailRepository.java

@Override
@PostConstruct/*from  w  ww . jav  a2 s. co m*/
public void init() throws Exception {
    try {
        DefaultConfigurationBuilder reposConfiguration = new DefaultConfigurationBuilder();

        reposConfiguration.addProperty("[@destinationURL]", destination);
        objectRepository = new FilePersistentObjectRepository();
        objectRepository.setLog(getLogger());
        objectRepository.setFileSystem(fileSystem);
        objectRepository.configure(reposConfiguration);
        objectRepository.init();

        streamRepository = new FilePersistentStreamRepository();
        streamRepository.setLog(getLogger());
        streamRepository.setFileSystem(fileSystem);
        streamRepository.configure(reposConfiguration);
        streamRepository.init();

        if (cacheKeys)
            keys = Collections.synchronizedSet(new HashSet<String>());

        // Finds non-matching pairs and deletes the extra files
        HashSet<String> streamKeys = new HashSet<String>();
        for (Iterator<String> i = streamRepository.list(); i.hasNext();) {
            streamKeys.add(i.next());
        }
        HashSet<String> objectKeys = new HashSet<String>();
        for (Iterator<String> i = objectRepository.list(); i.hasNext();) {
            objectKeys.add(i.next());
        }

        @SuppressWarnings("unchecked")
        Collection<String> strandedStreams = (Collection<String>) streamKeys.clone();
        strandedStreams.removeAll(objectKeys);
        for (Object strandedStream : strandedStreams) {
            String key = (String) strandedStream;
            remove(key);
        }

        @SuppressWarnings("unchecked")
        Collection<String> strandedObjects = (Collection<String>) objectKeys.clone();
        strandedObjects.removeAll(streamKeys);
        for (Object strandedObject : strandedObjects) {
            String key = (String) strandedObject;
            remove(key);
        }

        if (keys != null) {
            // Next get a list from the object repository
            // and use that for the list of keys
            keys.clear();
            for (Iterator<String> i = objectRepository.list(); i.hasNext();) {
                keys.add(i.next());
            }
        }
        if (getLogger().isDebugEnabled()) {
            String logBuffer = getClass().getName() + " created in " + destination;
            getLogger().debug(logBuffer);
        }
    } catch (Exception e) {
        final String message = "Failed to retrieve Store component:" + e.getMessage();
        getLogger().error(message, e);
        throw e;
    }
}

From source file:org.openanzo.glitter.syntax.abstrakt.Group.java

/**
 * Construct a group from a list of patterns and a set of filter expressions.
 * /*from www .j  a v  a  2 s . c  om*/
 * @param patterns
 * @param filters
 * @param assignments
 */
@SuppressWarnings("unchecked")
public Group(ArrayList<GraphPattern> patterns, HashSet<Expression> filters,
        MultiHashMap<Variable, Expression> assignments) {
    this.patterns = new ArrayList<GraphPattern>();
    for (GraphPattern gp : patterns) {
        this.patterns.add((GraphPattern) gp.clone());
    }
    this.filters = (HashSet<Expression>) filters.clone();
    this.assignments = (MultiHashMap<Variable, Expression>) assignments.clone();
    for (GraphPattern gp : this.patterns)
        gp.setParent(this);
}

From source file:voldemort.NamedZone.java

public ClusterBuilder verify() throws Exception {

    // Verify that no zone has an unknown zone id
    for (Zone zone : cluster.getZones()) {
        if (NamedZone.getById(zone.getId()) == null)
            throw new Exception("Zone " + zone.getId() + " has unexpected zone id");
    }//from w  ww .jav  a  2  s . co  m

    // Verify that no zone has duplicates in its proximity list
    for (Zone zone : cluster.getZones()) {
        HashSet<Integer> seenProximates = new HashSet<Integer>();
        for (Integer proxZoneId : zone.getProximityList()) {
            Integer id = new Integer(proxZoneId);
            if (seenProximates.contains(id))
                throw new Exception("Zone " + zone.getId() + " has duplicate proximate " + proxZoneId);
            seenProximates.add(id);
        }
    }

    // Verify that no zone is recorded as proximate to itself
    for (Zone zone : cluster.getZones()) {
        for (Integer proxZoneId : zone.getProximityList()) {
            if (proxZoneId == zone.getId())
                throw new Exception("Zone " + zone.getId() + " is proximate to itself");
        }
    }

    // Verify that each zone is proximate to all the other zones
    // and only to listed zones
    HashSet<Integer> seenZones = new HashSet<Integer>();
    for (Zone zone : cluster.getZones())
        seenZones.add(new Integer(zone.getId()));
    for (Zone zone : cluster.getZones()) {
        HashSet<Integer> expectProxes = (HashSet<Integer>) seenZones.clone();
        expectProxes.remove(new Integer(zone.getId()));
        for (Integer proxZoneId : zone.getProximityList()) {
            Integer id = new Integer(proxZoneId);
            if (!expectProxes.contains(id))
                throw new Exception("Zone " + zone.getId() + " has unknown proximate zone " + proxZoneId);
            expectProxes.remove(id);
        }
        if (expectProxes.size() > 0) {
            StringBuffer buf = new StringBuffer();
            for (Integer id : expectProxes)
                buf.append(" ").append(id);
            throw new Exception("Zone " + zone.getId() + " is missing proximates to " + buf);
        }
    }
    return this;
}