Example usage for java.util HashSet toString

List of usage examples for java.util HashSet toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:Main.java

public static void addTaintInformationToIntent(Intent i, HashSet<String> taintCategories) {
    boolean intentHasNoExtras = i.getExtras() == null ? true : false;

    //A bit of limitation here, because we do only care about the extras
    if (!intentHasNoExtras) {
        Bundle extras = i.getExtras();// w ww.  java 2 s. c o m

        String taintKeyName = generateKeyNameForTaintInfo(extras.keySet());

        String taintInformation = null;

        if (taintCategories.size() > 1)
            taintInformation = taintCategories.toString().substring(1, taintCategories.toString().length() - 1);
        else
            taintInformation = taintCategories.iterator().next();

        i.putExtra(taintKeyName, taintInformation);
    }
}

From source file:Main.java

public static void addTaintInformationToIntent(Intent i, HashSet<String> taintCategories) {
    boolean intentHasNoExtras = i.getExtras() == null ? true : false;

    Log.i("PEP", "in addTaintInformationToIntent(Intent i, HashSet<String> taintCategories)");

    //A bit of limitation here, because we do only care about the extras
    if (!intentHasNoExtras) {
        Bundle extras = i.getExtras();//from www  .  jav a  2s  .c om

        String taintKeyName = generateKeyNameForTaintInfo(extras.keySet());

        String taintInformation = null;

        if (taintCategories.size() > 1)
            taintInformation = taintCategories.toString().substring(1, taintCategories.toString().length() - 1);
        else
            taintInformation = taintCategories.iterator().next();

        i.putExtra(taintKeyName, taintInformation);
    }
}

From source file:cm.confide.ex.chips.RecipientAlternatesAdapter.java

/**
 * Get a HashMap of address to RecipientEntry that contains all contact
 * information for a contact with the provided address, if one exists. This
 * may block the UI, so run it in an async task.
 *
 * @param context Context.//  w w w  . j a v a2s. c om
 * @param inAddresses Array of addresses on which to perform the lookup.
 * @param callback RecipientMatchCallback called when a match or matches are found.
 * @return HashMap<String,RecipientEntry>
 */
public static void getMatchingRecipients(Context context, BaseRecipientAdapter adapter,
        ArrayList<String> inAddresses, int addressType, Account account, RecipientMatchCallback callback) {
    Queries.Query query;
    if (addressType == QUERY_TYPE_EMAIL) {
        query = Queries.EMAIL;
    } else {
        query = Queries.PHONE;
    }
    int addressesSize = Math.min(MAX_LOOKUPS, inAddresses.size());
    HashSet<String> addresses = new HashSet<String>();
    StringBuilder bindString = new StringBuilder();
    // Create the "?" string and set up arguments.
    for (int i = 0; i < addressesSize; i++) {
        Rfc822Token[] tokens = Rfc822Tokenizer.tokenize(inAddresses.get(i).toLowerCase());
        addresses.add(tokens.length > 0 ? tokens[0].getAddress() : inAddresses.get(i));
        bindString.append("?");
        if (i < addressesSize - 1) {
            bindString.append(",");
        }
    }

    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "Doing reverse lookup for " + addresses.toString());
    }

    String[] addressArray = new String[addresses.size()];
    addresses.toArray(addressArray);
    HashMap<String, RecipientEntry> recipientEntries = null;
    Cursor c = null;

    try {
        c = context.getContentResolver().query(query.getContentUri(), query.getProjection(),
                query.getProjection()[Queries.Query.DESTINATION] + " IN (" + bindString.toString() + ")",
                addressArray, null);
        recipientEntries = processContactEntries(c);
        callback.matchesFound(recipientEntries);
    } finally {
        if (c != null) {
            c.close();
        }
    }
    // See if any entries did not resolve; if so, we need to check other
    // directories
    final Set<String> matchesNotFound = new HashSet<String>();
    if (recipientEntries.size() < addresses.size()) {
        final List<DirectorySearchParams> paramsList;
        Cursor directoryCursor = null;
        try {
            directoryCursor = context.getContentResolver().query(DirectoryListQuery.URI,
                    DirectoryListQuery.PROJECTION, null, null, null);
            if (directoryCursor == null) {
                paramsList = null;
            } else {
                paramsList = BaseRecipientAdapter.setupOtherDirectories(context, directoryCursor, account);
            }
        } finally {
            if (directoryCursor != null) {
                directoryCursor.close();
            }
        }
        // Run a directory query for each unmatched recipient.
        HashSet<String> unresolvedAddresses = new HashSet<String>();
        for (String address : addresses) {
            if (!recipientEntries.containsKey(address)) {
                unresolvedAddresses.add(address);
            }
        }

        matchesNotFound.addAll(unresolvedAddresses);

        if (paramsList != null) {
            Cursor directoryContactsCursor = null;
            for (String unresolvedAddress : unresolvedAddresses) {
                for (int i = 0; i < paramsList.size(); i++) {
                    try {
                        directoryContactsCursor = doQuery(unresolvedAddress, 1, paramsList.get(i).directoryId,
                                account, context.getContentResolver(), query);
                    } finally {
                        if (directoryContactsCursor != null && directoryContactsCursor.getCount() == 0) {
                            directoryContactsCursor.close();
                            directoryContactsCursor = null;
                        } else {
                            break;
                        }
                    }
                }
                if (directoryContactsCursor != null) {
                    try {
                        final Map<String, RecipientEntry> entries = processContactEntries(
                                directoryContactsCursor);

                        for (final String address : entries.keySet()) {
                            matchesNotFound.remove(address);
                        }

                        callback.matchesFound(entries);
                    } finally {
                        directoryContactsCursor.close();
                    }
                }
            }
        }
    }

    // If no matches found in contact provider or the directories, try the extension
    // matcher.
    // todo (aalbert): This whole method needs to be in the adapter?
    if (adapter != null) {
        final Map<String, RecipientEntry> entries = adapter.getMatchingRecipients(matchesNotFound);
        if (entries != null && entries.size() > 0) {
            callback.matchesFound(entries);
            for (final String address : entries.keySet()) {
                matchesNotFound.remove(address);
            }
        }
    }
    callback.matchesNotFound(matchesNotFound);
}

