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:cn.fql.utility.ClassUtility.java

/**
 * Import data to this object from input Map
 *
 * @param obj    object//from   w  w w  .j a v a  2s  . com
 * @param values <code>values</code>
 */
public static void importValueFromMap(Object obj, Map values) {
    if (values != null) {
        PropertyDescriptor[] pds;
        try {
            pds = exportPropertyDesc(obj.getClass());
            if (pds != null && pds.length > 0) {
                Set keySet = values.keySet();
                Iterator it = keySet.iterator();
                while (it.hasNext()) {
                    String name = (String) it.next();
                    for (int i = 0; i < pds.length; i++) {
                        PropertyDescriptor pd = pds[i];
                        if (pd.getName().equals(name)) {
                            Method setter = pd.getWriteMethod();
                            if (setter != null) {
                                Object[] params = { values.get(name) };
                                setter.invoke(obj, params);
                            }
                            break;
                        }
                    }
                }
            }
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }
}

From source file:com.anyi.gp.license.RegisterTools.java

public static String getKeyString(String encodeType) {
    StringBuffer sb = new StringBuffer();
    sb.append("Host[" + getHostName() + "];");
    sb.append("Ip[");
    Set entrySet = getInetAddresses().entrySet();
    java.util.Map.Entry entry;/*from   www  .  j  a v a  2  s  .  co m*/
    for (Iterator iterator = entrySet.iterator(); iterator.hasNext(); sb.append(entry.getValue() + ",")) {
        entry = (java.util.Map.Entry) iterator.next();
    }

    if (!entrySet.isEmpty()) {
        sb = new StringBuffer(sb.substring(0, sb.length() - 1));
    }
    sb.append("];");
    sb.append("ENCODETYPE[" + encodeType + "];");
    sb.append("Mac[");
    List macList = getMacAddresses();
    for (int i = 0; i < macList.size(); i++) {
        if (i != 0) {
            sb.append(",");
        }
        sb.append(macList.get(i));
    }

    sb.append("]");
    return sb.toString();
}

From source file:cc.flydev.launcher.InstallShortcutReceiver.java

public static void removeFromInstallQueue(SharedPreferences sharedPrefs, ArrayList<String> packageNames) {
    synchronized (sLock) {
        Set<String> strings = sharedPrefs.getStringSet(APPS_PENDING_INSTALL, null);
        if (DBG) {
            Log.d(TAG, "APPS_PENDING_INSTALL: " + strings + ", removing packages: " + packageNames);
        }/*w  w  w.  j  a v a2  s. com*/
        if (strings != null) {
            Set<String> newStrings = new HashSet<String>(strings);
            Iterator<String> newStringsIter = newStrings.iterator();
            while (newStringsIter.hasNext()) {
                String json = newStringsIter.next();
                try {
                    JSONObject object = (JSONObject) new JSONTokener(json).nextValue();
                    Intent launchIntent = Intent.parseUri(object.getString(LAUNCH_INTENT_KEY), 0);
                    String pn = launchIntent.getPackage();
                    if (pn == null) {
                        pn = launchIntent.getComponent().getPackageName();
                    }
                    if (packageNames.contains(pn)) {
                        newStringsIter.remove();
                    }
                } catch (org.json.JSONException e) {
                    Log.d(TAG, "Exception reading shortcut to remove: " + e);
                } catch (java.net.URISyntaxException e) {
                    Log.d(TAG, "Exception reading shortcut to remove: " + e);
                }
            }
            sharedPrefs.edit().putStringSet(APPS_PENDING_INSTALL, new HashSet<String>(newStrings)).commit();
        }
    }
}

From source file:com.conwet.silbops.model.Constraint.java

/**
 * Deserialize from a JSON representation
 *
 * @param json JSON representation/*from  w w  w .j  av  a 2s. co  m*/
 * @return A new constraint
 */
public static Constraint fromJSON(JSONObject json) {

    @SuppressWarnings("unchecked")
    Set<Map.Entry<String, Object>> entries = json.entrySet();

    if (entries.size() != 1) {

        throw new IllegalArgumentException("Malformed object: " + json);
    }

    Entry<String, Object> entry = entries.iterator().next();
    Operator operator = Operator.fromJSON(entry.getKey());
    return (operator == Operator.EXISTS) ? EXIST : new Constraint(operator, Value.fromJSON(entry.getValue()));
}

From source file:com.adaptris.core.XStreamMarshallerTest.java

public static void adapterInstanceFieldChecks(Adapter fromXML) {
    assertNotNull(fromXML);/*from  ww w  . ja va  2 s . c o  m*/
    assertEquals("SimpleAdapterTest", fromXML.getUniqueId());
    assertTrue(fromXML.logHandler() instanceof NullLogHandler);

    assertTrue(fromXML.getEventHandler() instanceof DefaultEventHandler);
    assertTrue(((DefaultEventHandler) fromXML.getEventHandler()).getConnection() instanceof NullConnection);
    assertTrue(((DefaultEventHandler) fromXML.getEventHandler()).getProducer() instanceof NullMessageProducer);
    // ShutdownWaitSeconds is now null.
    assertNull(((DefaultEventHandler) fromXML.getEventHandler()).getShutdownWaitSeconds());

    assertTrue(fromXML.getMessageErrorHandler() instanceof NullProcessingExceptionHandler);

    Channel channel = fromXML.getChannelList().get(0);
    assertTrue(channel.getConsumeConnection() instanceof NullConnection);
    assertTrue(channel.getProduceConnection() instanceof NullConnection);

    // Check workflow
    WorkflowList workflowList = channel.getWorkflowList();
    assertNotNull(workflowList);
    assertEquals(1, workflowList.size());
    // test workflow
    StandardWorkflow standardWorkflow = (StandardWorkflow) workflowList.get(0);
    assertNotNull(standardWorkflow);
    assertEquals("workflow1", standardWorkflow.getUniqueId());
    // test workflow consumer
    AdaptrisMessageConsumer consumer = standardWorkflow.getConsumer();
    assertNotNull(consumer);
    ConsumeDestination destination = consumer.getDestination();
    assertNotNull(destination);
    assertTrue(destination instanceof ConfiguredConsumeDestination);
    assertEquals("dummy", destination.getDestination());

    // test services
    ServiceCollection serviceCollection = standardWorkflow.getServiceCollection();
    assertNotNull(serviceCollection);
    assertEquals("serviceListID1", serviceCollection.getUniqueId());
    assertEquals(3, serviceCollection.size());
    assertTrue(serviceCollection instanceof ServiceList);
    // test service 1
    Service service1 = serviceCollection.get(0);
    assertEquals("serviceID1", service1.getUniqueId());
    assertTrue(service1 instanceof AddMetadataService);
    Set<MetadataElement> metadataElements = ((AddMetadataService) service1).getMetadataElements();
    assertEquals(1, metadataElements.size());
    for (Iterator<MetadataElement> iterator = metadataElements.iterator(); iterator.hasNext();) {
        MetadataElement metadataElement = (MetadataElement) iterator.next();
        assertEquals("key1", metadataElement.getKey());
        assertEquals("val1", metadataElement.getValue());
        break;
    }

    // test service 2
    Service service2 = serviceCollection.get(1);
    assertEquals("serviceID2", service2.getUniqueId());
    assertTrue(service2 instanceof XpathMetadataService);
    List<XpathQuery> xpathQueries = ((XpathMetadataService) service2).getXpathQueries();
    assertEquals(1, xpathQueries.size());
    assertEquals(ConfiguredXpathQuery.class, xpathQueries.get(0).getClass());
    assertEquals("/a/b/c", ((ConfiguredXpathQuery) xpathQueries.get(0)).getXpathQuery());

    // Test service3
    Service service3 = serviceCollection.get(2);
    assertEquals("serviceID3", service3.getUniqueId());
    assertTrue(service3 instanceof LogMessageService);
    assertTrue(StringUtils.isBlank(((LogMessageService) service3).getLogPrefix()));
    assertFalse(((LogMessageService) service3).getIncludeEvents());
    assertTrue(((LogMessageService) service3).getIncludePayload());
}

From source file:grails.plugin.searchable.internal.lucene.LuceneUtils.java

/**
 * Returns an array of {@link Term}s by parsing the given query string. Since Lucene's query parser is used,
 * special query characters and words (OR / AND) are not included in the returned terms
 *
 * @param defaultField The default term field, cannot be null
 * @param queryString the query string to parse, cannot be null
 * @param analyzer the Analyzer instance, may be null in which case Lucene's StandardAnalyzer is used
 * @return the Term array (field + term pairs)
 * @throws org.apache.lucene.queryParser.ParseException if the the query has invalid syntax
 *///  w w w.j  av a 2 s .co  m
public static Term[] realTermsForQueryString(String defaultField, String queryString, Analyzer analyzer)
        throws ParseException {
    Assert.notNull(defaultField, "defaultField cannot be null");
    Assert.notNull(queryString, "queryString cannot be null");
    if (analyzer == null) {
        analyzer = new StandardAnalyzer();
    }
    QueryParser queryParser = new QueryParser(defaultField, analyzer);
    Query query = queryParser.parse(queryString);
    Set terms = new ListNotSet();
    query.extractTerms(terms);
    Term[] termsArray = new Term[terms.size()];
    int i = 0;
    for (Iterator iter = terms.iterator(); iter.hasNext();) {
        Term term = (Term) iter.next();
        termsArray[i++] = term;
    }
    return termsArray;
}

From source file:grails.plugin.searchable.internal.lucene.LuceneUtils.java

/**
 * Returns a list of terms by parsing the given query string - special query characters and words (OR/AND) are
 * not included in the returned list/*from www  .  j  a  v  a 2 s.c  om*/
 *
 * @param queryString the query string to parse
 * @param analyzer the Analyzer instance, may be null in which case Lucene's StandardAnalyzer is used
 * @return a list of text terms
 * @throws org.apache.lucene.queryParser.ParseException if the query is invalid
 */
public static String[] termsForQueryString(String queryString, Analyzer analyzer) throws ParseException {
    if (analyzer == null) {
        analyzer = new StandardAnalyzer();
    }
    final String defaultField = "$termsForQueryString_defaultField$";
    QueryParser queryParser = new QueryParser(defaultField, analyzer);
    Query query = queryParser.parse(queryString);
    Set terms = new ListNotSet();
    query.extractTerms(terms);
    String[] termsArray = new String[terms.size()];
    int i = 0;
    for (Iterator iter = terms.iterator(); iter.hasNext();) {
        termsArray[i++] = ((Term) iter.next()).text();
    }
    return termsArray;
}

From source file:SigningProcess.java

public static String sign(String base64, HashMap map) {
    String base64string = null;/*ww w.ja  v  a  2s.c  om*/
    try {
        System.out.println("map :" + map);
        // Getting a set of the entries
        Set set = map.entrySet();
        System.out.println("set :" + set);
        // Get an iterator
        Iterator it = set.iterator();
        // Display elements
        while (it.hasNext()) {
            Entry me = (Entry) it.next();
            String key = (String) me.getKey();
            if ("privateKey".equalsIgnoreCase(key)) {
                privateKey = (PrivateKey) me.getValue();
            }
            if ("certificateChain".equalsIgnoreCase(key)) {
                certificateChain = (X509Certificate[]) me.getValue();
            }
        }

        OcspClient ocspClient = new OcspClientBouncyCastle();
        TSAClient tsaClient = null;
        for (int i = 0; i < certificateChain.length; i++) {
            X509Certificate cert = (X509Certificate) certificateChain[i];
            String tsaUrl = CertificateUtil.getTSAURL(cert);
            if (tsaUrl != null) {
                tsaClient = new TSAClientBouncyCastle(tsaUrl);
                break;
            }
        }
        List<CrlClient> crlList = new ArrayList<CrlClient>();
        crlList.add(new CrlClientOnline(certificateChain));

        String property = System.getProperty("java.io.tmpdir");
        BASE64Decoder decoder = new BASE64Decoder();
        byte[] FileByte = decoder.decodeBuffer(base64);
        writeByteArraysToFile(property + "_unsigned.pdf", FileByte);

        // Creating the reader and the stamper
        PdfReader reader = new PdfReader(property + "_unsigned.pdf");
        FileOutputStream os = new FileOutputStream(property + "_signed.pdf");
        PdfStamper stamper = PdfStamper.createSignature(reader, os, '\0');
        // Creating the appearance
        PdfSignatureAppearance appearance = stamper.getSignatureAppearance();
        //            appearance.setReason(reason);
        //            appearance.setLocation(location);
        appearance.setAcro6Layers(false);
        appearance.setVisibleSignature(new Rectangle(36, 748, 144, 780), 1, "sig1");
        // Creating the signature
        ExternalSignature pks = new PrivateKeySignature((PrivateKey) privateKey, DigestAlgorithms.SHA256,
                providerMSCAPI.getName());
        ExternalDigest digest = new BouncyCastleDigest();
        MakeSignature.signDetached(appearance, digest, pks, certificateChain, crlList, ocspClient, tsaClient, 0,
                MakeSignature.CryptoStandard.CMS);

        InputStream docStream = new FileInputStream(property + "_signed.pdf");
        byte[] encodeBase64 = Base64.encodeBase64(IOUtils.toByteArray(docStream));
        base64string = new String(encodeBase64);
    } catch (IOException ex) {
        System.out.println("Exception :" + ex.getLocalizedMessage());
    } catch (DocumentException ex) {
        System.out.println("Exception :" + ex.getLocalizedMessage());
    } catch (GeneralSecurityException ex) {
        System.out.println("Exception :" + ex.getLocalizedMessage());
    }
    return base64string;
}

From source file:JsonParser.ParseJson.java

public static void dumpJSONElement(JsonElement element, String type) {
    if (element.isJsonObject()) {
        //System.out.println("Is an object");
        JsonObject obj = element.getAsJsonObject();
        java.util.Set<java.util.Map.Entry<String, JsonElement>> entries = obj.entrySet();
        java.util.Iterator<java.util.Map.Entry<String, JsonElement>> iter = entries.iterator();
        while (iter.hasNext()) {
            java.util.Map.Entry<String, JsonElement> entry = iter.next();
            //  System.out.println("Key: " + entry.getKey());
            if (entry.getKey().toString().equals("instances")) {
                System.out.println("............Topic: ");
                dumpJSONElement(entry.getValue(), "topic");

            }/*from  w  w  w. ja  va 2s  .c om*/
            if (entry.getKey().toString().equals("aspects")) {
                System.out.println("............aspects: ");
                dumpJSONElement(entry.getValue(), "aspect");

            } else if (entry.getKey().toString().equals("positives")) {
                System.out.println(".............Positive Words ");
                dumpJSONElement(entry.getValue(), "positive");
            } else if (entry.getKey().toString().equals("negatives")) {
                System.out.println(".............negatives Words ");
                dumpJSONElement(entry.getValue(), "negative");
            } else {
                dumpJSONElement(entry.getValue(), "");
            }

        }

    } else if (element.isJsonArray()) {
        JsonArray array = element.getAsJsonArray();
        //System.out.println("Is an array. Number of values: " + array.size());
        java.util.Iterator<JsonElement> iter = array.iterator();
        while (iter.hasNext()) {
            JsonElement entry = iter.next();

            dumpJSONElement(entry, "");
        }
    } else if (element.isJsonPrimitive()) {
        //System.out.println("Is a primitive");
        JsonPrimitive value = element.getAsJsonPrimitive();
        if (value.isBoolean()) {
            //System.out.println("Is boolean: " + value.getAsBoolean());
        } else if (value.isNumber()) {
            //  System.out.println("Is number: " + value.getAsNumber());
        } else if (value.isString()) {
            //if(!value.getAsString().equals("empty"))
            //{
            //if(type.equals("topic"))
            //{
            System.out.println(type + " :" + value.getAsString());
            //}
        }
    } else if (element.isJsonNull()) {
        System.out.println("Is NULL");
    } else {
        System.out.println("Error. Unknown type of element");
    }
}

From source file:gemlite.core.internal.index.IndexHelper.java

public final static List<String> listIndex(String regionName) {
    List<String> indexList = new ArrayList<String>();
    GemliteIndexContext topIdxContext = GemliteContext.getTopIndexContext();
    Set<IndexRegion> indexNames = topIdxContext.getIndexNamesByRegion(regionName);
    if (indexNames != null) {
        for (Iterator<IndexRegion> it = indexNames.iterator(); it.hasNext();) {
            IndexRegion index = it.next();
            if (!index.isRegion())
                indexList.add(index.indexName());
            else//from www  . j a va2s  .co m
                indexList.add(index.indexName() + "(Hash Index)");
        }
    }
    return indexList;
}