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:org.agiso.core.lang.util.ClassUtils.java

/**
 * Wyszukuje dla wskazanej klasy publiczn metod o okrelonej sygnaturze. Jeli
 * metoda nie zostanie naleziona zwraca {@code null}.
 * <p>W przypadku gdy nie jest okrelona tablica parametrw wywoania, zwraca metod
 * tylko gdy wynik wyszukiwania jest unikatowy, tj. istnieje tylko jedna publiczna
 * metoda o wskazanej nazwie./*from w  ww .  ja  v  a  2 s  . c  o m*/
 * 
 * <p>Based on:
 * org.springframework.util.ClassUtils.getMethodIfAvailable(Class<?>, String, Class<?>...)
 * 
 * @param clazz Klasa do sprawdzenia
 * @param methodName Nazwa wyszukiwanej metody
 * @param paramTypes Tablica typw parametrw wywoania metody
 *     (moe by {@code null} w celu wyszukania dowolnej metody o wskazanej nazwie)
 * @return Znaleziona metoda lub @{code null} gdy nie istnieje lub nie jest unikatowa
 * @see Class#getMethod
 */
public static Method getMethodIfAvailable(Class<?> clazz, String methodName, Class<?>... paramTypes) {
    if (clazz == null) {
        throw new NullPointerException("Klasa musi by okrelona");
    }
    if (methodName == null) {
        throw new NullPointerException("Nazwa metody musi by okrelona");
    }

    if (paramTypes != null) {
        try {
            return clazz.getMethod(methodName, paramTypes);
        } catch (NoSuchMethodException ex) {
            return null;
        }
    } else {
        Set<Method> candidates = new HashSet<Method>(1);
        Method[] methods = clazz.getMethods();
        for (Method method : methods) {
            if (methodName.equals(method.getName())) {
                candidates.add(method);
            }
        }
        if (candidates.size() == 1) {
            return candidates.iterator().next();
        }
        return null;
    }
}

From source file:gov.tva.sparky.util.indexer.IndexingAgent.java

public static void Index_HDFS_File(String strHdfsPath) throws Exception {

    LOG.info("Indexing File: " + strHdfsPath);

    long lBytesUploaded = 0;
    int iBucketsUpdated = 0;
    boolean bExistsAlreadyInRegistry = false;
    String strHBaseRegistryFileID = "";
    int iHBaseRegistryFileID = -1;
    HistorianArchiveLookupTable oLookupTable = new HistorianArchiveLookupTable();

    try {/*from  w w w.ja va2 s . c o  m*/

        strHBaseRegistryFileID = oLookupTable.Lookup_FileID_byPath(strHdfsPath);
        System.out.println("Found File ID: " + strHBaseRegistryFileID + " For Path: " + strHdfsPath);
        bExistsAlreadyInRegistry = true;

    } catch (Exception e) {

        bExistsAlreadyInRegistry = false;

    }

    // if its not already registered, register it

    if (!bExistsAlreadyInRegistry) {

        try {
            HistorianArchiveLookupTable.InsertEntryInto_Hbase_LookupTables(strHdfsPath);
            strHBaseRegistryFileID = oLookupTable.Lookup_FileID_byPath(strHdfsPath);
            iHBaseRegistryFileID = HistorianArchiveLookupTableEntry.GetIntFromBytes(strHBaseRegistryFileID);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            strHBaseRegistryFileID = "";
        }

    }

    if (strHBaseRegistryFileID.equals("") || iHBaseRegistryFileID < 0) {
        throw new Exception("Unable to register hdfs file in Index Registry!");
    }

    // We need to group each range of block pointers into buckets
    FileIndex archive_index = new FileIndex(strHdfsPath, iHBaseRegistryFileID);
    HashMap<String, PriorityQueue<HDFSPointBlockPointer>> map = archive_index.GetKeyMap();

    //int iPass = 0;
    Set<String> Keys = map.keySet();
    Iterator It = Keys.iterator();
    while (It.hasNext()) {
        //        if (It.hasNext()) {
        String key_str = (String) (It.next());
        IndexBucket oBucket = new IndexBucket(map.get(key_str));
        lBytesUploaded += oBucket.GetSerializedByteSize();

        HBaseRestInterface.Update_HDFS_FileIndex(oBucket);

        iBucketsUpdated++;

    }

    // log summary stats...

    LOG.info("Indexer > Summary > Total Bytes Uploaded: " + lBytesUploaded + ", Buckets Updated: "
            + iBucketsUpdated);

}