From source file:com.vaadin.tests.server.LicenseInJavaFiles.java

public void testJavaFilesContainsLicense() throws IOException {
    File srcDir = new File(SRC_DIR);
    System.out.println(new File(".").getAbsolutePath());
    HashSet<String> missing = new HashSet<String>();
    checkForLicense(srcDir, missing);/*  w w  w.  jav a 2s  .  c o m*/
    if (!missing.isEmpty()) {
        throw new RuntimeException(
                "The following files are missing license information:\n" + missing.toString());
    }
}

From source file:util.LdapUtil.java

/**
* removeElements() remove the elements from list1 that are in list2 and return list1.
* @param list1 remove the elements that contains in the list2
* @param list2  has elements that need to be removed from list1
* @return List return the list of elements from the list1
*//*from   ww  w.  ja  v a 2s .  c o  m*/
public static List removeElements(List list1, List list2) throws Exception {

    if (list1 == null) {
        throw new Exception("list1 is null");
    }

    if (list2 == null) {
        return list1;
    }

    HashSet hs1 = new HashSet((List) list1);
    logger.info(" list1= " + list1.size() + " hs1 = " + hs1.size());

    HashSet hs2 = new HashSet((List) list2);
    logger.info(" list2= " + list2.size() + " hs2 = " + hs2.size());

    if (hs1 != null && hs2 != null) {
        if (hs1.removeAll(hs2)) {
            logger.info("removed the elements of list2 from list1" + hs1.size());
        } else {
            logger.info("did not find any elements of list1 in list2" + hs1.size());
        }
    }
    logger.info("hs1 = " + hs1.toString());

    if (hs1 != null) {
        return new ArrayList(hs1);
    } else {
        return null;
    }
}

From source file:org.batoo.jpa.parser.impl.acl.ClassloaderAnnotatedClassLocator.java

/**
 * {@inheritDoc}//from   w  w  w .  ja  v a 2  s  . c  o m
 * 
 */
@Override
public Set<Class<?>> locateClasses(PersistenceUnitInfo persistenceUnitInfo, URL url) {
    final String root = FilenameUtils.separatorsToUnix(FilenameUtils.normalize(url.getFile()));

    ClassloaderAnnotatedClassLocator.LOG.info("Checking persistence root {0} for persistence classes...", root);

    final HashSet<Class<?>> classes = Sets.newHashSet();
    try {
        return this.findClasses(persistenceUnitInfo.getClassLoader(), classes, root, root);
    } finally {
        ClassloaderAnnotatedClassLocator.LOG.info("Found persistent classes {0}", classes.toString());
    }
}

From source file:jsentvar.GenerateTestsResults.java

public void substitutionOneTermResult() throws IOException {
    RDFReader lector = new RDFReader();
    String filename;/*  w  w w .  j  av a2  s.c o  m*/
    //filename = "resources/test/miniReasoner.owl";
    filename = "resources/IEEE_reasoner20022016.owl";
    //String term_value = term_value0.substring(0, 1).toUpperCase() +term_value0.substring(1);

    model = lector.reader(filename);

    //Read positions, a json file
    String possFile = "resources/test/text_doc0.json";
    JsonReader jreader = new JsonReader();
    HashMap<String, HashMap<Integer, Integer>> poss = jreader.reader(possFile);
    ArrayList<String> terms1 = new ArrayList<>();

    Set originS = poss.keySet();
    terms1.addAll(originS);

    //Get all the terms for substitution
    Surrogate sur = new Surrogate(model);
    HashMap<String, ArrayList<String>> alternatives;
    Utils utils = new Utils();
    ArrayList<String> terms = utils.firstUpperForeach(terms1);
    alternatives = sur.surrogatesForeach(terms);
    String docFile = "resources/tex_doc0.txt";
    String doc = FileUtils.readFileToString(new File(docFile), "utf8");
    Substitution gen = new Substitution();
    HashSet newDocs = new HashSet();
    for (String term : terms) {
        //System.out.println(term);
        HashSet newDocs0 = gen.oneTerm(doc, term, alternatives.get(term));
        newDocs.addAll(newDocs0);
    }
    FileUtils.writeStringToFile(new File("resources/test/substitutionOneTermResult.txt"), newDocs.toString(),
            "utf8");

}

