Example usage for java.util Set toArray

List of usage examples for java.util Set toArray

Introduction

In this page you can find the example usage for java.util Set toArray.

Prototype

<T> T[] toArray(T[] a);

Source Link

Document

Returns an array containing all of the elements in this set; the runtime type of the returned array is that of the specified array.

Usage

From source file:com.mirth.connect.server.controllers.AuthorizationController.java

public void auditAuthorizationRequest(Integer userId, Operation operation, Map<String, Object> parameterMap,
        ServerEvent.Outcome outcome, String address) {
    if (operation != null && operation.isAuditable()) {
        String displayName = operation.getDisplayName();
        if (operation instanceof ExtensionOperation) {
            displayName += " invoked through " + ((ExtensionOperation) operation).getExtensionName();
        }/*from w  w  w.  j a  v a2s  .co m*/
        ServerEvent serverEvent = new ServerEvent(serverId, displayName);
        serverEvent.setLevel(Level.INFORMATION);
        serverEvent.setUserId(userId);
        serverEvent.setOutcome(outcome);
        serverEvent.setIpAddress(address);

        if (MapUtils.isNotEmpty(parameterMap)) {
            for (Entry<String, Object> entry : parameterMap.entrySet()) {
                String key = entry.getKey();
                Object value = entry.getValue();

                // If channelId was one of the params, print out each channel as separate attributes and add the channel name
                if (key.contains("channelId")) {
                    Set<String> collection = null;

                    if (value instanceof Set) {
                        collection = (Set<String>) value;
                    } else if (value instanceof String) {
                        collection = Collections.singleton((String) value);
                    }

                    if (collection != null) {
                        String[] channelIds = collection.toArray(new String[collection.size()]);
                        for (int i = 0; i < channelIds.length; i++) {
                            String name = "channel";
                            if (channelIds.length > 1) {
                                name += "[" + i + "]";
                            }
                            value = channelController.getChannelById(channelIds[i]);
                            addAttribute(serverEvent.getAttributes(), name, value);
                        }
                    }
                } else {
                    addAttribute(serverEvent.getAttributes(), key, value);
                }
            }
        }
        eventController.dispatchEvent(serverEvent);
    }
}

From source file:org.jax.bham.test.MultiHaplotypeBlockTestGraphPanel.java

private List<JComponent> createContextMenuItems() {
    List<JComponent> menuItems = new ArrayList<JComponent>();

    int[] chromosomes = this.getSelectedChromosomes();
    if (this.lastClickedIntervalIndex >= 0 && chromosomes.length == 1) {
        RealValuedBasePairInterval[] intervals = this.chromosomeToNegLogValueMap.get(chromosomes[0]);
        RealValuedBasePairInterval selectedInterval = intervals[this.lastClickedIntervalIndex];
        menuItems.add(new JMenuItem(new GoToMouseIntervalInCGDSnpDatabaseAction(selectedInterval,
                BhamApplication.getInstance().getBhamFrame())));
        menuItems.add(new JMenuItem(new GoToMouseIntervalInCGDGBrowseAction(selectedInterval,
                BhamApplication.getInstance().getBhamFrame())));
        menuItems.add(new JMenuItem(new GoToMouseIntervalInUCSCBrowserAction(selectedInterval,
                BhamApplication.getInstance().getBhamFrame())));
        menuItems.add(new JSeparator());

        if (selectedInterval instanceof CompositeRealValuedBasePairInterval) {
            CompositeRealValuedBasePairInterval selectedCompositeInterval = (CompositeRealValuedBasePairInterval) selectedInterval;
            if (selectedCompositeInterval.getDelegateInterval() instanceof MultiGroupStrainPartition) {
                MultiGroupStrainPartition partition = (MultiGroupStrainPartition) selectedCompositeInterval
                        .getDelegateInterval();
                Set<String> strains = this.testToPlot.getCommonStrains();
                String[] sortedStrains = strains.toArray(new String[strains.size()]);
                Arrays.sort(sortedStrains);
                short[] strainGroups = partition.getStrainGroups();
                Map<Short, Set<String>> numberedStrainGroups = new HashMap<Short, Set<String>>();
                for (int strainIndex = 0; strainIndex < strainGroups.length; strainIndex++) {
                    Set<String> strainsInGroup = numberedStrainGroups.get(strainGroups[strainIndex]);
                    if (strainsInGroup == null) {
                        strainsInGroup = new HashSet<String>();
                        numberedStrainGroups.put(strainGroups[strainIndex], strainsInGroup);
                    }//from  w  ww.  ja  v  a 2s  .c  o  m

                    strainsInGroup.add(sortedStrains[strainIndex]);
                }

                // create a human readable name for the strain groups
                Map<String, Set<String>> namedStrainGroups = new HashMap<String, Set<String>>();
                for (Set<String> strainGroup : numberedStrainGroups.values()) {
                    String anyStrain = strainGroup.iterator().next();
                    String groupName = anyStrain + " Group";

                    assert !namedStrainGroups.containsKey(groupName);
                    namedStrainGroups.put(groupName, strainGroup);
                }

                menuItems.add(new JMenuItem(new ShowPhenotypeEffectPlotAction(
                        this.testToPlot.getPhenotypeDataSource(), namedStrainGroups)));
                menuItems.add(new JSeparator());
            }
        }
    }

    return menuItems;
}

