Example usage for java.util HashSet add

List of usage examples for java.util HashSet add

Introduction

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

Prototype

public boolean add(E e) 

Source Link

Document

Adds the specified element to this set if it is not already present.

Usage

From source file:biomine.bmvis2.pipeline.TextFilterShower.java

/**
 * TODO: how should this really work?  Should the nodes be made POIs instead of showing them and their neighbors?
 *
 * @param graph Processable graph//from w w w.  j  a  v  a  2s .c  o  m
 * @throws biomine.bmvis2.pipeline.GraphOperation.GraphOperationException
 *
 */
public void doOperation(VisualGraph graph) throws GraphOperationException {
    if (this.getFilter().equals(""))
        return;

    Set<VisualNode> shownNodes = new HashSet<VisualNode>();

    for (VisualNode node : graph.getAllNodes()) {
        if (node instanceof VisualGroupNode)
            continue;

        if (this.filter.equals("*")) {
            shownNodes.add(node);
            continue;
        }

        for (String key : node.getBMNode().getAttributes().keySet())
            if (new String(node.getBMNode().getAttributes().get(key)).toLowerCase()
                    .contains(this.filter.toLowerCase()))
                shownNodes.add(node);

        if (node.getName().toLowerCase().contains(this.filter.toLowerCase())
                || node.getType().toLowerCase().contains(this.filter)
                || node.getId().toLowerCase().contains(this.filter))
            shownNodes.add(node);

        if (node.getId().equals(this.filter))
            shownNodes.add(node);

        // Logging.debug("graph_operation", "Node: " + node + ", to be shown: " + shownNodes.contains(node));
    }

    HashSet<VisualNode> oneNeighborhood = new HashSet<VisualNode>();
    for (VisualNode node : shownNodes)
        for (VisualNode neighbor : node.getNeighbors())
            oneNeighborhood.add(neighbor);
    shownNodes.addAll(oneNeighborhood);

    graph.unHideNodes(shownNodes);
}

From source file:info.magnolia.ui.framework.task.LocalTaskDispatcherManager.java

private Set<String> getAllRecipients(final Task task) {

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

    log.debug("Found actorId [{}]", task.getActorId());
    if (StringUtils.isNotBlank(task.getActorId())) {
        users.add(task.getActorId());
    }//from www .  j a v  a  2s  .  c  o  m

    if (task.getActorIds() != null) {
        log.debug("Found actorIds {}", task.getActorIds());
        users.addAll(task.getActorIds());
    }

    log.debug("Found groups {}", task.getGroupIds());
    if (task.getGroupIds() != null) {
        for (String group : task.getGroupIds()) {
            Collection<String> usersOfGroupTransitive = securitySupport.get().getUserManager()
                    .getUsersWithGroup(group, true);
            users.addAll(usersOfGroupTransitive);
        }
    }

    return users;
}

From source file:com.adobe.cq.wcm.core.components.internal.servlets.ClientLibraryCategoriesDataSourceServlet.java

private List<Resource> getCategoryResourceList(@Nonnull SlingHttpServletRequest request,
        LibraryType libraryType) {/*from  www  .  ja  v a2 s.co m*/
    List<Resource> categoryResourceList = new ArrayList<>();
    HashSet<String> clientLibraryCategories = new HashSet<String>();
    for (ClientLibrary library : htmlLibraryManager.getLibraries().values()) {
        for (String category : library.getCategories()) {
            clientLibraryCategories.add(category);
        }
    }
    if (libraryType != null) {
        Collection<ClientLibrary> clientLibraries = htmlLibraryManager.getLibraries(
                clientLibraryCategories.toArray(new String[clientLibraryCategories.size()]), libraryType, true,
                true);
        clientLibraryCategories.clear();
        for (ClientLibrary library : clientLibraries) {
            for (String category : library.getCategories()) {
                clientLibraryCategories.add(category);
            }
        }
    }
    for (String category : clientLibraryCategories) {
        categoryResourceList.add(new CategoryResource(category, request.getResourceResolver()));
    }
    return categoryResourceList;
}

From source file:com.esri.squadleader.model.GeoPackageReader.java

/**
 * Reads the tables in a GeoPackage, makes a layer from each table, and returns a list containing
 * those layers./*from w  w  w .  ja  v a 2 s  .  co  m*/
 *
 * @param gpkgPath       the full path to the .gpkg file.
 * @param sr             the spatial reference to which any raster layers should be projected, typically the
 *                       spatial reference of your map.
 * @param showVectors    if true, this method will include the GeoPackage's vector layers.
 * @param showRasters    if true, this method will include the GeoPackage's raster layer.
 * @param rasterRenderer the renderer to be used for raster layers. One simple option is an RGBRenderer.
 * @param markerRenderer the renderer to be used for point layers.
 * @param lineRenderer   the renderer to be used for polyline layers.
 * @param fillRenderer   the renderer to be used for polygon layers.
 * @return a list of the layers created for all tables in the GeoPackage.
 * @throws IOException if gpkgPath cannot be read. Possible reasons include the file not
 *                     existing, failure to request READ_EXTERNAL_STORAGE or
 *                     WRITE_EXTERNAL_STORAGE permission, or the GeoPackage containing an
 *                     invalid spatial reference.
 */
