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:hr.fer.zemris.vhdllab.platform.ui.wizard.schema.NewSchemaWizard.java

private String createSchema(CircuitInterface ci) throws Exception {
    ISchemaInfo info = new SchemaInfo();

    Caseless cname = new Caseless(ci.getName());
    info.getEntity().getParameters().setValue(SchemaEntity.KEY_NAME, cname);
    HashSet<Object> allowed = new HashSet<Object>();
    allowed.add(cname);
    info.getEntity().getParameters().getParameter(SchemaEntity.KEY_NAME).getConstraint()
            .setPossibleValues(allowed);

    int ly = MARGIN_OFFSET, ry = MARGIN_OFFSET;
    ISchemaComponentCollection components = info.getComponents();
    for (Port p : ci.getPorts()) {
        InOutSchemaComponent inout = new InOutSchemaComponent(p);
        if (p.isIN()) {
            components.addComponent(MARGIN_OFFSET, ly, inout);
            ly += inout.getHeight() + MARGIN_OFFSET;
        } else { // else isOUT
            components.addComponent(Constants.DEFAULT_SCHEMA_WIDTH, ry, inout);
            ry += inout.getHeight() + MARGIN_OFFSET;
        }//from w  w w. ja  v  a2 s  . com
    }

    SchemaSerializer ss = new SchemaSerializer();
    StringWriter writer = new StringWriter(1000 + 1000 * ci.getPorts().size());
    try {
        ss.serializeSchema(writer, info);
    } catch (IOException e) {
        throw new UnhandledException(e);
    }
    return writer.toString();
}

From source file:DirectoryWalker.java

/**
  * Get all the files in the starting directory (but NOT sub dirs)
  * returns only files ending this the filename
  * @param startingDirectory/*  w ww  .j a va 2s. co m*/
  * @return filesFound (as HashSet)
  * @exception java.io.IOException
  */
public static HashSet getFiles(String startingDirectory, String endFileName) throws java.io.IOException {

    //Local Variables
    String tmpFullFile;
    File startDir = new File(startingDirectory);
    File tmpFile;
    String[] thisDirContents;
    HashSet filesFound = new HashSet();

    //Check that this is a valid directory
    if (!startDir.isDirectory()) {
        throw new java.io.IOException(startingDirectory + " was not a valid directory");
    }

    //Get the contents of the current directory
    thisDirContents = startDir.list();

    if (thisDirContents != null) {
        //Now loop through , apply filter , or adding them to list of sub dirs
        for (int a = 0; a < thisDirContents.length; a++) {

            //Get Handle to (full) file (inc path)  
            tmpFullFile = FileUtil.combineFileAndDirectory(thisDirContents[a], startingDirectory);

            tmpFile = new File(tmpFullFile);

            //Add to Output if file
            if (tmpFile.isFile()) {
                //Add if file 
                if ((endFileName == null) || (tmpFullFile.endsWith(endFileName))) {
                    filesFound.add(tmpFullFile);
                }
            }
        }
    }

    return filesFound;

}

From source file:io.cloudslang.orchestrator.services.MergedConfigurationServiceTest.java

@Test
public void testPausedFlow() {
    String pausedExecutionId = "22223333";
    HashSet<String> pausedFlows = new HashSet<>();
    pausedFlows.add(pausedExecutionId);
    when(pauseResumeService.readAllPausedExecutionBranchIds()).thenReturn(pausedFlows);
    assertTrue(mergedConfigurationService.fetchMergedConfiguration(getWorkerUuid()).getPausedExecutions()
            .contains(pausedExecutionId));
}

From source file:com.cyberway.issue.crawler.util.BdbUriUniqFilterTest.java

/**
 * Verify that two URIs which gave colliding hashes, when previously
 * the last 40bits of the composite did not sufficiently vary with certain
 * inputs, no longer collide. //from   www.j a v  a 2s .  com
 */
public void testCreateKeyCollisions() {
    HashSet<Long> fingerprints = new HashSet<Long>();
    fingerprints.add(new Long(BdbUriUniqFilter.createKey("dns:mail.daps.dla.mil")));
    fingerprints.add(new Long(BdbUriUniqFilter.createKey("dns:militaryreview.army.mil")));
    assertEquals("colliding fingerprints", 2, fingerprints.size());
}

From source file:com.redhat.lightblue.rest.metadata.hystrix.GetEntityNamesCommand.java

@Override
protected String run() {
    LOGGER.debug("run:");
    Error.reset();//from  w w  w .  j ava 2s .  c  o  m
    Error.push(getClass().getSimpleName());
    try {
        HashSet<MetadataStatus> statusSet = new HashSet<>();
        for (String x : statuses) {
            statusSet.add(MetadataParser.statusFromString(x));
        }
        String[] names = getMetadata().getEntityNames(statusSet.toArray(new MetadataStatus[statusSet.size()]));
        ObjectNode node = NODE_FACTORY.objectNode();
        ArrayNode arr = NODE_FACTORY.arrayNode();
        node.put("entities", arr);
        for (String x : names) {
            arr.add(NODE_FACTORY.textNode(x));
        }
        return node.toString();
    } catch (Error e) {
        return e.toString();
    } catch (Exception e) {
        LOGGER.error("Failure: {}", e);
        return Error.get(RestMetadataConstants.ERR_REST_ERROR, e.toString()).toString();
    }
}

From source file:io.cloudslang.orchestrator.services.MergedConfigurationServiceTest.java