From source file:com.haulmont.cuba.gui.components.filter.UserSetHelper.java

public static String createIdsString(Set<String> current, Collection entities) {
    Set<String> convertedSet = new HashSet<>();
    for (Object entity : entities) {
        convertedSet.add(((BaseUuidEntity) entity).getId().toString());
    }/*from   w w  w . j a v  a2  s.  co  m*/
    current.addAll(convertedSet);
    if (current.isEmpty()) {
        return "NULL";
    }
    StringBuilder listOfId = new StringBuilder();
    Iterator it = current.iterator();
    while (it.hasNext()) {
        listOfId.append(it.next());
        if (it.hasNext()) {
            listOfId.append(',');
        }
    }
    return listOfId.toString();
}

From source file:com.marlonjones.voidlauncher.InstallShortcutReceiver.java

public static void removeFromInstallQueue(Context context, HashSet<String> packageNames,
        UserHandleCompat user) {//from ww w.j a  v  a  2  s .  c  om
    if (packageNames.isEmpty()) {
        return;
    }
    SharedPreferences sp = Utilities.getPrefs(context);
    synchronized (sLock) {
        Set<String> strings = sp.getStringSet(APPS_PENDING_INSTALL, null);
        if (DBG) {
            Log.d(TAG, "APPS_PENDING_INSTALL: " + strings + ", removing packages: " + packageNames);
        }
        if (strings != null) {
            Set<String> newStrings = new HashSet<String>(strings);
            Iterator<String> newStringsIter = newStrings.iterator();
            while (newStringsIter.hasNext()) {
                String encoded = newStringsIter.next();
                PendingInstallShortcutInfo info = decode(encoded, context);
                if (info == null
                        || (packageNames.contains(info.getTargetPackage()) && user.equals(info.user))) {
                    newStringsIter.remove();
                }
            }
            sp.edit().putStringSet(APPS_PENDING_INSTALL, newStrings).apply();
        }
    }
}

From source file:org.agiso.core.lang.util.ClassUtils.java

/**
 * Wyszukuje dla wskazanej klasy publiczn metod o okrelonej sygnaturze. Jeli
 * metoda nie zostanie naleziona wyrzuca wyjtek {@code IllegalStateException}.
 * <p>W przypadku gdy nie jest okrelona tablica parametrw wywoania, zwraca metod
 * tylko gdy wynik wyszukiwania jest unikatowy, tj. istnieje tylko jedna publiczna
 * metoda o wskazanej nazwie.//from  w w  w . j  a v a 2s .c o m
 * 
 * <p>Based on:
 * org.springframework.util.ClassUtils.getMethod(Class<?>, String, Class<?>...)
 * 
 * @param clazz Klasa do sprawdzenia
 * @param methodName Nazwa wyszukiwanej metody
 * @param paramTypes Tablica typw parametrw wywoania metody
 *     (moe by {@code null} w celu wyszukania dowolnej metody o wskazanej nazwie)
 * @return Znaleziona metoda (niegdy {@code null})
 * @throws IllegalStateException jeli nie znaleziono metody lub nie jest unikatowa
 * @see Class#getMethod
 */
public static Method getMethod(Class<?> clazz, String methodName, Class<?>... paramTypes) {
    if (clazz == null) {
        throw new NullPointerException("Klasa musi by okrelona");
    }
    if (methodName == null) {
        throw new NullPointerException("Nazwa metody musi by okrelona");
    }

    if (paramTypes != null) {
        try {
            return clazz.getMethod(methodName, paramTypes);
        } catch (NoSuchMethodException ex) {
            throw new IllegalStateException("Expected method not found: " + ex);
        }
    } else {
        Set<Method> candidates = new HashSet<Method>(1);
        Method[] methods = clazz.getMethods();
        for (Method method : methods) {
            if (methodName.equals(method.getName())) {
                candidates.add(method);
            }
        }
        if (candidates.size() == 1) {
            return candidates.iterator().next();
        } else if (candidates.isEmpty()) {
            throw new IllegalStateException("Expected method not found: " + clazz + "." + methodName);
        } else {
            throw new IllegalStateException("No unique method found: " + clazz + "." + methodName);
        }
    }
}

