Example usage for java.util Set stream

List of usage examples for java.util Set stream

Introduction

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

Prototype

default Stream<E> stream() 

Source Link

Document

Returns a sequential Stream with this collection as its source.

Usage

From source file:io.subutai.plugin.usergrid.impl.UsergridIMPL.java

@Override
public List<String> getClusterList(Environment name) {
    List<String> c = new ArrayList();
    Set<EnvironmentContainerHost> containerHosts = name.getContainerHosts();
    containerHosts.stream().forEach((e) -> {
        c.add(e.getHostname());//from w w  w. j  a  v  a2  s  .c o  m
    });
    return c;
}

From source file:ddf.catalog.transformer.csv.common.CsvTransformerTest.java

@Test
public void getOnlyRequestedAttributes() {

    Set<String> requestedAttributes = new HashSet<>();
    requestedAttributes.add("attribute1");

    Set<AttributeDescriptor> onlyRequestedAttributes = CsvTransformer.getOnlyRequestedAttributes(metacardList,
            requestedAttributes);//w  ww.java 2s  . c  om

    assertThat(onlyRequestedAttributes, hasSize(1));
    final Optional<AttributeDescriptor> attributeDescriptorOptional = onlyRequestedAttributes.stream()
            .findFirst();
    assertThat(attributeDescriptorOptional.isPresent(), is(true));

    final AttributeDescriptor attributeDescriptor = attributeDescriptorOptional.get();
    assertThat(attributeDescriptor, notNullValue());

    final String name = attributeDescriptor.getName();
    assertThat(name, is("attribute1"));
}

From source file:uk.ac.kcl.at.ElasticGazetteerAcceptanceTest.java

