Example usage for java.util LinkedHashSet iterator

List of usage examples for java.util LinkedHashSet iterator

Introduction

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

Prototype

Iterator<E> iterator();

Source Link

Document

Returns an iterator over the elements in this set.

Usage

From source file:org.objectweb.proactive.extensions.dataspaces.vfs.VFSSpacesMountManagerImpl.java

/**
 * Internal method for resolving a file, will mount the file system if it is not mounted yet
 * @param uri virtual uri of the file/*from  w  w w.j  av a2  s. com*/
 * @param ownerActiveObjectId Id of active object requesting this file
 * @param spaceRootFOUri root file system to use
 * @return
 * @throws FileSystemException
 */
private DataSpacesFileObject doResolveFile(final DataSpacesURI uri, final String ownerActiveObjectId,
        String spaceRootFOUri) throws FileSystemException {

    DataSpacesURI spacePart = uri.getSpacePartOnly();

    if (spaceRootFOUri != null) {
        ensureFileSystemIsMounted(spacePart, spaceRootFOUri);
    } else {
        try {
            readLock.lock();
            LinkedHashSet<String> los = accessibleFileObjectUris.get(spacePart);
            spaceRootFOUri = los.iterator().next();
        } finally {
            readLock.unlock();
        }
        ensureFileSystemIsMounted(spacePart, spaceRootFOUri);
    }

    final String relativeToSpace = uri.getRelativeToSpace();
    try {
        readLock.lock();

        if (!mountedSpaces.containsKey(spacePart)) {
            throw new FileSystemException("Could not access file that should exist (be mounted)");
        }

        final ConcurrentHashMap<String, FileObject> spaceRoots = mountedSpaces.get(spacePart);
        FileObject spaceRoot = spaceRoots.get(spaceRootFOUri);
        FileName dataSpaceVFSFileName = null;

        final FileObject file;
        // the dataspace "File name" (it is actually a File Path) is computed using the Virtual Space root
        if (dataSpaceVFSFileName == null) {
            dataSpaceVFSFileName = spaceRoot.getName();
        }
        try {
            if (relativeToSpace == null)
                file = spaceRoot;
            else
                file = spaceRoot.resolveFile(relativeToSpace);
            final DataSpacesLimitingFileObject limitingFile = new DataSpacesLimitingFileObject(file, spacePart,
                    spaceRoot.getName(), ownerActiveObjectId);
            return new VFSFileObjectAdapter(limitingFile, spacePart, dataSpaceVFSFileName,
                    new ArrayList<String>(accessibleFileObjectUris.get(spacePart)), spaceRootFOUri, this,
                    ownerActiveObjectId);
        } catch (org.apache.commons.vfs.FileSystemException x) {
            logger.error("[VFSMountManager] Could not access file within a space: " + uri);

            throw new FileSystemException(x);
        } catch (FileSystemException e) {
            ProActiveLogger.logImpossibleException(logger, e);
            throw new ProActiveRuntimeException(e);
        }

    } finally {
        readLock.unlock();
    }
}

From source file:com.geewhiz.pacify.TestArchive.java

@Test
public void checkUnkownArchiveType() {
    String testFolder = "testArchive/wrong/unkownArchiveType";

    LinkedHashSet<Defect> defects = createPrepareValidateAndReplace(testFolder,
            createPropertyResolveManager(propertiesToUseWhileResolving));

    Assert.assertEquals("We should get a defect.", 1, defects.size());
    Assert.assertEquals("We expect ArchiveTypeNotImplementedDefect", ArchiveTypeNotImplementedDefect.class,
            defects.iterator().next().getClass());
}

From source file:com.geewhiz.pacify.TestArchive.java

@Test
public void checkDuplicateArchiveEntry() {
    String testFolder = "testArchive/wrong/duplicateEntry";

    LinkedHashSet<Defect> defects = createPrepareAndExecuteValidator(testFolder,
            createPropertyResolveManager(propertiesToUseWhileResolving));

    Assert.assertEquals("We should get a defect.", 1, defects.size());
    Assert.assertEquals("We expect ArchiveTypeNotImplementedDefect",
            ArchiveDuplicateDefinedInPMarkerDefect.class, defects.iterator().next().getClass());
}

From source file:therian.operator.copy.ContainerCopierTest.java

@Test
public void testSingletonToEmptySet() {
    final LinkedHashSet<Book> targetValue = new LinkedHashSet<>();
    final Position.Readable<Set<Book>> target = Positions.readOnly(LocalTypes.SET_OF_BOOK, targetValue);
    therianContext.eval(Copy.to(target, Positions.readOnly(books[0])));
    assertSame(targetValue, target.getValue());
    assertEquals(1, targetValue.size());
    assertEquals(books[0], targetValue.iterator().next());
}