From source file:org.eclipse.gemini.blueprint.test.internal.util.PropertiesUtil.java

/**
 * Apply placeholder expansion to the given properties object.
 * //from   www.j  a v  a 2s.  co  m
 * Will return a new properties object, containing the expanded entries. Note that both keys and values will be
 * expanded.
 * 
 * @param props
 * @return
 */
public static Properties expandProperties(Properties props) {
    Assert.notNull(props);

    Set entrySet = props.entrySet();

    Properties newProps = (props instanceof OrderedProperties ? new OrderedProperties() : new Properties());

    for (Iterator iter = entrySet.iterator(); iter.hasNext();) {
        // first expand the keys
        Map.Entry entry = (Map.Entry) iter.next();
        String key = (String) entry.getKey();
        String value = (String) entry.getValue();

        String resultKey = expandProperty(key, props);
        String resultValue = expandProperty(value, props);

        // replace old entry

        newProps.put(resultKey, resultValue);
    }

    return newProps;
}

From source file:com.haulmont.cuba.gui.components.filter.UserSetHelper.java

public static String removeIds(Set<String> current, Collection entities) {
    Set<String> convertedSet = new HashSet<>();
    for (Object entity : entities) {
        convertedSet.add(((BaseUuidEntity) entity).getId().toString());
    }/*from  www  . jav a  2 s.c  o  m*/
    current.removeAll(convertedSet);
    if (current.isEmpty()) {
        return "NULL";
    }
    StringBuilder listOfId = new StringBuilder();
    Iterator it = current.iterator();
    while (it.hasNext()) {
        listOfId.append(it.next());
        if (it.hasNext()) {
            listOfId.append(',');
        }
    }
    return listOfId.toString();
}

From source file:eu.stratosphere.nephele.jobmanager.scheduler.RecoveryLogic.java

private static final boolean invalidateReceiverLookupCaches(final ExecutionVertex failedVertex,
        final Set<ExecutionVertex> verticesToBeCanceled) {

    final Map<AbstractInstance, Set<ChannelID>> entriesToInvalidate = new HashMap<AbstractInstance, Set<ChannelID>>();

    collectCacheEntriesToInvalidate(failedVertex, entriesToInvalidate);
    for (final Iterator<ExecutionVertex> it = verticesToBeCanceled.iterator(); it.hasNext();) {
        collectCacheEntriesToInvalidate(it.next(), entriesToInvalidate);
    }/*  w  w  w  .j a v  a2 s. com*/

    final Iterator<Map.Entry<AbstractInstance, Set<ChannelID>>> it = entriesToInvalidate.entrySet().iterator();

    while (it.hasNext()) {

        final Map.Entry<AbstractInstance, Set<ChannelID>> entry = it.next();
        final AbstractInstance instance = entry.getKey();

        try {
            instance.invalidateLookupCacheEntries(entry.getValue());
        } catch (IOException ioe) {
            LOG.error(StringUtils.stringifyException(ioe));
            return false;
        }
    }

    return true;
}

From source file:io.github.swagger2markup.MarkdownConverterTest.java

/**
 * Given a markdown document to search, this checks to see if the specified tables
 * have all of the expected fields listed.
 * Match is a "search", and not an "equals" match.
 *
 * @param doc           markdown document file to inspect
 * @param fieldsByTable map of table name (header) to field names expected
 *                      to be found in that table.
 * @throws IOException if the markdown document could not be read
 *//*from   w w w .  ja  v  a  2 s . c o  m*/