From source file:com.intel.databackend.api.inquiry.advanced.AdvancedDataInquiryService.java

private String[] getAttributesFromRequest() {
    Set<String> attributesSet = new HashSet<>();
    if (dataInquiryRequest.getReturnedMeasureAttributes() != null) {
        attributesSet.addAll(dataInquiryRequest.getReturnedMeasureAttributes());
    }/*from w  w  w  . j  a v a 2s. co m*/
    if (dataInquiryRequest.getMeasurementAttributeFilter() != null) {
        attributesSet.addAll(dataInquiryRequest.getMeasurementAttributeFilter().keySet());
    }
    return attributesSet.toArray(new String[attributesSet.size()]);
}

From source file:org.onosproject.uiref.UiRefTopoOverlayMessageHandler.java

private void initLinkSet() {
    Set<Link> links = new HashSet<>();
    for (Link link : linkService.getActiveLinks()) {
        links.add(link);// w  ww.j av a2s.c o m
    }
    linkSet = links.toArray(new Link[links.size()]);
    linkIndex = 0;
    log.debug("initialized link set to {}", linkSet.length);
}

From source file:org.fcrepo.auth.oauth.api.AuthzEndpoint.java

/**
 * Saves an authorization code for later retrieval at the token endpoint.
 * //from   w  w  w  .  ja v  a  2 s  . c  om
 * @param authCode
 * @param scopes
 * @param client
 * @throws RepositoryException
 */
private void saveAuthCode(final String authCode, final Set<String> scopes, final String client)
        throws RepositoryException {
    final Session session = sessions.getSession(OAUTH_WORKSPACE);
    try {
        final Node codeNode = jcrTools.findOrCreateNode(session, "/authorization-codes/" + authCode);
        codeNode.setProperty(CLIENT_PROPERTY, client);
        codeNode.setProperty(Constants.SCOPES_PROPERTY, scopes.toArray(new String[0]));
        session.save();
    } finally {
        session.logout();
    }

}

From source file:com.amalto.core.storage.SystemStorageWrapper.java

@Override
public String[] getAllClusters() throws XmlServerException {
    Set<String> internalClusterNames = DispatchWrapper.getInternalClusterNames();
    return internalClusterNames.toArray(new String[internalClusterNames.size()]);
}

From source file:com.streamreduce.core.service.ConnectionServiceCreateConnectionIT.java

@Test
public void testCreateConnectionPersistsOutboundConfigurations() throws Exception {
    OutboundConfiguration outboundConfiguration = new OutboundConfiguration.Builder()
            .credentials(new ConnectionCredentials(cloudBundle.getString("nodeable.aws.accessKeyId"),
                    cloudBundle.getString("nodeable.aws.secretKey")))
            .destination("eu-west-1").protocol("s3").namespace("com.streamreduce.bucket")
            .dataTypes(OutboundDataType.PROCESSED).build();

    Connection feedConnection = new Connection.Builder().alias("EC2 Test Connection")
            .description("Reports the status of Amazon Elastic Compute Cloud (N. California).")
            .visibility(SobaObject.Visibility.ACCOUNT)
            .provider(connectionProviderFactory.connectionProviderFromId(ProviderIdConstants.FEED_PROVIDER_ID))
            .user(testUser).authType(AuthType.NONE).url("status.aws.amazon.com/rss/ec2-us-west-1.rss?junkParam")
            .outboundConfigurations(outboundConfiguration).build();

    Connection createdFeedConnection = connectionService.createConnection(feedConnection);
    ObjectId objectId = createdFeedConnection.getId();

    Connection retrievedConnection = connectionService.getConnection(objectId);
    Set<OutboundConfiguration> retrievedConnectionOutboundConfigurations = retrievedConnection
            .getOutboundConfigurations();
    Set<OutboundConfiguration> feedConnectionOutboundConfigurations = feedConnection
            .getOutboundConfigurations();
    OutboundConfiguration[] retrivedConfigurations = retrievedConnectionOutboundConfigurations
            .toArray(new OutboundConfiguration[retrievedConnectionOutboundConfigurations.size()]);
    OutboundConfiguration[] feedConfigurations = feedConnectionOutboundConfigurations
            .toArray(new OutboundConfiguration[feedConnectionOutboundConfigurations.size()]);
    Assert.assertEquals(retrivedConfigurations[0], feedConfigurations[0]);
    Assert.assertEquals(retrievedConnection.getId(), feedConnection.getId());
}

