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:hoot.services.osm.OsmTestUtils.java

public static void verifyTestRelationsNoWaysUnmodified(final Set<Long> relationIds, final Set<Long> nodeIds,
        final long changesetId, final boolean verifyTags) {
    QCurrentRelations currentRelations = QCurrentRelations.currentRelations;
    final Long[] relationIdsArr = relationIds.toArray(new Long[] {});
    final Long[] nodeIdsArr = nodeIds.toArray(new Long[] {});
    try {// w ww .ja  va  2  s .co m
        final Map<Long, CurrentRelations> relations = new SQLQuery(conn, DbUtils.getConfiguration(mapId))
                .from(currentRelations).where((currentRelations.changesetId.eq(changesetId)))
                .map(currentRelations.id, currentRelations)

        ;
        Assert.assertEquals(3, relations.size());

        QCurrentRelationMembers currentRelationMembers = QCurrentRelationMembers.currentRelationMembers;
        CurrentRelations relationRecord = (CurrentRelations) relations.get(relationIdsArr[0]);
        Assert.assertEquals(new Long(changesetId), relationRecord.getChangesetId());
        Assert.assertEquals(relationIdsArr[0], relationRecord.getId());
        Assert.assertEquals(new Long(1), relationRecord.getVersion());
        List<CurrentRelationMembers> relationMembers = new SQLQuery(conn, DbUtils.getConfiguration(mapId))
                .from(currentRelationMembers).where(currentRelationMembers.relationId.eq(relationIdsArr[0]))
                .orderBy(currentRelationMembers.sequenceId.asc()).list(currentRelationMembers)

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

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

        Assert.assertEquals(nodeIdsArr[2], member.getMemberId());
        if (verifyTags) {
            try {
                Map<String, String> tags = PostgresUtils
                        .postgresObjToHStore((PGobject) relationRecord.getTags());
                Assert.assertEquals(1, tags.size());
                Assert.assertEquals("val 1", tags.get("key 1"));
            } catch (Exception e) {
                Assert.fail("Error checking relation tags: " + e.getMessage());
            }
        }

        relationRecord = (CurrentRelations) relations.get(relationIdsArr[1]);
        Assert.assertEquals(new Long(changesetId), relationRecord.getChangesetId());
        Assert.assertEquals(relationIdsArr[1], relationRecord.getId());
        Assert.assertEquals(new Long(1), relationRecord.getVersion());
        relationMembers = new SQLQuery(conn, DbUtils.getConfiguration(mapId)).from(currentRelationMembers)
                .where(currentRelationMembers.relationId.eq(relationIdsArr[1]))
                .orderBy(currentRelationMembers.sequenceId.asc()).list(currentRelationMembers)

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

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

        Assert.assertEquals(relationIdsArr[0], member.getMemberId());
        if (verifyTags) {
            try {
                Map<String, String> tags = PostgresUtils
                        .postgresObjToHStore((PGobject) relationRecord.getTags());
                Assert.assertEquals(2, tags.size());
                Assert.assertEquals("val 2", tags.get("key 2"));
                Assert.assertEquals("val 3", tags.get("key 3"));
            } catch (Exception e) {
                Assert.fail("Error checking relation tags: " + e.getMessage());
            }
        }

        relationRecord = (CurrentRelations) relations.get(relationIdsArr[2]);
        Assert.assertEquals(new Long(changesetId), relationRecord.getChangesetId());
        Assert.assertEquals(relationIdsArr[2], relationRecord.getId());
        Assert.assertEquals(new Long(1), relationRecord.getVersion());
        relationMembers = new SQLQuery(conn, DbUtils.getConfiguration(mapId)).from(currentRelationMembers)
                .where(currentRelationMembers.relationId.eq(relationIdsArr[2]))
                .orderBy(currentRelationMembers.sequenceId.asc()).list(currentRelationMembers)

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

        Assert.assertEquals(nodeIdsArr[2], member.getMemberId());
        if (verifyTags) {
            try {
                Map<String, String> tags = PostgresUtils
                        .postgresObjToHStore((PGobject) relationRecord.getTags());
                Assert.assertEquals(1, tags.size());
                Assert.assertEquals("val 4", tags.get("key 4"));
            } catch (Exception e) {
                Assert.fail("Error checking relation tags: " + e.getMessage());
            }
        }
    } catch (Exception e) {
        Assert.fail("Error checking relations with no ways: " + e.getMessage());
    }
}