public List<Layer> readGeoPackageToLayerList(String gpkgPath, SpatialReference sr, boolean showVectors,
        boolean showRasters, RasterRenderer rasterRenderer, Renderer markerRenderer, Renderer lineRenderer,
        Renderer fillRenderer) throws IOException {
    List<Layer> layers = new ArrayList<Layer>();

    if (showRasters) {
        // Check to see if there are any rasters before loading them
        SQLiteDatabase sqliteDb = null;
        Cursor cursor = null;
        try {
            sqliteDb = SQLiteDatabase.openDatabase(gpkgPath, null, SQLiteDatabase.OPEN_READONLY);
            cursor = sqliteDb.rawQuery("SELECT COUNT(*) FROM gpkg_contents WHERE data_type = ?",
                    new String[] { "tiles" });
            if (cursor.moveToNext()) {
                if (0 < cursor.getInt(0)) {
                    cursor.close();
                    sqliteDb.close();
                    FileRasterSource src = new FileRasterSource(gpkgPath);
                    rasterSources.add(src);
                    if (null != sr) {
                        src.project(sr);
                    }
                    RasterLayer rasterLayer = new RasterLayer(src);
                    rasterLayer.setRenderer(rasterRenderer);
                    rasterLayer
                            .setName((gpkgPath.contains("/") ? gpkgPath.substring(gpkgPath.lastIndexOf("/") + 1)
                                    : gpkgPath) + " (raster)");
                    layers.add(rasterLayer);
                }
            }
        } catch (Throwable t) {
            Log.e(TAG, "Could not read raster(s) from GeoPackage", t);
        } finally {
            if (null != cursor) {
                cursor.close();
            }
            if (null != sqliteDb) {
                sqliteDb.close();
            }
        }
    }

    if (showVectors) {
        Geopackage gpkg;
        try {
            gpkg = new Geopackage(gpkgPath);
        } catch (RuntimeException ex) {
            throw new IOException(null != ex.getMessage() && ex.getMessage().contains("unknown wkt")
                    ? "Geopackage " + gpkgPath + " contains an invalid spatial reference."
                    : null, ex);
        }
        geopackages.add(gpkg);
        List<GeopackageFeatureTable> tables = gpkg.getGeopackageFeatureTables();
        if (0 < tables.size()) {
            //First pass: polygons and unknowns
            HashSet<Geometry.Type> types = new HashSet<Geometry.Type>();
            types.add(Geometry.Type.ENVELOPE);
            types.add(Geometry.Type.POLYGON);
            types.add(Geometry.Type.UNKNOWN);
            layers.addAll(getTablesAsLayers(tables, types, fillRenderer));

            //Second pass: lines
            types.clear();
            types.add(Geometry.Type.LINE);
            types.add(Geometry.Type.POLYLINE);
            layers.addAll(getTablesAsLayers(tables, types, lineRenderer));

            //Third pass: points
            types.clear();
            types.add(Geometry.Type.MULTIPOINT);
            types.add(Geometry.Type.POINT);
            layers.addAll(getTablesAsLayers(tables, types, markerRenderer));
        }
    }

    return layers;
}

From source file:de.tudarmstadt.ukp.dkpro.tc.fstore.simple.DenseFeatureStore.java

@Override
public void addInstance(Instance instance) throws TextClassificationException {
    if (featureNames == null) {
        featureNames = new TreeSet<String>();
        for (Feature feature : instance.getFeatures()) {
            String name = feature.getName();
            if (featureNames.contains(name)) {
                throw new TextClassificationException(
                        "Feature with name '" + name + "' is defined multiple times.");
            }/*from  w w w .ja v  a  2  s .  com*/
            featureNames.add(name);
        }
    }

    HashSet<String> instanceFeatureNames = new HashSet<String>();
    for (Feature f : instance.getFeatures()) {
        instanceFeatureNames.add(f.getName());
    }
    @SuppressWarnings("unchecked")
    String[] symDiff = new ArrayList<String>(CollectionUtils.disjunction(instanceFeatureNames, featureNames))
            .toArray(new String[] {});
    if (symDiff.length > 0) {
        throw new TextClassificationException(
                "One or more, but not all of your instances return the following feature(s): "
                        + StringUtils.join(symDiff, " and "));
    }

    // create map of feature names and offset in set
    Map<String, Integer> sortedFeatureNameMap = new HashMap<String, Integer>();
    int offset = 0;
    Iterator<String> iterator = featureNames.iterator();
    while (iterator.hasNext()) {
        sortedFeatureNameMap.put(iterator.next(), offset);
        offset++;
    }

    Object[] values = new Object[featureNames.size()];
    for (Feature feature : instance.getFeatures()) {
        values[sortedFeatureNameMap.get(feature.getName())] = feature.getValue();
    }
    this.instanceList.add(Arrays.asList(values));
    this.outcomeList.add(instance.getOutcomes());
    this.weightList.add(instance.getWeight());
    this.sequenceIds.add(instance.getSequenceId());
    this.sequencePositions.add(instance.getSequencePosition());
}