From source file:org.fusesource.mop.support.Database.java

public void install(final LinkedHashSet<String> artifiactIds) throws IOException {
    if (artifiactIds.isEmpty()) {
        throw new IllegalArgumentException("artifiactIds cannot be empty");
    }//from   w  w  w .  j  a va  2  s.  c  om
    final String mainArtifact = artifiactIds.iterator().next();

    assertOpen();
    pageFile.tx().execute(new Transaction.Closure<IOException>() {
        public void execute(Transaction tx) throws IOException {
            RootEntity root = RootEntity.load(tx);
            BTreeIndex<String, HashSet<String>> artifacts = root.artifacts.get(tx);
            BTreeIndex<String, HashSet<String>> artifactIdIndex = root.artifactIdIndex.get(tx);
            BTreeIndex<String, HashSet<String>> typeIndex = root.typeIndex.get(tx);
            BTreeIndex<String, HashSet<String>> explicityInstalledArtifacts = root.explicityInstalledArtifacts
                    .get(tx);

            explicityInstalledArtifacts.put(tx, mainArtifact, new LinkedHashSet<String>(artifiactIds));
            for (String id : artifiactIds) {
                ArtifactId a = ArtifactId.strictParse(id);
                if (a == null) {
                    throw new IOException("Invalid artifact id: " + id);
                }
                HashSet<String> rc = artifacts.get(tx, id);
                if (rc == null) {
                    rc = new HashSet<String>();
                }
                rc.add(mainArtifact);
                artifacts.put(tx, id, rc);
                indexAdd(tx, artifactIdIndex, id, a.getArtifactId());
                indexAdd(tx, typeIndex, id, a.getType());
            }

            root.tx_sequence++;
            root.store(tx);
        }
    });
}

From source file:alma.acs.tmcdb.compare.TestHighLevelNodes.java

/**
 * Searches dao for all potential (nodes containing Name attribute) ComponentInfo nodes.
 * @param dc   dao to be searched./*from   w w w  .  j a va  2  s.c o m*/
 * @returns list of all potential ComponentInfo nodes.
 */
private String[] retrieveComponentsList(CDBAccess cdbAccess) {
    ArrayList<String> componentList = new ArrayList<String>();

    try {
        DAOProxy dc = cdbAccess.createDAO("MACI/Components");
        LinkedHashSet<String> nodes = new LinkedHashSet<String>();
        // current
        nodes.add("");
        String[] subnodes = cdbAccess.getSubNodes(dc);
        if (subnodes != null)
            for (int i = 0; i < subnodes.length; i++)
                nodes.add(subnodes[i]);

        Iterator<String> iter = nodes.iterator();
        while (iter.hasNext()) {
            String prefix = iter.next().toString();
            if (prefix.length() > 0)
                prefix += "/";
            String attributes = dc.get_field_data(prefix + "_characteristics");

            // convert into array
            StringTokenizer tokenizer = new StringTokenizer(attributes, ",");
            while (tokenizer.hasMoreTokens()) {
                String subname = tokenizer.nextToken().toString();
                String componentName = prefix + subname;

                // check if potentially valid ComponentInfo entry - read name
                /// @todo this could be done better (to check if all attributes exist)
                if (readStringCharacteristics(dc, componentName + "/Name", true) != null)
                    componentList.add(componentName);
            }
        }

    } catch (Throwable th) {
        Exception ce = new Exception("Failed to obtain list of all components.", th);
        logger.log(Level.WARNING, ce.getMessage(), ce);
    }

    String[] retVal = new String[componentList.size()];
    componentList.toArray(retVal);

    //logger.log(Level.INFO,"Found " + retVal.length + " component entries in the configuration database.");

    return retVal;
}

From source file:com.redhat.rhn.frontend.action.token.configuration.RankChannelsAction.java

/**
 * Sets up the rangling widget./*from ww w  .  java  2s . c o  m*/
 * @param context the request context of the current request
 * @param form the dynaform  related to the current request.
 * @param set the set holding the channel ids.
 */