From source file:com.floragunn.searchguard.dlic.rest.validation.AbstractConfigurationValidator.java

private void addErrorMessage(final XContentBuilder builder, final String message, final Set<String> keys)
        throws IOException {
    if (!keys.isEmpty()) {
        builder.startObject(message);/*from   w  ww.j  a  va2  s  . co m*/
        builder.field("keys", Joiner.on(",").join(keys.toArray(new String[0])));
        builder.endObject();
    }
}

From source file:net.riccardocossu.autodoc.maven.AutodocMojo.java

@SuppressWarnings("unchecked")
public void execute() throws MojoExecutionException {
    try {/*from w  w  w.j  a v  a2 s . c o m*/
        Set<URL> urls = new HashSet<URL>();
        List<String> elements = project.getCompileClasspathElements();
        for (String element : elements) {
            urls.add(new File(element).toURI().toURL());
        }

        ClassLoader contextClassLoader = URLClassLoader.newInstance(urls.toArray(new URL[0]),
                Thread.currentThread().getContextClassLoader());

        Thread.currentThread().setContextClassLoader(contextClassLoader);

    } catch (DependencyResolutionRequiredException e) {
        throw new MojoExecutionException("Error expanding classloader", e);
    } catch (MalformedURLException e) {
        throw new MojoExecutionException("Error expanding classloader", e);
    }
    File f = new File(outputDirectory.getAbsolutePath() + "/autodoc");

    if (!f.exists()) {
        f.mkdirs();
    }

    BaseConfiguration conf = new BaseConfiguration();
    conf.addProperty(Engine.CONFIG_PACKAGES, packages);
    conf.addProperty(Engine.CONFIG_INPUT_PLUGINS, inputPlugins);
    conf.addProperty(Engine.CONFIG_OUTPUT_PLUGINS, outputPlugins);
    conf.addProperty(Engine.CONFIG_BASE_OUTPUT_DIR, f.getAbsolutePath());
    Engine eng = new Engine(conf);
    List<PackageContainer> parsedPackages = eng.execute();
    getLog().info(String.format("Parsed %d packages", parsedPackages.size()));
}

From source file:com.github.rwhogg.git_vcr.VelocityReport.java

/**
 * extract the changes between two reviews
 * @return A map of (old) files to changes in results
 *///  www .  j a v a 2  s.co m
@SuppressWarnings("rawtypes")
private Map<String, Changes> extractChanges() {
    Map<String, Changes> changeMap = new HashMap<>();

    List<ImmutablePair<String, String>> changedFiles = Util.getFilesChanged(patch);
    // FIXME: for now, we'll just assume no files were added or deleted
    for (ImmutablePair<String, String> filePair : changedFiles) {
        String oldFileName = filePair.getLeft();
        String newFileName = filePair.getRight();
        Changes changesForThisFile = new Changes();
        Map<Class, List<String>> resultsForOldFile = oldResults.getResultsFor(oldFileName);
        Map<Class, List<String>> resultsForNewFile = newResults.getResultsFor(newFileName);
        Set<Class> toolsUsed = resultsForOldFile.keySet();
        assert toolsUsed.equals(resultsForNewFile.keySet());

        // for each tool, go through and detect changes
        for (Class toolUsed : toolsUsed) {
            List<String> oldResultListFromThisTool = resultsForOldFile.get(toolUsed);
            List<String> newResultListFromThisTool = resultsForNewFile.get(toolUsed);
            Set<String> oldResultsFromThisTool = new HashSet<>(oldResultListFromThisTool);
            Set<String> newResultsFromThisTool = new HashSet<>(newResultListFromThisTool);
            Set<String> additions = Sets.difference(newResultsFromThisTool, oldResultsFromThisTool);
            Set<String> subtractions = Sets.difference(oldResultsFromThisTool, newResultsFromThisTool);

            // construct the change
            List<String> additionList = Arrays.asList(additions.toArray(new String[additions.size()]));
            List<String> subtractionList = Arrays.asList(subtractions.toArray(new String[subtractions.size()]));
            ImmutablePair<List<String>, List<String>> changeListPair = ImmutablePair.of(additionList,
                    subtractionList);
            changesForThisFile.put(toolUsed, changeListPair);
        }

        changeMap.put(oldFileName, changesForThisFile);
    }

    return changeMap;
}

