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.streamsets.pipeline.lib.util.ProtobufTypeUtil.java

private static Set<Descriptors.FileDescriptor> getDependencies(
        Map<String, Set<Descriptors.FileDescriptor>> dependenciesMap,
        Map<String, Descriptors.FileDescriptor> fileDescriptorMap, DescriptorProtos.FileDescriptorProto file,
        DescriptorProtos.FileDescriptorSet set) throws StageException {
    Set<Descriptors.FileDescriptor> result = new LinkedHashSet<>();
    for (String name : file.getDependencyList()) {
        DescriptorProtos.FileDescriptorProto fileDescriptorProto = null;
        for (DescriptorProtos.FileDescriptorProto fdp : set.getFileList()) {
            if (name.equals(fdp.getName())) {
                fileDescriptorProto = fdp;
                break;
            }//from   w  ww .j ava  2s.  c om
        }
        if (fileDescriptorProto == null) {
            // could not find the message type from all the proto files contained in the descriptor file
            throw new StageException(Errors.PROTOBUF_01, file.getName());
        }
        Descriptors.FileDescriptor fileDescriptor;
        if (fileDescriptorMap.containsKey(fileDescriptorProto.getName())) {
            fileDescriptor = fileDescriptorMap.get(fileDescriptorProto.getName());
        } else {
            Set<Descriptors.FileDescriptor> deps = new LinkedHashSet<>();
            if (dependenciesMap.containsKey(name)) {
                deps.addAll(dependenciesMap.get(name));
            } else {
                deps.addAll(getDependencies(dependenciesMap, fileDescriptorMap, fileDescriptorProto, set));
            }
            try {
                fileDescriptor = Descriptors.FileDescriptor.buildFrom(fileDescriptorProto,
                        deps.toArray(new Descriptors.FileDescriptor[deps.size()]));
            } catch (Descriptors.DescriptorValidationException e) {
                throw new StageException(Errors.PROTOBUF_07, e.getDescription(), e);
            }
        }
        result.add(fileDescriptor);
    }
    return result;
}

From source file:com.acc.controller.OrderController.java

protected List<OrderHistoryData> getAllOrdersForStatuses(final String statuses) {
    if ("all".equals(statuses)) {
        return orderFacade.getOrderHistoryForStatuses();
    }/*from  w  ww .  j a va2  s  . c om*/
    final Set<OrderStatus> statusSet = extractOrderStatuses(statuses);
    return orderFacade.getOrderHistoryForStatuses(statusSet.toArray(new OrderStatus[statusSet.size()]));
}

From source file:eu.eexcess.diversityasurement.iaselect.IAselect.java

private String sToString(Set<Document> S) {
    return new StringBuilder().append("S:{").append(StringUtils.join(S.toArray(new Document[0]), ", "))
            .append("}").toString();
}

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

public static Set<Long> createTestRelationsNoWays(final long changesetId, final Set<Long> nodeIds)
        throws Exception {
    Set<Long> relationIds = new LinkedHashSet<Long>();
    final Long[] nodeIdsArr = nodeIds.toArray(new Long[] {});
    Map<String, String> tags = new HashMap<String, String>();
    List<RelationMember> members = new ArrayList<RelationMember>();

    members.add(new RelationMember(nodeIdsArr[0], ElementType.Node, "role1"));
    members.add(new RelationMember(nodeIdsArr[2], ElementType.Node));
    tags.put("key 1", "val 1");
    final long firstRelationId = Relation.insertNew(changesetId, mapId, members, tags, conn);
    relationIds.add(firstRelationId);// w w w.  ja v a2s  . c  o  m
    tags.clear();
    members.clear();

    tags.put("key 2", "val 2");
    tags.put("key 3", "val 3");
    members.add(new RelationMember(nodeIdsArr[4], ElementType.Node, "role1"));
    members.add(new RelationMember(firstRelationId, ElementType.Relation, "role1"));
    relationIds.add(Relation.insertNew(changesetId, mapId, members, tags, conn));
    tags.clear();
    members.clear();

    tags.put("key 4", "val 4");
    members.add(new RelationMember(nodeIdsArr[2], ElementType.Node, "role1"));
    relationIds.add(Relation.insertNew(changesetId, mapId, members, tags, conn));
    tags.clear();
    members.clear();

    return relationIds;
}

From source file:org.commonjava.maven.atlas.graph.spi.neo4j.io.Conversions.java

public static String[] toStringArray(final Collection<?> sources) {
    final Set<String> result = new LinkedHashSet<String>(sources.size());
    for (final Object object : sources) {
        if (object == null) {
            continue;
        }//  w w w  .j a  v  a2  s  . c o m

        result.add(object.toString());
    }

    return result.toArray(new String[result.size()]);
}