private void setupWidget(RequestContext context, DynaActionForm form, Set<String> set) {
    LinkedHashSet labelValues = new LinkedHashSet();
    populateWidgetLabels(labelValues, context);
    for (String id : set) {
        Long ccid = Long.valueOf(id);
        ConfigChannel channel = ConfigurationFactory.lookupConfigChannelById(ccid);
        labelValues.add(lv(channel.getName(), channel.getId().toString()));
    }

    //set the form variables for the widget to read.
    form.set(POSSIBLE_CHANNELS, labelValues);
    if (!labelValues.isEmpty()) {
        if (form.get(SELECTED_CHANNEL) == null) {
            String selected = ((LabelValueBean) labelValues.iterator().next()).getValue();
            form.set(SELECTED_CHANNEL, selected);
        }
    }
}

From source file:com.redhat.rhn.frontend.action.configuration.BaseRankChannels.java

/**
 * Sets up the rangling widget./*ww  w .  j ava 2s .  com*/
 * @param context the request context of the current request
 * @param form the dynaform  related to the current request.
 * @param set the rhnset holding the channel ids.
 */
protected void setupWidget(RequestContext context, DynaActionForm form, RhnSet set) {
    User user = context.getCurrentUser();
    LinkedHashSet labelValues = new LinkedHashSet();
    populateWidgetLabels(labelValues, context);
    for (Iterator itr = set.getElements().iterator(); itr.hasNext();) {
        Long ccid = ((RhnSetElement) itr.next()).getElement();
        ConfigChannel channel = ConfigurationManager.getInstance().lookupConfigChannel(user, ccid);
        labelValues.add(lv(channel.getName(), channel.getId().toString()));
    }

    //set the form variables for the widget to read.
    form.set(POSSIBLE_CHANNELS, labelValues);
    if (!labelValues.isEmpty()) {
        if (form.get(SELECTED_CHANNEL) == null) {
            String selected = ((LabelValueBean) labelValues.iterator().next()).getValue();
            form.set(SELECTED_CHANNEL, selected);
        }
    }
}

From source file:org.chromium.content_shell.Shell.java

private void updateHistory(String url) {
    String json = mPref.getString("history", null);
    JSONArray array = new JSONArray();
    if (json != null) {
        try {/*from  w  w w.  j ava  2s.c  om*/
            array = new JSONArray(json);
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    LinkedHashSet<String> history = new LinkedHashSet<String>();
    for (int i = 0; i < array.length(); i++) {
        try {
            history.add(array.getString(i));
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    if (history.contains(url)) {
        history.remove(url);
    }
    history.add(url);
    if (history.size() > 100) {
        String f = history.iterator().next();
        history.remove(f);
    }
    array = new JSONArray();
    for (String u : history) {
        array.put(u);
    }

    mPref.edit().putString("history", array.toString()).commit();
}

From source file:solidbase.core.UpgradeProcessor.java

/**
 * Perform upgrade to the given target version. The target version can end with an '*', indicating whatever tip version that
 * matches the target prefix./*from   w  ww. ja v a 2 s. c  o  m*/
 *
 * @param target The target requested.
 * @param downgradeable Indicates that downgrade paths are allowed to reach the given target.
 * @throws SQLExecutionException When the execution of a command throws an {@link SQLException}.
 */
protected void upgrade(String target, boolean downgradeable) throws SQLExecutionException {
    setupControlTables();

    String version = this.dbVersion.getVersion();

    if (target == null) {
        LinkedHashSet<String> targets = getTargets(true, null, downgradeable);
        if (targets.size() > 1)
            throw new FatalException("More than one possible target found, you should specify a target.");
        Assert.notEmpty(targets);

        target = targets.iterator().next();
    } else if (target.endsWith("*")) {
        String targetPrefix = target.substring(0, target.length() - 1);
        LinkedHashSet<String> targets = getTargets(true, targetPrefix, downgradeable);
        if (targets.size() > 1)
            throw new FatalException("More than one possible target found for " + target);
        if (targets.isEmpty())
            throw new FatalException("Target " + target + " is not reachable from version "
                    + StringUtils.defaultString(version, "<no version>"));

        target = targets.iterator().next();
    } else {
        LinkedHashSet<String> targets = getTargets(false, null, downgradeable);
        Assert.notEmpty(targets);

        // TODO Refactor this, put this in getTargets()
        boolean found = false;
        for (String t : targets)
            if (ObjectUtils.equals(t, target)) {
                found = true;
                break;
            }

        if (!found)
            throw new FatalException("Target " + target + " is not reachable from version "
                    + StringUtils.defaultString(version, "<no version>"));
    }

    if (ObjectUtils.equals(target, version)) {
        this.progress.noUpgradeNeeded();
        return;
    }

    upgrade(version, target, downgradeable);
}