From source file:jsentvar.SubstitutionTest.java

/**
 * Test of oneTerm method, of class Substitution.
 *///  w w  w  .ja v a  2  s  .  c om
@Test
public void testOneTerm() throws IOException {
    System.out.println("Substitution.oneTerm() Test");
    RDFReader lector = new RDFReader();
    String filename;
    //filename = "resources/test/miniReasoner.owl";
    filename = "resources/IEEE_reasoner20022016.owl";
    Model model;
    //String term_value = term_value0.substring(0, 1).toUpperCase() +term_value0.substring(1);

    model = lector.reader(filename);

    //Read positions, a json file
    String possFile = "resources/test/text_doc0.json";
    JsonReader jreader = new JsonReader();
    HashMap<String, HashMap<Integer, Integer>> poss = jreader.reader(possFile);
    /*
    try {
    System.out.println(poss.toString());
    } catch (NullPointerException e) {
    System.out.println("ERROR showing results " + e);
    }
    */
    ArrayList<String> terms1 = new ArrayList<>();

    Set originS = poss.keySet();
    terms1.addAll(originS);

    //Get all the terms for substitution
    /*
    ArrayList<String> terms0 = new ArrayList<>();
            terms0.add("military satellites");
            terms0.add("intelligent_systems");
    */
    Surrogate sur = new Surrogate(model);
    HashMap<String, ArrayList<String>> alternatives;
    Utils utils = new Utils();
    ArrayList<String> terms = utils.firstUpperForeach(terms1);
    alternatives = sur.surrogatesForeach(terms);
    //System.out.println(alternatives.toString());

    String docFile = "resources/test/tex_doc0.txt";
    String doc = FileUtils.readFileToString(new File(docFile), "utf8");
    Substitution gen = new Substitution();
    HashSet newDocs = new HashSet();
    for (String term : terms) {
        System.out.println(term);
        HashSet newDocs0 = gen.oneTerm(doc, term, alternatives.get(term));
        newDocs.addAll(newDocs0);
    }

    String expResult = FileUtils.readFileToString(new File("resources/test/substitutionOneTermResult.txt"),
            "utf8");
    assertEquals(expResult, newDocs.toString());

}

From source file:org.apache.zeppelin.rest.SecurityRestApi.java

/**
 * Get ticket// w  w  w .ja v a 2  s.  c o m
 * Returns username & ticket
 * for anonymous access, username is always anonymous.
 * After getting this ticket, access through websockets become safe
 *
 * @return 200 response
 */
@GET
@Path("ticket")
@ZeppelinApi
public Response ticket() {
    ZeppelinConfiguration conf = ZeppelinConfiguration.create();
    String principal = SecurityUtils.getPrincipal();
    HashSet<String> roles = SecurityUtils.getRoles();
    JsonResponse response;
    // ticket set to anonymous for anonymous user. Simplify testing.
    String ticket;
    if ("anonymous".equals(principal))
        ticket = "anonymous";
    else
        ticket = TicketContainer.instance.getTicket(principal);

    Map<String, String> data = new HashMap<>();
    data.put("principal", principal);
    data.put("roles", roles.toString());
    data.put("ticket", ticket);

    response = new JsonResponse(Response.Status.OK, "", data);
    LOG.warn(response.toString());
    return response.build();
}

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

public void testMACI_Components() throws Exception {
    String[] xmlAllNodes = retrieveComponentsList(xmlAccess);
    String[] rdbAllNodes = retrieveComponentsList(rdbAccess);
    assertEquals(xmlAllNodes.length, rdbAllNodes.length);
    HashSet<String> xmlNodes = new HashSet<String>(Arrays.asList(xmlAllNodes));
    HashSet<String> rdbNodes = new HashSet<String>(Arrays.asList(rdbAllNodes));
    logger.info("XML: " + xmlNodes.toString() + ";\n TMCDB: " + rdbNodes.toString());

    assertTrue(xmlNodes.equals(rdbNodes));
    assertTrue(CollectionUtils.isEqualCollection(xmlNodes, rdbNodes));

    for (Iterator<String> iterator = xmlNodes.iterator(); iterator.hasNext();) {
        String xmlstring = "MACI/Components/" + (String) iterator.next();
        DAO xmlDao = xmlDAL.get_DAO_Servant(xmlstring);
        DAO rdbDao = rdbDAL.get_DAO_Servant(xmlstring);
        assertEquals(xmlDao.get_string("Code"), rdbDao.get_string("Code"));
        assertEquals(xmlDao.get_string("Type"), rdbDao.get_string("Type"));
        assertEquals(xmlDao.get_string("Container"), rdbDao.get_string("Container"));
        assertEquals(xmlDao.get_string("Default"), rdbDao.get_string("Default"));
        assertEquals(xmlDao.get_string("ImplLang"), rdbDao.get_string("ImplLang"));
    }//from   ww  w .j  a va  2s .co m

}