@Test
public void deidentificationPerformanceTest() {
    dbmsTestUtils.createBasicInputTable();
    dbmsTestUtils.createBasicOutputTable();
    dbmsTestUtils.createDeIdInputTable();
    List<Mutant> mutants = testUtils.insertTestDataForDeidentification(env.getProperty("tblIdentifiers"),
            env.getProperty("tblInputDocs"), mutatortype, true);

    int totalTruePositives = 0;
    int totalFalsePositives = 0;
    int totalFalseNegatives = 0;

    for (Mutant mutant : mutants) {
        Set<Pattern> mutatedPatterns = new HashSet<>();
        mutant.setDeidentifiedString(elasticGazetteerService.deIdentifyString(mutant.getFinalText(),
                String.valueOf(mutant.getDocumentid())));
        Set<String> set = new HashSet<>(mutant.getOutputTokens());
        mutatedPatterns.addAll(// ww w  .  j  av  a  2  s .c  o  m
                set.stream().map(string -> Pattern.compile(Pattern.quote(string), Pattern.CASE_INSENSITIVE))
                        .collect(Collectors.toSet()));
        List<MatchResult> results = new ArrayList<>();
        for (Pattern pattern : mutatedPatterns) {
            Matcher matcher = pattern.matcher(mutant.getFinalText());
            while (matcher.find()) {
                results.add(matcher.toMatchResult());
            }
        }

        int truePositives = getTruePositiveTokenCount(mutant);
        int falsePositives = getFalsePositiveTokenCount(mutant);
        int falseNegatives = getFalseNegativeTokenCount(mutant);

        System.out.println("Doc ID " + mutant.getDocumentid() + " has " + falseNegatives
                + " unmasked identifiers from a total of " + (falseNegatives + truePositives));
        System.out.println("Doc ID " + mutant.getDocumentid() + " has " + falsePositives
                + " inaccurately masked tokens from a total of " + (falsePositives + truePositives));
        System.out.println("TP: " + truePositives + " FP: " + falsePositives + " FN: " + falseNegatives);
        System.out.println("Doc ID precision " + calcPrecision(falsePositives, truePositives));
        System.out.println("Doc ID recall " + calcRecall(falseNegatives, truePositives));
        System.out.println(mutant.getDeidentifiedString());
        System.out.println(mutant.getFinalText());
        System.out.println(mutant.getInputTokens());
        System.out.println(mutant.getOutputTokens());
        System.out.println();
        if (env.getProperty("elasticgazetteerTestOutput") != null) {
            try {
                try (BufferedWriter bw = new BufferedWriter(
                        new FileWriter(new File(env.getProperty("elasticgazetteerTestOutput") + File.separator
                                + mutant.getDocumentid())))) {
                    bw.write("Doc ID " + mutant.getDocumentid() + " has " + falseNegatives
                            + " unmasked identifiers from a total of " + (falseNegatives + truePositives));
                    bw.newLine();
                    bw.write("Doc ID " + mutant.getDocumentid() + " has " + falsePositives
                            + " inaccurately masked tokens from a total of "
                            + (falsePositives + truePositives));
                    bw.newLine();
                    bw.write("TP: " + truePositives + " FP: " + falsePositives + " FN: " + falseNegatives);
                    bw.newLine();
                    bw.write("Doc ID precision " + calcPrecision(falsePositives, truePositives));
                    bw.newLine();
                    bw.write("Doc ID recall " + calcRecall(falseNegatives, truePositives));
                    bw.newLine();
                    bw.write(mutant.getDeidentifiedString());
                    bw.newLine();
                    bw.write(mutant.getFinalText());
                    bw.newLine();
                    bw.write(mutant.getInputTokens().toString());
                    bw.newLine();
                    bw.write(mutant.getOutputTokens().toString());

                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        totalTruePositives += truePositives;
        totalFalsePositives += falsePositives;
        totalFalseNegatives += falseNegatives;
    }
    DecimalFormat df = new DecimalFormat("#.#");
    df.setRoundingMode(RoundingMode.CEILING);

    System.out.println();
    System.out.println();
    System.out.println("THIS RUN TP: " + totalTruePositives + " FP: " + totalFalsePositives + " FN: "
            + totalFalseNegatives);
    System.out.println("Doc ID precision " + calcPrecision(totalFalsePositives, totalTruePositives));
    System.out.println("Doc ID recall " + calcRecall(totalFalseNegatives, totalTruePositives));
    System.out.println(totalTruePositives + " & " + totalFalsePositives + " & " + totalFalseNegatives + " & "
            + df.format(calcPrecision(totalFalsePositives, totalTruePositives)) + " & "
            + df.format(calcRecall(totalFalseNegatives, totalTruePositives)) + " \\\\");

    if (env.getProperty("elasticgazetteerTestOutput") != null) {
        try {
            try (BufferedWriter bw = new BufferedWriter(new FileWriter(
                    new File(env.getProperty("elasticgazetteerTestOutput") + File.separator + "summary")))) {
                bw.write("THIS RUN TP: " + totalTruePositives + " FP: " + totalFalsePositives + " FN: "
                        + totalFalseNegatives);
                bw.newLine();
                bw.write("Doc ID precision " + calcPrecision(totalFalsePositives, totalTruePositives));
                bw.newLine();
                bw.write("Doc ID recall " + calcRecall(totalFalseNegatives, totalTruePositives));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:nu.yona.server.analysis.service.InactivityManagementService.java

public void createInactivityEntities(UUID userAnonymizedId, Set<IntervalInactivityDto> intervalInactivities) {
    try (LockPool<UUID>.Lock lock = userAnonymizedSynchronizer.lock(userAnonymizedId)) {
        transactionHelper.executeInNewTransaction(() -> {
            UserAnonymizedDto userAnonymized = userAnonymizedService.getUserAnonymized(userAnonymizedId);
            createWeekInactivityEntities(userAnonymizedId, intervalInactivities.stream()
                    .filter(ia -> ia.getTimeUnit() == ChronoUnit.WEEKS).collect(Collectors.toSet()));
            createDayInactivityEntities(userAnonymized, intervalInactivities.stream()
                    .filter(ia -> ia.getTimeUnit() == ChronoUnit.DAYS).collect(Collectors.toSet()));
        });//from   ww  w. j  ava 2 s  .com
    }
}

From source file:org.sardineproject.sbyod.rest.AppWebService.java

/**
 * This method removes all services from a set that are not intended for the user to manipulate,
 * for example the portal service or the dns service
 * @param services a set of services//  w  ww  .  ja va2s  . c  om
 * @return an iterable of services without configuration services
 */
private Iterable<Service> removeConfigurationServices(Set<Service> services) {
    // get the portalService
    Service portalService = get(PortalService.class).getPortalService();
    // get the dns services
    Set<Service> dnsServices = get(DnsService.class).getDnsServices();

    // remove the configuration services
    return services.stream().filter(s -> !s.equals(portalService)).filter(s -> !dnsServices.contains(s))
            .collect(Collectors.toSet());
}

From source file:com.devicehive.dao.riak.UserDaoRiakImpl.java

@Override
public long hasAccessToDevice(UserVO user, String deviceGuid) {
    Set<Long> networkIds = userNetworkDao.findNetworksForUser(user.getId());
    for (Long networkId : networkIds) {
        Set<DeviceVO> devices = networkDeviceDao.findDevicesForNetwork(networkId).stream()
                .map(deviceDao::findByUUID).collect(Collectors.toSet());
        if (devices != null) {
            long guidCount = devices.stream().map(DeviceVO::getGuid).filter(g -> g.equals(deviceGuid)).count();
            if (guidCount > 0) {
                return guidCount;
            }/*from   w w  w. j  a v a2s. c om*/
        }
    }
    return 0L;
}

From source file:uk.ac.kcl.it.DeIdentificationPKPartitionWithoutScheduling.java

@Test
public void deidentificationPerformanceTest() {
    dbmsTestUtils.createBasicInputTable();
    dbmsTestUtils.createBasicOutputTable();
    dbmsTestUtils.createDeIdInputTable();
    List<Mutant> mutants = testUtils.insertTestDataForDeidentification(env.getProperty("tblIdentifiers"),
            env.getProperty("tblInputDocs"), mutatortype);
    int totalTruePositives = 0;
    int totalFalsePositives = 0;
    int totalFalseNegatives = 0;

    for (Mutant mutant : mutants) {
        Set<Pattern> mutatedPatterns = new HashSet<>();
        mutant.setDeidentifiedString(elasticGazetteerService.deIdentifyString(mutant.getFinalText(),
                String.valueOf(mutant.getDocumentid())));
        Set<String> set = new HashSet<>(mutant.getOutputTokens());
        mutatedPatterns.addAll(/*from w  w w  .  j a v  a2s  .c  om*/
                set.stream().map(string -> Pattern.compile(Pattern.quote(string), Pattern.CASE_INSENSITIVE))
                        .collect(Collectors.toSet()));
        List<MatchResult> results = new ArrayList<>();
        for (Pattern pattern : mutatedPatterns) {
            Matcher matcher = pattern.matcher(mutant.getFinalText());
            while (matcher.find()) {
                results.add(matcher.toMatchResult());
            }
        }

        int truePositives = getTruePositiveTokenCount(mutant);
        int falsePositives = getFalsePositiveTokenCount(mutant);
        int falseNegatives = getFalseNegativeTokenCount(mutant);

        System.out.println("Doc ID " + mutant.getDocumentid() + " has " + falseNegatives
                + " unmasked identifiers from a total of " + (falseNegatives + truePositives));
        System.out.println("Doc ID " + mutant.getDocumentid() + " has " + falsePositives
                + " inaccurately masked tokens from a total of " + (falsePositives + truePositives));
        System.out.println("TP: " + truePositives + " FP: " + falsePositives + " FN: " + falseNegatives);
        System.out.println("Doc ID precision " + calcPrecision(falsePositives, truePositives));
        System.out.println("Doc ID recall " + calcRecall(falseNegatives, truePositives));
        System.out.println(mutant.getDeidentifiedString());
        System.out.println(mutant.getFinalText());
        System.out.println(mutant.getInputTokens());
        System.out.println(mutant.getOutputTokens());
        System.out.println();
        if (env.getProperty("elasticgazetteerTestOutput") != null) {
            try {
                try (BufferedWriter bw = new BufferedWriter(
                        new FileWriter(new File(env.getProperty("elasticgazetteerTestOutput") + File.separator
                                + mutant.getDocumentid())))) {
                    bw.write("Doc ID " + mutant.getDocumentid() + " has " + falseNegatives
                            + " unmasked identifiers from a total of " + (falseNegatives + truePositives));
                    bw.newLine();
                    bw.write("Doc ID " + mutant.getDocumentid() + " has " + falsePositives
                            + " inaccurately masked tokens from a total of "
                            + (falsePositives + truePositives));
                    bw.newLine();
                    bw.write("TP: " + truePositives + " FP: " + falsePositives + " FN: " + falseNegatives);
                    bw.newLine();
                    bw.write("Doc ID precision " + calcPrecision(falsePositives, truePositives));
                    bw.newLine();
                    bw.write("Doc ID recall " + calcRecall(falseNegatives, truePositives));
                    bw.newLine();
                    bw.write(mutant.getDeidentifiedString());
                    bw.newLine();
                    bw.write(mutant.getFinalText());
                    bw.newLine();
                    bw.write(mutant.getInputTokens().toString());
                    bw.newLine();
                    bw.write(mutant.getOutputTokens().toString());

                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        totalTruePositives += truePositives;
        totalFalsePositives += falsePositives;
        totalFalseNegatives += falseNegatives;
    }
    System.out.println();
    System.out.println();
    System.out.println("THIS RUN TP: " + totalTruePositives + " FP: " + totalFalsePositives + " FN: "
            + totalFalseNegatives);
    System.out.println("Doc ID precision " + calcPrecision(totalFalsePositives, totalTruePositives));
    System.out.println("Doc ID recall " + calcRecall(totalFalseNegatives, totalTruePositives));
    if (env.getProperty("elasticgazetteerTestOutput") != null) {
        try {
            try (BufferedWriter bw = new BufferedWriter(new FileWriter(
                    new File(env.getProperty("elasticgazetteerTestOutput") + File.separator + "summary")))) {
                bw.write("THIS RUN TP: " + totalTruePositives + " FP: " + totalFalsePositives + " FN: "
                        + totalFalseNegatives);
                bw.newLine();
                bw.write("Doc ID precision " + calcPrecision(totalFalsePositives, totalTruePositives));
                bw.newLine();
                bw.write("Doc ID recall " + calcRecall(totalFalseNegatives, totalTruePositives));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:ddf.catalog.metacard.duplication.DuplicationValidator.java

private ValidationViolation reportDuplicates(final Metacard metacard, String[] attributeNames,
        ValidationViolation.Severity severity) {

    Set<String> duplicates = new HashSet<>();
    ValidationViolation violation = null;

    final Set<String> uniqueAttributeNames = Stream.of(attributeNames)
            .filter(attribute -> metacard.getAttribute(attribute) != null).collect(Collectors.toSet());
    final Set<Attribute> uniqueAttributes = uniqueAttributeNames.stream()
            .map(attribute -> metacard.getAttribute(attribute)).collect(Collectors.toSet());
    if (!uniqueAttributes.isEmpty()) {
        LOGGER.debug("Checking for duplicates for id {} against attributes [{}]", metacard.getId(),
                collectionToString(uniqueAttributeNames));

        SourceResponse response = query(uniqueAttributes);
        if (response != null) {
            response.getResults().forEach(result -> duplicates.add(result.getMetacard().getId()));
        }/*from   ww w.j  a v  a 2s.c  o  m*/
        if (!duplicates.isEmpty()) {

            violation = createViolation(uniqueAttributeNames, duplicates, severity);
            LOGGER.debug(violation.getMessage());
        }
    }
    return violation;
}