From source file:io.joynr.examples.jee.RadioProviderBean.java

@Override
public void shuffleStations() {
    Set<RadioStation> radioStations = radioStationDatabase.getRadioStations();
    int randomIndex = RandomUtils.nextInt(radioStations.size());
    radioStationDatabase.setCurrentStation(radioStations.toArray(new RadioStation[0])[randomIndex]);
}

From source file:com.linkedin.pinot.common.metadata.IndexLoadingConfigMetadataTest.java

@Test
public void testInvertedIndexConfig() {
    Configuration resourceMetadata = getTestResourceMetadata();
    IndexLoadingConfigMetadata indexLoadingConfigMetadata = new IndexLoadingConfigMetadata(resourceMetadata);
    Set<String> loadingInvertedIndexColumns = indexLoadingConfigMetadata.getLoadingInvertedIndexColumns();

    System.out.println("loadingInvertedIndexColumns is "
            + Arrays.toString(loadingInvertedIndexColumns.toArray(new String[0])));
    Assert.assertEquals(10, loadingInvertedIndexColumns.size());
    for (int j = 0; j < 10; ++j) {
        String columnName = "col" + j;
        Assert.assertTrue(indexLoadingConfigMetadata.isLoadingInvertedIndexForColumn(columnName));
    }//from www .java 2  s .co  m
    for (int j = 10; j < 20; ++j) {
        String columnName = "col" + j;
        Assert.assertFalse(indexLoadingConfigMetadata.isLoadingInvertedIndexForColumn(columnName));
    }
}

From source file:com.healthcit.cacure.model.TableQuestionTest.java

@Test
@DataSet("classpath:skips_on_tables.xml")
public void testGetSkipAffectees_single() {
    TableQuestion tquest = em.find(TableQuestion.class, 1014L);
    Set<BaseSkipPatternDetail> skipAffectees = tquest.getSkipAffectees();
    assertNotNull(skipAffectees);//from w ww .j  a va2 s.c o  m
    assertEquals(1, skipAffectees.size());
    BaseSkipPatternDetail detail = skipAffectees.toArray(new BaseSkipPatternDetail[0])[0];
    assertEquals(new Long(1050), detail.getId());
    assertEquals(new Long(1050), detail.getSkip().getId());
    assertEquals(new Long(1031), detail.getFormElementId());
    assertNull(detail.getFormId());
    assertEquals(new Long(1008), detail.getSkipTriggerForm().getId());
    assertEquals(new Long(1014), detail.getSkipTriggerQuestion().getId());
}

From source file:com.healthcit.cacure.model.TableQuestionTest.java

@Test
@DataSet("classpath:skips_on_tables.xml")
public void testGetSkipAffectees_multi() {
    TableQuestion tquest = em.find(TableQuestion.class, 1020L);
    Set<BaseSkipPatternDetail> skipAffectees = tquest.getSkipAffectees();
    assertNotNull(skipAffectees);//  ww w  .  j  ava2  s. c om
    assertEquals(1, skipAffectees.size());
    BaseSkipPatternDetail detail = skipAffectees.toArray(new BaseSkipPatternDetail[0])[0];
    assertEquals(new Long(1055), detail.getId());
    assertEquals(new Long(1055), detail.getSkip().getId());
    assertEquals(new Long(1035), detail.getFormElementId());
    assertNull(detail.getFormId());
    assertEquals(new Long(1008), detail.getSkipTriggerForm().getId());
    assertEquals(new Long(1020), detail.getSkipTriggerQuestion().getId());
}

From source file:com.healthcit.cacure.model.TableQuestionTest.java

@Test
@DataSet("classpath:skips_on_tables.xml")
public void testGetSkipAffectees_static() {
    TableQuestion tquest = em.find(TableQuestion.class, 1027L);
    Set<BaseSkipPatternDetail> skipAffectees = tquest.getSkipAffectees();
    assertNotNull(skipAffectees);/*from  ww  w .  j  a v a 2  s.c o m*/
    assertEquals(2, skipAffectees.size());
    BaseSkipPatternDetail[] array = skipAffectees.toArray(new BaseSkipPatternDetail[0]);
    BaseSkipPatternDetail detail0 = array[0];
    BaseSkipPatternDetail detail1 = array[1];
    assertArrayEquals(new long[] { 10232, 10233 },
            new long[] { detail0.getSkip().getIdentifyingAnswerValue().getId(),
                    detail1.getSkip().getIdentifyingAnswerValue().getId() });
}