From source file:com.github.rutvijkumar.twittfuse.TwitterUtil.java

@SuppressLint("DefaultLocale")
public void postReply(final Tweet tweet) {
    HashSet<String> handles = new HashSet<String>();

    List<String> list = Util.testExtract(tweet.getBody());
    for (String l : list) {
        handles.add(l.toLowerCase());
    }//from  ww w  .  ja  va  2s.c  o  m
    handles.add(tweet.getUser().getScreenName().toLowerCase());
    Tweet retweetedTweeet = tweet.getReTweeted();
    if (retweetedTweeet != null) {
        handles.add(retweetedTweeet.getUser().getScreenName().toLowerCase());
    }

    Util.onReply(activity, handles, String.valueOf(tweet.getUid()));

}

From source file:org.openmrs.module.phrjournal.web.controller.JournalController.java

/**
  * Add missing parent entries for comments
  * //w  w w.  java 2 s.  c  o m
  * @param entries original entries found through search
  */
private void addMissingParents(List<JournalEntry> entries) {
    // TODO Auto-generated method stub
    HashSet<Integer> parents = new HashSet<Integer>();
    for (JournalEntry entry : entries) {
        Integer parentId = entry.getParentEntryId();
        if (parentId != null) {
            parents.add(parentId);
        }
    }

    for (Integer parent : parents) {
        boolean exists = false;
        for (JournalEntry entry : entries) {
            if (entry.getEntryId().equals(parent)) {
                exists = true;
                break;
            }
        }
        if (!exists) {
            JournalEntry entry = Context.getService(JournalEntryService.class).getJournalEntry(parent);
            entries.add(entry);
        }
    }
}

From source file:org.ambraproject.admin.service.AdminRolesServiceTest.java

@DataProvider(name = "userRoles")
public Object[][] roles() {
    UserProfile up = new UserProfile();
    up.setDisplayName("roles5");
    up.setEmail("roles5@example.org");
    up.setPassword("pass");

    dummyDataStore.store(up);//from  w ww.j  ava2  s.com

    UserRole ur1 = new UserRole();
    ur1.setRoleName("Role5");

    dummyDataStore.store(ur1);

    UserRole ur2 = new UserRole();
    ur2.setRoleName("Role6");

    dummyDataStore.store(ur2);

    HashSet<UserRole> roles = new HashSet<UserRole>();

    roles.add(ur1);
    roles.add(ur2);

    return new Object[][] { { roles, up.getID() } };
}

From source file:org.ambraproject.admin.service.AdminRolesServiceTest.java

@DataProvider(name = "userProfileAndRoles2")
public Object[][] roleSet2() {
    UserRole ur1 = new UserRole();
    ur1.setRoleName("Role3");

    dummyDataStore.store(ur1);//from ww w .  j a  v a 2  s  . c  om

    UserRole ur2 = new UserRole();
    ur2.setRoleName("Role4");

    dummyDataStore.store(ur2);

    HashSet<UserRole> roles = new HashSet<UserRole>();

    roles.add(ur1);
    roles.add(ur2);

    UserProfile up = new UserProfile();
    up.setDisplayName("adminRolesServiceTest2");
    up.setEmail("adminRolesServiceTest2@example.org");
    up.setPassword("pass");
    up.setRoles(roles);

    dummyDataStore.store(up);

    return new Object[][] { { up, roles } };
}

From source file:org.ambraproject.admin.service.AdminRolesServiceTest.java

@DataProvider(name = "userAssignedRoles")
public Object[][] userAssignedRoles() {
    UserRole ur1 = new UserRole();
    ur1.setRoleName("Role7");

    dummyDataStore.store(ur1);// w ww  .  ja va  2 s  .  c o m

    UserRole ur2 = new UserRole();
    ur2.setRoleName("Role8");

    dummyDataStore.store(ur2);

    HashSet<UserRole> roles = new HashSet<UserRole>();

    roles.add(ur1);
    roles.add(ur2);

    UserProfile up = new UserProfile();
    up.setDisplayName("assignedRoles");
    up.setEmail("assignedRoles@example.org");
    up.setPassword("pass");
    up.setRoles(roles);

    dummyDataStore.store(up);

    return new Object[][] { { roles, up.getID() } };
}