From source file:ch.entwine.weblounge.contentrepository.fs.FileSystemContentRepositoryTest.java

/**
 * Sets up everything valid for all test runs.
 * //  w  w w .  ja v  a 2  s  .  c om
 * @throws Exception
 *           if setup fails
 */
@BeforeClass
public static void setUpClass() throws Exception {
    jpegContentURL = FileSystemContentRepositoryTest.class.getResource(jpegContentPath);
    pngContentURL = FileSystemContentRepositoryTest.class.getResource(pngContentPath);

    // Resource serializer
    serializer = new ResourceSerializerServiceImpl();
    serializer.addSerializer(new PageSerializer());
    serializer.addSerializer(new FileResourceSerializer());
    serializer.addSerializer(new ImageResourceSerializer());
    serializer.addSerializer(new MovieResourceSerializer());

    testRoot = new File(PathUtils.concat(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString()));
    repositoryRoot = new File(testRoot, "repository");

    // Set weblounge.home so that search index can properly be created
    System.setProperty("weblounge.home", testRoot.getAbsolutePath());
    TestUtils.startTesting();
    ElasticSearchUtils.createIndexConfigurationAt(testRoot);

    // Template
    template = EasyMock.createNiceMock(PageTemplate.class);
    EasyMock.expect(template.getIdentifier()).andReturn("templateid").anyTimes();
    EasyMock.expect(template.getStage()).andReturn("non-existing").anyTimes();
    EasyMock.replay(template);

    Set<Language> languages = new HashSet<Language>();
    languages.add(LanguageUtils.getLanguage("en"));
    languages.add(LanguageUtils.getLanguage("de"));

    // Site
    site = EasyMock.createNiceMock(Site.class);
    EasyMock.expect(site.getIdentifier()).andReturn("test").anyTimes();
    EasyMock.expect(site.getTemplate((String) EasyMock.anyObject())).andReturn(template).anyTimes();
    EasyMock.expect(site.getDefaultTemplate()).andReturn(template).anyTimes();
    EasyMock.expect(site.getLanguages()).andReturn(languages.toArray(new Language[languages.size()]))
            .anyTimes();
    EasyMock.expect(site.getModules()).andReturn(new Module[] {}).anyTimes();
    EasyMock.expect(site.getDefaultLanguage()).andReturn(LanguageUtils.getLanguage("de")).anyTimes();
    EasyMock.expect(site.getAdministrator()).andReturn(new SiteAdminImpl("admin")).anyTimes();
    EasyMock.replay(site);

    // Connect to the repository
    repository = new FileSystemContentRepository();
    repository.setSerializer(serializer);
    repository.setEnvironment(Environment.Production);
    Dictionary<String, Object> repositoryProperties = new Hashtable<String, Object>();
    repositoryProperties.put(FileSystemContentRepository.OPT_ROOT_DIR, repositoryRoot.getAbsolutePath());
    repository.updated(repositoryProperties);
    repository.connect(site);
}

From source file:hoot.services.controllers.osm.OSMTestUtils.java