@Test
public void testPausedCancelledFlows() {
    String pausedExecutionId = "22223333";
    HashSet<String> pausedFlows = new HashSet<>();
    pausedFlows.add(pausedExecutionId);
    Long cancelledExecution1 = 11112222L;
    Long cancelledExecution2 = 22221111L;
    ArrayList cancelledFlows = new ArrayList();
    cancelledFlows.add(cancelledExecution1);
    cancelledFlows.add(cancelledExecution2);
    when(pauseResumeService.readAllPausedExecutionBranchIds()).thenReturn(pausedFlows);
    when(cancelExecutionService.readCanceledExecutionsIds()).thenReturn(cancelledFlows);
    assertTrue(mergedConfigurationService.fetchMergedConfiguration(getWorkerUuid()).getPausedExecutions()
            .contains(pausedExecutionId));
    assertTrue(mergedConfigurationService.fetchMergedConfiguration(getWorkerUuid()).getCancelledExecutions()
            .contains(cancelledExecution1));
    assertTrue(mergedConfigurationService.fetchMergedConfiguration(getWorkerUuid()).getCancelledExecutions()
            .contains(cancelledExecution2));
}

From source file:de.uni_koeln.spinfo.maalr.login.MaalrAuthorityGranter.java

public Set<String> grant(Principal principal) {
    HashSet<String> roles = new HashSet<String>();
    String name = principal.getName();
    if ("admin".equals(name)) {
        roles.add(Role.ADMIN_5.getRoleId());
        return roles;
    }//from  w w w  . ja  v a 2 s  .  c om
    MaalrUserInfo user = userInfos.getByLogin(name);
    if (user == null) {
        user = new MaalrUserInfo(name, Role.GUEST_1);
        try {
            userInfos.insert(user);
        } catch (InvalidUserException e) {
            throw new RuntimeException(e);
        }
        roles.add(user.getRole().getRoleId());
        return roles;
    }
    roles.add(user.getRole().getRoleId());
    return roles;
}

From source file:amie.keys.CombinationsExplorationNew.java

private static HashMap<Rule, HashSet<String>> discoverConditionalKeysFirstLevel(
        HashMap<Rule, GraphNew> ruleToGraphNew, HashMap<Integer, GraphNew> instantiatedProperty2GraphNew) {
    Rule rule = new Rule();
    for (int conditionProperty : instantiatedProperty2GraphNew.keySet()) {
        GraphNew graph = instantiatedProperty2GraphNew.get(conditionProperty);
        String prop = id2Property.get(conditionProperty);

        Iterable<Rule> conditions = Utilities.getConditions(rule, prop, (int) support, kb);
        for (Rule conditionRule : conditions) {
            GraphNew newGraph = new GraphNew();
            discoverConditionalKeysForCondition(newGraph, graph, graph.topGraphNodes(), conditionRule);
            if (newGraph != null) {
                ruleToGraphNew.put(conditionRule, newGraph);
            }/*from   w  w  w  . ja va  2 s  .c  o  m*/
        }
    }

    HashMap<Rule, HashSet<String>> newRuleToExtendWith = new HashMap<>();
    for (Rule conRule : ruleToGraphNew.keySet()) {
        GraphNew newGraph = ruleToGraphNew.get(conRule);
        HashSet<String> properties = new HashSet<>();
        for (Node node : newGraph.topGraphNodes()) {
            if (node.toExplore) {
                Iterator<Integer> it = node.set.iterator();
                int prop = it.next();
                String propertyStr = id2Property.get(prop);
                properties.add(propertyStr);
            }

        }
        if (properties.size() != 0) {
            newRuleToExtendWith.put(conRule, properties);
        }
    }
    return newRuleToExtendWith;
}

From source file:org.sventon.web.ctrl.ConfigurationFormControllerTest.java

@Test
public void setUpForm() throws Exception {
    Application application = mock(Application.class);

    HashSet<RepositoryName> repositoryNames = new HashSet<RepositoryName>();
    repositoryNames.add(new RepositoryName("sventon"));
    repositoryNames.add(new RepositoryName("nordpolen"));
    when(application.getRepositoryNames()).thenReturn(repositoryNames);
    ConfigurationFormController controller = new ConfigurationFormController(application);

    ModelAndView modelAndView = controller.setUpForm(new ModelAndView());

    Map expectedModel = new HashMap();
    expectedModel.put("addedRepositories", repositoryNames);
    expectedModel.put("command", new ConfigCommand());

    assertModelAttributeValues(modelAndView, expectedModel);
    assertViewName(modelAndView, CONFIG_FORM_VIEW_NAME);
}

From source file:com.relicum.ipsum.Utils.LocUtils.java

/**
 * It will return a specified {@link org.bukkit.entity.LivingEntity} in a radius, from location.
 *
 * @param location Initial location/*from w  w w .j a v a2s.c  o  m*/
 * @param radius   distance from the "location" that will return all the entities from each block;
 * @param entity   the type of entity to get returned
 * @return HashSet(LivingEntity)
 * credits skore87
 */
public static HashSet<LivingEntity> getNearByEntities(Location location, int radius, EntityType entity) {

    int chunkRadius = radius < 16 ? 1 : (radius - (radius % 16)) / 16;
    HashSet<LivingEntity> radiusEntities = new HashSet<>();

    for (int chX = 0 - chunkRadius; chX <= chunkRadius; chX++) {
        for (int chZ = 0 - chunkRadius; chZ <= chunkRadius; chZ++) {
            int x = (int) location.getX(), y = (int) location.getY(), z = (int) location.getZ();
            for (Entity e : new Location(location.getWorld(), x + (chX * 16), y, z + (chZ * 16)).getChunk()
                    .getEntities()) {
                if (e.getLocation().distance(location) <= radius
                        && e.getLocation().getBlock() != location.getBlock()) {
                    if (e instanceof LivingEntity) {

                        if (e.getType().equals(entity)) {
                            radiusEntities.add((LivingEntity) e);
                        }
                    }
                }
            }
        }
    }
    return radiusEntities;

}