From source file:org.nbheaven.sqe.codedefects.history.controlcenter.panels.SQEHistoryPanel.java

private void addSelectedProvider(QualityProvider provider) {
    Set<String> l = new HashSet<String>(Arrays.asList(getSelectedProviders()));
    l.add(provider.getId());/*w  ww  .j  av  a2s.  c  o m*/
    setSelectedProviders(l.toArray(new String[l.size()]));
}

From source file:edu.kit.dama.ui.simon.panel.SimonMainPanel.java

/**
 * Reload the view and refresh the status of all probes.
 *//*  w  w w  . j  av  a  2 s .c  o  m*/
private void reload() {
    LOGGER.debug("Reloading main panel");

    //remove all tabs and clear all categories
    for (Tab tab : tabs) {
        tabSheet.removeTab(tab);
        probesByCategory.clear();
        tabsByCategory.clear();
    }

    //get all probes
    AbstractProbe[] probes = SimonConfigurator.getSingleton().getProbes();
    LOGGER.debug(" - Obtaining categories for {} probes", probes.length);
    for (AbstractProbe probe : probes) {
        //refresh the status
        probe.refreshProbeStatus();
        //obtain category and assign probe to according list
        String currentProbesCategory = probe.getCategory();
        List<AbstractProbe> probesInCategory = probesByCategory.get(currentProbesCategory);
        if (probesInCategory == null) {
            LOGGER.debug(" - Obtained new category {}", currentProbesCategory);
            probesInCategory = new LinkedList<>();
            probesInCategory.add(probe);
            LOGGER.debug(" - Adding probe {} to new category", probe.getName());
            probesByCategory.put(currentProbesCategory, probesInCategory);
        } else {
            LOGGER.debug(" - Adding probe {} to existing category {}",
                    new Object[] { probe.getName(), currentProbesCategory });
            probesInCategory.add(probe);
        }
    }

    //sort all category keys by name
    Set<String> keys = probesByCategory.keySet();
    String[] aKeys = keys.toArray(new String[keys.size()]);
    Arrays.sort(aKeys);
    LOGGER.debug(" - Building category tabs");
    for (String key : aKeys) {
        tabsByCategory.put(key, createCategoryTab(probesByCategory.get(key)));
    }
    tabsByCategory.put("Overview", buildOverviewTab(aKeys));
    tabs.add(tabSheet.addTab(tabsByCategory.get("Overview"), "Overview"));

    for (String key : aKeys) {
        Tab categoryTab = tabSheet.addTab(tabsByCategory.get(key), key);
        List<AbstractProbe> probeList = probesByCategory.get(key);
        if (CollectionUtils.find(probeList, new Predicate() {
            @Override
            public boolean evaluate(Object o) {
                return ((AbstractProbe) o).getCurrentStatus().equals(AbstractProbe.PROBE_STATUS.FAILED);
            }
        }) != null) {
            categoryTab.setIcon(new ThemeResource("img/icons/warning.png"));
        }

        tabs.add(categoryTab);
    }

    LOGGER.debug("Layout successfully created.");
}

From source file:jp.co.nemuzuka.service.impl.ProjectServiceImpl.java