private static void verifyMarkdownContainsFieldsInTables(File doc, Map<String, Set<String>> fieldsByTable)
        throws IOException {
    //TODO: This method is too complex, split it up in smaller methods to increase readability
    final List<String> lines = Files.readAllLines(doc.toPath(), Charset.defaultCharset());
    final Map<String, Set<String>> fieldsLeftByTable = Maps.newHashMap();
    for (Map.Entry<String, Set<String>> entry : fieldsByTable.entrySet()) {
        fieldsLeftByTable.put(entry.getKey(), Sets.newHashSet(entry.getValue()));
    }
    String inTable = null;
    for (String line : lines) {
        // If we've found every field we care about, quit early
        if (fieldsLeftByTable.isEmpty()) {
            return;
        }

        // Transition to a new table if we encounter a header
        final String currentHeader = getTableHeader(line);
        if (inTable == null || currentHeader != null) {
            inTable = currentHeader;
        }

        // If we're in a table that we care about, inspect this potential table row
        if (inTable != null && fieldsLeftByTable.containsKey(inTable)) {
            // If we're still in a table, read the row and check for the field name
            //  NOTE: If there was at least one pipe, then there's at least 2 fields
            String[] parts = line.split("\\|");
            if (parts.length > 1) {
                final String fieldName = parts[1];
                final Set<String> fieldsLeft = fieldsLeftByTable.get(inTable);
                // Mark the field as found and if this table has no more fields to find,
                //  remove it from the "fieldsLeftByTable" map to mark the table as done
                Iterator<String> fieldIt = fieldsLeft.iterator();
                while (fieldIt.hasNext()) {
                    String fieldLeft = fieldIt.next();
                    if (fieldName.contains(fieldLeft))
                        fieldIt.remove();
                }
                if (fieldsLeft.isEmpty()) {
                    fieldsLeftByTable.remove(inTable);
                }
            }
        }
    }

    // After reading the file, if there were still types, fail
    if (!fieldsLeftByTable.isEmpty()) {
        fail(String.format("Markdown file '%s' did not contain expected fields (by table): %s", doc,
                fieldsLeftByTable));
    }
}

From source file:eu.stratosphere.nephele.jobmanager.scheduler.RecoveryLogic.java

public static boolean recover(final ExecutionVertex failedVertex,
        final Map<ExecutionVertexID, ExecutionVertex> verticesToBeRestarted,
        final Set<ExecutionVertex> assignedVertices) {

    // Perform initial sanity check
    if (failedVertex.getExecutionState() != ExecutionState.FAILED) {
        LOG.error("Vertex " + failedVertex + " is requested to be recovered, but is not failed");
        return false;
    }//from   w w w. j a  v  a2 s  .c  o m

    final ExecutionGraph eg = failedVertex.getExecutionGraph();
    synchronized (eg) {

        LOG.info("Starting recovery for failed vertex " + failedVertex);

        final Set<ExecutionVertex> verticesToBeCanceled = new HashSet<ExecutionVertex>();

        findVerticesToRestart(failedVertex, verticesToBeCanceled);

        // Restart all predecessors without checkpoint
        final Iterator<ExecutionVertex> cancelIterator = verticesToBeCanceled.iterator();
        while (cancelIterator.hasNext()) {

            final ExecutionVertex vertex = cancelIterator.next();

            if (vertex.compareAndUpdateExecutionState(ExecutionState.FINISHED, getStateToUpdate(vertex))) {
                LOG.info("Vertex " + vertex + " has already finished and will not be canceled");
                if (vertex.getExecutionState() == ExecutionState.ASSIGNED) {
                    assignedVertices.add(vertex);
                }
                continue;
            }

            LOG.info(vertex + " is canceled by recovery logic");
            verticesToBeRestarted.put(vertex.getID(), vertex);
            final TaskCancelResult cancelResult = vertex.cancelTask();

            if (cancelResult.getReturnCode() != AbstractTaskResult.ReturnCode.SUCCESS
                    && cancelResult.getReturnCode() != AbstractTaskResult.ReturnCode.TASK_NOT_FOUND) {

                verticesToBeRestarted.remove(vertex.getID());
                LOG.error("Unable to cancel vertex" + cancelResult.getDescription());
                return false;
            }
        }

        LOG.info("Starting cache invalidation");

        // Invalidate the lookup caches
        if (!invalidateReceiverLookupCaches(failedVertex, verticesToBeCanceled)) {
            return false;
        }

        LOG.info("Cache invalidation complete");

        // Restart failed vertex
        failedVertex.updateExecutionState(getStateToUpdate(failedVertex));
        if (failedVertex.getExecutionState() == ExecutionState.ASSIGNED) {
            assignedVertices.add(failedVertex);
        }
    }

    return true;
}