static void verifyTestRelationsNoWaysUnmodified(Set<Long> relationIds, Set<Long> nodeIds, long changesetId,
        boolean verifyTags) {
    Long[] relationIdsArr = relationIds.toArray(new Long[relationIds.size()]);
    Long[] nodeIdsArr = nodeIds.toArray(new Long[nodeIds.size()]);
    Map<Long, CurrentRelations> relations = createQuery(getMapId()).from(currentRelations)
            .where((currentRelations.changesetId.eq(changesetId)))
            .transform(groupBy(currentRelations.id).as(currentRelations));

    assertEquals(3, relations.size());/*from www.j  a  v a  2s  . co m*/

    CurrentRelations relationRecord = relations.get(relationIdsArr[0]);
    assertEquals(new Long(changesetId), relationRecord.getChangesetId());
    assertEquals(relationIdsArr[0], relationRecord.getId());
    assertEquals(new Long(1), relationRecord.getVersion());

    List<CurrentRelationMembers> relationMembers = createQuery(getMapId()).select(currentRelationMembers)
            .from(currentRelationMembers).where(currentRelationMembers.relationId.eq(relationIdsArr[0]))
            .orderBy(currentRelationMembers.sequenceId.asc()).fetch();

    assertEquals(2, relationMembers.size());
    CurrentRelationMembers member = relationMembers.get(0);
    assertEquals(relationRecord.getId(), member.getRelationId());
    assertEquals(DbUtils.nwr_enum.node, member.getMemberType());
    assertEquals("role1", member.getMemberRole());
    assertEquals(new Integer(1), member.getSequenceId());

    assertEquals(nodeIdsArr[0], member.getMemberId());
    member = relationMembers.get(1);
    assertEquals(relationRecord.getId(), member.getRelationId());
    assertEquals(DbUtils.nwr_enum.node, member.getMemberType());
    assertEquals("", member.getMemberRole());
    assertEquals(new Integer(2), member.getSequenceId());

    assertEquals(nodeIdsArr[2], member.getMemberId());
    if (verifyTags) {
        Map<String, String> tags = PostgresUtils.postgresObjToHStore(relationRecord.getTags());
        assertEquals(1, tags.size());
        assertEquals("val 1", tags.get("key 1"));
    }

    relationRecord = relations.get(relationIdsArr[1]);
    assertEquals(new Long(changesetId), relationRecord.getChangesetId());
    assertEquals(relationIdsArr[1], relationRecord.getId());
    assertEquals(new Long(1), relationRecord.getVersion());

    relationMembers = createQuery(getMapId()).select(currentRelationMembers).from(currentRelationMembers)
            .where(currentRelationMembers.relationId.eq(relationIdsArr[1]))
            .orderBy(currentRelationMembers.sequenceId.asc()).fetch();

    assertEquals(2, relationMembers.size());
    member = relationMembers.get(0);
    assertEquals(relationRecord.getId(), member.getRelationId());
    assertEquals(DbUtils.nwr_enum.node, member.getMemberType());
    assertEquals("role1", member.getMemberRole());
    assertEquals(new Integer(1), member.getSequenceId());

    assertEquals(nodeIdsArr[4], member.getMemberId());
    member = relationMembers.get(1);
    assertEquals(relationRecord.getId(), member.getRelationId());
    assertEquals(DbUtils.nwr_enum.relation, member.getMemberType());
    assertEquals("role1", member.getMemberRole());
    assertEquals(new Integer(2), member.getSequenceId());

    assertEquals(relationIdsArr[0], member.getMemberId());
    if (verifyTags) {
        Map<String, String> tags = PostgresUtils.postgresObjToHStore(relationRecord.getTags());
        assertEquals(2, tags.size());
        assertEquals("val 2", tags.get("key 2"));
        assertEquals("val 3", tags.get("key 3"));
    }

    relationRecord = relations.get(relationIdsArr[2]);
    assertEquals(new Long(changesetId), relationRecord.getChangesetId());
    assertEquals(relationIdsArr[2], relationRecord.getId());
    assertEquals(new Long(1), relationRecord.getVersion());

    relationMembers = createQuery(getMapId()).select(currentRelationMembers).from(currentRelationMembers)
            .where(currentRelationMembers.relationId.eq(relationIdsArr[2]))
            .orderBy(currentRelationMembers.sequenceId.asc()).fetch();

    assertEquals(1, relationMembers.size());
    member = relationMembers.get(0);
    assertEquals(relationIdsArr[2], member.getRelationId());
    assertEquals(DbUtils.nwr_enum.node, member.getMemberType());
    assertEquals("role1", member.getMemberRole());
    assertEquals(new Integer(1), member.getSequenceId());

    assertEquals(nodeIdsArr[2], member.getMemberId());
    if (verifyTags) {
        Map<String, String> tags = PostgresUtils.postgresObjToHStore(relationRecord.getTags());
        assertEquals(1, tags.size());
        assertEquals("val 4", tags.get("key 4"));
    }
}

From source file:org.opencastproject.userdirectory.jpa.JpaUserAndRoleProvider.java

public User loadUser(String userName, String organizationId) {
    EntityManager em = null;/*w w w.ja  va 2s  . c om*/
    try {
        em = emf.createEntityManager();
        Query q = em.createNamedQuery("user");
        q.setParameter("u", userName);
        q.setParameter("o", organizationId);
        JpaUser user = null;
        try {
            user = (JpaUser) q.getSingleResult();
        } catch (NoResultException e) {
            return null;
        }
        Set<String> roles = user.getRoles();
        return new User(userName, user.getPassword(), user.getOrganization(),
                roles.toArray(new String[roles.size()]));
    } finally {
        if (em != null)
            em.close();
    }
}