/**
 * LabelValueBean?./*from  www .  ja  v  a2 s .c o  m*/
 * @param projectKeySet KeySet
 * @return LabelValueBeanList(???)
 */
protected List<LabelValueBean> createUserProjectList(Set<Key> projectKeySet) {

    List<ProjectModel> projectList = projectDao.getList(projectKeySet.toArray(new Key[0]));
    return createUserProjectList(projectList);
}

From source file:org.nbheaven.sqe.codedefects.history.controlcenter.panels.SQEHistoryPanel.java

private void removeSelectedProvider(QualityProvider provider) {
    Set<String> l = new HashSet<String>(Arrays.asList(getSelectedProviders()));
    l.remove(provider.getId());//w w  w.j  a  v a2 s . c o m
    setSelectedProviders(l.toArray(new String[l.size()]));
}

From source file:hoot.services.osm.OsmTestUtils.java

public static void verifyTestNodesUnmodified(final Set<Long> nodeIds, final long changesetId,
        final BoundingBox originalBounds, final boolean verifyTags) {
    try {//from   w  w w . ja va 2  s .  c o m
        QCurrentNodes currentNodes = QCurrentNodes.currentNodes;

        final Long[] nodeIdsArr = nodeIds.toArray(new Long[] {});
        final Map<Long, CurrentNodes> nodes = new SQLQuery(conn, DbUtils.getConfiguration(mapId))
                .from(currentNodes).where((currentNodes.changesetId.eq(changesetId)))
                .map(currentNodes.id, currentNodes)

        ;
        Assert.assertEquals(5, nodes.size());

        CurrentNodes nodeRecord = (CurrentNodes) nodes.get(nodeIdsArr[0]);
        Assert.assertEquals(new Long(changesetId), nodeRecord.getChangesetId());
        Assert.assertEquals(new Integer(
                (int) (DbUtils.toDbCoordPrecision(originalBounds.getMinLat()) * GeoUtils.GEO_RECORD_SCALE)),
                nodeRecord.getLatitude());
        Assert.assertEquals(new Integer(
                (int) (DbUtils.toDbCoordPrecision(originalBounds.getMinLon()) * GeoUtils.GEO_RECORD_SCALE)),
                nodeRecord.getLongitude());
        Assert.assertEquals(nodeIdsArr[0], nodeRecord.getId());
        Assert.assertEquals(new Long(1), nodeRecord.getVersion());
        if (verifyTags) {
            try {
                Map<String, String> tags = PostgresUtils.postgresObjToHStore((PGobject) nodeRecord.getTags());
                Assert.assertEquals(2, tags.size());
                //System.out.println(tags.get("key 1"));
                Assert.assertEquals("val 1", tags.get("key 1"));
                //System.out.println(tags.get("key 2"));
                Assert.assertEquals("val 2", tags.get("key 2"));
            } catch (Exception e) {
                Assert.fail("Error checking node tags: " + e.getMessage());
            }
        }

        nodeRecord = (CurrentNodes) nodes.get(nodeIdsArr[1]);
        Assert.assertEquals(new Long(changesetId), nodeRecord.getChangesetId());
        Assert.assertEquals(new Integer(
                (int) (DbUtils.toDbCoordPrecision(originalBounds.getMaxLat()) * GeoUtils.GEO_RECORD_SCALE)),
                nodeRecord.getLatitude());
        Assert.assertEquals(new Integer(
                (int) (DbUtils.toDbCoordPrecision(originalBounds.getMaxLon()) * GeoUtils.GEO_RECORD_SCALE)),
                nodeRecord.getLongitude());
        Assert.assertEquals(nodeIdsArr[1], nodeRecord.getId());
        Assert.assertEquals(new Long(1), nodeRecord.getVersion());
        if (verifyTags) {
            try {
                Assert.assertTrue(nodeRecord.getTags() == null
                        || StringUtils.isEmpty(((PGobject) nodeRecord.getTags()).getValue()));
            } catch (Exception e) {
                Assert.fail("Error checking node tags: " + e.getMessage());
            }
        }

        nodeRecord = (CurrentNodes) nodes.get(nodeIdsArr[2]);
        Assert.assertEquals(new Long(changesetId), nodeRecord.getChangesetId());
        Assert.assertEquals(new Integer(
                (int) (DbUtils.toDbCoordPrecision(originalBounds.getMinLat()) * GeoUtils.GEO_RECORD_SCALE)),
                nodeRecord.getLatitude());
        Assert.assertEquals(new Integer(
                (int) (DbUtils.toDbCoordPrecision(originalBounds.getMinLon()) * GeoUtils.GEO_RECORD_SCALE)),
                nodeRecord.getLongitude());
        Assert.assertEquals(nodeIdsArr[2], nodeRecord.getId());
        Assert.assertEquals(new Long(1), nodeRecord.getVersion());
        if (verifyTags) {
            try {
                Assert.assertTrue(nodeRecord.getTags() == null
                        || StringUtils.isEmpty(((PGobject) nodeRecord.getTags()).getValue()));
            } catch (Exception e) {
                Assert.fail("Error checking node tags: " + e.getMessage());
            }
        }

        nodeRecord = (CurrentNodes) nodes.get(nodeIdsArr[3]);
        Assert.assertEquals(new Long(changesetId), nodeRecord.getChangesetId());
        Assert.assertEquals(new Integer(
                (int) (DbUtils.toDbCoordPrecision(originalBounds.getMinLat()) * GeoUtils.GEO_RECORD_SCALE)),
                nodeRecord.getLatitude());
        Assert.assertEquals(new Integer(
                (int) (DbUtils.toDbCoordPrecision(originalBounds.getMinLon()) * GeoUtils.GEO_RECORD_SCALE)),
                nodeRecord.getLongitude());
        Assert.assertEquals(nodeIdsArr[3], nodeRecord.getId());
        Assert.assertEquals(new Long(1), nodeRecord.getVersion());
        if (verifyTags) {
            try {
                Map<String, String> tags = PostgresUtils.postgresObjToHStore((PGobject) nodeRecord.getTags());
                Assert.assertEquals(1, tags.size());
                Assert.assertEquals("val 3", tags.get("key 3"));
            } catch (Exception e) {
                Assert.fail("Error checking node tags: " + e.getMessage());
            }
        }

        nodeRecord = (CurrentNodes) nodes.get(nodeIdsArr[4]);
        Assert.assertEquals(new Long(changesetId), nodeRecord.getChangesetId());
        Assert.assertEquals(new Integer(
                (int) (DbUtils.toDbCoordPrecision(originalBounds.getMinLat()) * GeoUtils.GEO_RECORD_SCALE)),
                nodeRecord.getLatitude());
        Assert.assertEquals(new Integer(
                (int) (DbUtils.toDbCoordPrecision(originalBounds.getMinLon()) * GeoUtils.GEO_RECORD_SCALE)),
                nodeRecord.getLongitude());
        Assert.assertEquals(nodeIdsArr[4], nodeRecord.getId());
        Assert.assertEquals(new Long(1), nodeRecord.getVersion());
        if (verifyTags) {
            try {
                Map<String, String> tags = PostgresUtils.postgresObjToHStore((PGobject) nodeRecord.getTags());
                Assert.assertEquals(1, tags.size());
                Assert.assertEquals("val 4", tags.get("key 4"));
            } catch (Exception e) {
                Assert.fail("Error checking node tags: " + e.getMessage());
            }
        }
    } catch (Exception e) {
        Assert.fail("Error checking nodes: " + e.getMessage());
    }
}

From source file:net.lightbody.bmp.proxy.jetty.servlet.MultiPartRequest.java

/** Get the part names.
 * @return an array of part names//from  w w  w  .j a v a 2s  .co  m
 */
public String[] getPartNames() {
    Set s = _partMap.keySet();
    return (String[]) s.toArray(new String[s.size()]);
}