Example usage for java.util Collections frequency

List of usage examples for java.util Collections frequency

Introduction

In this page you can find the example usage for java.util Collections frequency.

Prototype

public static int frequency(Collection<?> c, Object o) 

Source Link

Document

Returns the number of elements in the specified collection equal to the specified object.

Usage

From source file:org.wso2.carbon.ml.core.impl.SummaryStatsGenerator.java

/**
 * Calculate the frequencies of each category/interval of Numerical data columns.
 *
 *//*from  ww  w.j  a  va  2s.co m*/
protected List<SortedMap<?, Integer>> calculateNumericColumnFrequencies() {
    int noOfIntervals = summarySettings.getHistogramBins();
    Iterator<Integer> numericColumns = this.numericDataColumnPositions.iterator();
    int currentCol;
    // Iterate through all Columns with Numerical data.
    while (numericColumns.hasNext()) {
        currentCol = numericColumns.next();
        // Create a unique set from the column.
        Set<String> uniqueSet = new HashSet<String>(this.columnData.get(currentCol));
        this.unique[currentCol] = uniqueSet.size();
        if (FeatureType.CATEGORICAL.equals(this.type[currentCol])) {
            // Calculate the category frequencies.
            SortedMap<String, Integer> frequencies = new TreeMap<String, Integer>();
            for (String uniqueValue : uniqueSet) {
                if (uniqueValue != null && !uniqueValue.isEmpty()) {
                    frequencies.put(uniqueValue,
                            Collections.frequency(this.columnData.get(currentCol), uniqueValue));
                }
            }
            this.graphFrequencies.set(currentCol, frequencies);
        } else {
            // If unique values are more than the threshold, calculate interval frequencies.
            calculateIntervalFreqs(currentCol, noOfIntervals);
        }
    }

    return graphFrequencies;
}

From source file:org.apache.falcon.regression.core.util.InstanceUtil.java

public static void areWorkflowsRunning(OozieClient oozieClient, List<String> workflowIds, int totalWorkflows,
        int runningWorkflows, int killedWorkflows, int succeededWorkflows) throws OozieClientException {
    if (totalWorkflows != -1) {
        Assert.assertEquals(workflowIds.size(), totalWorkflows);
    }//from  ww w . j a  v  a2  s  . c o m
    final List<WorkflowJob.Status> statuses = new ArrayList<>();
    for (String wfId : workflowIds) {
        final WorkflowJob.Status status = oozieClient.getJobInfo(wfId).getStatus();
        LOGGER.info("wfId: " + wfId + " status: " + status);
        statuses.add(status);
    }
    if (runningWorkflows != -1) {
        Assert.assertEquals(Collections.frequency(statuses, WorkflowJob.Status.RUNNING), runningWorkflows,
                "Number of running jobs doesn't match.");
    }
    if (killedWorkflows != -1) {
        Assert.assertEquals(Collections.frequency(statuses, WorkflowJob.Status.KILLED), killedWorkflows,
                "Number of killed jobs doesn't match.");
    }
    if (succeededWorkflows != -1) {
        Assert.assertEquals(Collections.frequency(statuses, WorkflowJob.Status.SUCCEEDED), succeededWorkflows,
                "Number of succeeded jobs doesn't match.");
    }
}

From source file:hydrograph.ui.propertywindow.widgets.dialogs.lookup.LookupMapDialog.java

private void createOutputFieldColumnInMappingTable() {
    tableViewerColumn_1 = new TableViewerColumn(mappingTableViewer, SWT.NONE);
    TableColumn tblclmnPropertyValue = tableViewerColumn_1.getColumn();
    tblclmnPropertyValue.setWidth(148);// www  .  j ava 2  s.c o m
    tblclmnPropertyValue.setText(JoinMapDialogConstants.OUTPUT_FIELD);
    outputEditingSupport = new JoinMappingEditingSupport(mappingTableViewer,
            JoinMapDialogConstants.OUTPUT_FIELD);
    WidgetUtility.addVerifyListnerToOutputEditingSupport(outputEditingSupport);
    tableViewerColumn_1.setEditingSupport(outputEditingSupport);
    tableViewerColumn_1.setLabelProvider(new ColumnLabelProvider() {

        String tooltipText;

        private List<String> getOutputFieldList() {
            List<String> outputFieldList = new LinkedList<>();
            for (LookupMapProperty lookupMapProperty : mappingTableItemList) {
                outputFieldList.add(lookupMapProperty.getOutput_Field());
            }
            return outputFieldList;
        }

        @Override
        public String getToolTipText(Object element) {
            tooltipText = null;

            int occurrences = Collections.frequency(getOutputFieldList(),
                    ((LookupMapProperty) element).getOutput_Field());
            if (occurrences > 1) {
                tooltipText = FIELD_TOOLTIP_MESSAGE_DUPLICATE_FIELDS;
            }

            LookupMapProperty lookupMapProperty = (LookupMapProperty) element;
            if (StringUtils.isBlank(lookupMapProperty.getSource_Field()))
                tooltipText = FIELD_TOOLTIP_MESSAGE_FIELD_CANT_BE_EMPTY;

            return tooltipText;
        }

        @Override
        public Color getForeground(Object element) {
            int occurrences = Collections.frequency(getOutputFieldList(),
                    ((LookupMapProperty) element).getOutput_Field());
            if (occurrences > 1) {
                return CustomColorRegistry.INSTANCE.getColorFromRegistry(255, 0, 0);
            } else {
                return super.getForeground(element);
            }

        }

        @Override
        public Color getBackground(Object element) {
            LookupMapProperty lookupMapProperty = (LookupMapProperty) element;

            if (StringUtils.isBlank(lookupMapProperty.getOutput_Field()))
                return CustomColorRegistry.INSTANCE.getColorFromRegistry(0xFF, 0xDD, 0xDD);
            else
                return super.getBackground(element);
        }

        @Override
        public String getText(Object element) {
            LookupMapProperty lookupMapProperty = (LookupMapProperty) element;

            if (ParameterUtil.isParameter(lookupMapProperty.getOutput_Field()))
                lookupMapProperty.setSource_Field(lookupMapProperty.getOutput_Field());

            return lookupMapProperty.getOutput_Field();
        }
    });
}

From source file:org.lightjason.agentspeak.action.builtin.TestCActionMathStatistics.java

/**
 * test exponential selection with strict parameter
 *//*  w  ww.j a v  a  2 s  .  c o  m*/
@Test
public final void exponentialselectionstrict() {
    final List<ITerm> l_return = Collections.synchronizedList(new ArrayList<>());

    IntStream.range(0, 5000).parallel()
            .forEach(i -> new CExponentialSelection().execute(false, IContext.EMPTYPLAN,
                    Stream.of(Stream.of("a", "b").collect(Collectors.toList()),
                            Stream.of(4.5, 3.5).collect(Collectors.toList()), 1).map(CRawTerm::from)
                            .collect(Collectors.toList()),
                    l_return));

    Assert.assertEquals(
            (double) Collections.frequency(l_return.stream().map(ITerm::raw).collect(Collectors.toList()), "a")
                    / l_return.size(),
            0.73, 0.02);

    Assert.assertEquals(
            (double) Collections.frequency(l_return.stream().map(ITerm::raw).collect(Collectors.toList()), "b")
                    / l_return.size(),
            0.27, 0.02);
}

From source file:metabup.annotations.general.Annotation.java

protected void removeReplicatedFeatures(MetaClass mc) {
    List<Feature> ff = mc.getFeatures();
    List<String> ffnames = new ArrayList<String>();
    List<Feature> removeff = new ArrayList<Feature>();
    for (Feature f : ff)
        ffnames.add(f.getName());/*  w ww.j  a  v a2  s.  co m*/

    for (Feature f : ff) {
        int occ = Collections.frequency(ffnames, f.getName());
        if (occ > 1) {
            String name = f.getName();
            int i = 1;

            for (Feature f2 : ff) {
                if (f2.getName().equals(name) && i < occ) {
                    removeff.add(f2);
                    i++;
                }
            }
        }
    }

    if (!removeff.isEmpty()) {
        mc.getFeatures().removeAll(removeff);
    }
}

From source file:org.apache.falcon.regression.core.util.InstanceUtil.java

public static int getInstanceCountWithStatus(OozieClient oozieClient, String processName,
        CoordinatorAction.Status status, EntityType entityType) throws OozieClientException {
    List<CoordinatorAction> coordActions = getProcessInstanceList(oozieClient, processName, entityType);
    List<CoordinatorAction.Status> statuses = new ArrayList<>();
    for (CoordinatorAction action : coordActions) {
        statuses.add(action.getStatus());
    }/*from   w w  w .j  av a  2s  .  c  o m*/
    return Collections.frequency(statuses, status);
}

From source file:eu.mihosoft.vrl.v3d.Edge.java

private static List<Edge> boundaryEdgesOfPlaneGroup(List<Polygon> planeGroup) {
    List<Edge> edges = new ArrayList<>();

    Stream<Polygon> pStream;

    if (planeGroup.size() > 200) {
        pStream = planeGroup.parallelStream();
    } else {// w  w w  .  ja  va 2 s.com
        pStream = planeGroup.stream();
    }

    pStream.map((p) -> Edge.fromPolygon(p)).forEach((pEdges) -> {
        edges.addAll(pEdges);
    });

    Stream<Edge> edgeStream;

    if (edges.size() > 200) {
        edgeStream = edges.parallelStream();
    } else {
        edgeStream = edges.stream();
    }

    // find potential boundary edges, i.e., edges that occur once (freq=1)
    List<Edge> potentialBoundaryEdges = new ArrayList<>();
    edgeStream.forEachOrdered((e) -> {
        int count = Collections.frequency(edges, e);
        if (count == 1) {
            potentialBoundaryEdges.add(e);
        }
    });

    // now find "false boundary" edges end remove them from the 
    // boundary-edge-list
    // 
    // thanks to Susanne Hllbacher for the idea :)
    Stream<Edge> bndEdgeStream;

    if (potentialBoundaryEdges.size() > 200) {
        bndEdgeStream = potentialBoundaryEdges.parallelStream();
    } else {
        bndEdgeStream = potentialBoundaryEdges.stream();
    }

    List<Edge> realBndEdges = bndEdgeStream
            .filter(be -> edges.stream().filter(e -> falseBoundaryEdgeSharedWithOtherEdge(be, e)).count() == 0)
            .collect(Collectors.toList());

    //
    //        System.out.println("#bnd-edges: " + realBndEdges.size()
    //                + ",#edges: " + edges.size()
    //                + ", #del-bnd-edges: " + (boundaryEdges.size() - realBndEdges.size()));
    return realBndEdges;
}

From source file:org.wso2.carbon.notebook.core.util.MLUtils.java

/**
 * Get the column types from the sample points : Categorical or Numerical
 *
 * @param samplePoints Sample points//ww  w  . j  a v  a2 s .  c om
 * @return Column types list
 */
public static String[] getColumnTypes(SamplePoints samplePoints) {
    Map<String, Integer> headerMap = samplePoints.getHeader();
    int[] stringCellCount = samplePoints.getStringCellCount();
    int[] decimalCellCount = samplePoints.getDecimalCellCount();
    String[] type = new String[headerMap.size()];
    List<Integer> numericDataColumnPositions = new ArrayList<Integer>();

    // If at least one cell contains strings, then the column is considered to has string data.
    for (int col = 0; col < headerMap.size(); col++) {
        if (stringCellCount[col] > 0) {
            type[col] = FeatureType.CATEGORICAL;
        } else {
            numericDataColumnPositions.add(col);
            type[col] = FeatureType.NUMERICAL;
        }
    }

    List<List<String>> columnData = samplePoints.getSamplePoints();

    // Marking categorical data encoded as numerical data as categorical features
    for (int currentCol = 0; currentCol < headerMap.size(); currentCol++) {
        if (numericDataColumnPositions.contains(currentCol)) {
            // Create a unique set from the column.
            List<String> data = columnData.get(currentCol);

            // Check whether it is an empty column
            // Rows with missing values are not filtered. Therefore it is possible to
            // have all rows in sample with values missing in a column.
            if (data.size() == 0) {
                continue;
            }

            Set<String> uniqueSet = new HashSet<String>(data);
            int multipleOccurences = 0;

            for (String uniqueValue : uniqueSet) {
                int frequency = Collections.frequency(data, uniqueValue);
                if (frequency > 1) {
                    multipleOccurences++;
                }
            }

            // if a column has at least one decimal value, then it can't be categorical.
            // if a feature has more than X% of repetitive distinct values, then that feature can be a categorical
            // one. X = categoricalThreshold
            if (decimalCellCount[currentCol] == 0
                    && (multipleOccurences / uniqueSet.size()) * 100 >= MLConstants.CATEGORICAL_THRESHOLD) {
                type[currentCol] = FeatureType.CATEGORICAL;
            }
        }
    }

    return type;
}

From source file:org.lightjason.agentspeak.action.builtin.TestCActionMathStatistics.java

/**
 * test exponential selection with lazy parameter
 *///from   w w  w.  j ava2  s  .  co  m
@Test
public final void exponentialselectionlazy() {
    final List<ITerm> l_return = Collections.synchronizedList(new ArrayList<>());

    IntStream.range(0, 6500).parallel()
            .forEach(i -> new CExponentialSelection().execute(false, IContext.EMPTYPLAN,
                    Stream.of(Stream.of("a", "b").collect(Collectors.toList()),
                            Stream.of(4.5, 3.5).collect(Collectors.toList()), 0.5).map(CRawTerm::from)
                            .collect(Collectors.toList()),
                    l_return));

    Assert.assertEquals(
            (double) Collections.frequency(l_return.stream().map(ITerm::raw).collect(Collectors.toList()), "a")
                    / l_return.size(),
            0.73, 0.2);

    Assert.assertEquals(
            (double) Collections.frequency(l_return.stream().map(ITerm::raw).collect(Collectors.toList()), "b")
                    / l_return.size(),
            0.27, 0.2);
}

From source file:org.apache.hadoop.hdfs.server.datanode.TestDataNodeHotSwapVolumes.java

@Test(timeout = 60000)
@Ignore //HOPS does not support federation
public void testAddVolumesToFederationNN()
        throws IOException, TimeoutException, InterruptedException, ReconfigurationException {
    // Starts a Cluster with 2 NameNode and 3 DataNodes. Each DataNode has 2
    // volumes.//from w  w w .  jav  a 2  s  .  co  m
    final int numNameNodes = 2;
    final int numDataNodes = 1;
    startDFSCluster(numNameNodes, numDataNodes);
    Path testFile = new Path("/test");
    // Create a file on the first namespace with 4 blocks.
    createFile(0, testFile, 4);
    // Create a file on the second namespace with 4 blocks.
    createFile(1, testFile, 4);

    // Add 2 volumes to the first DataNode.
    final int numNewVolumes = 2;
    addVolumes(numNewVolumes);

    // Append to the file on the first namespace.
    DFSTestUtil.appendFile(cluster.getFileSystem(0), testFile, BLOCK_SIZE * 8);

    List<List<Integer>> actualNumBlocks = getNumBlocksReport(0);
    assertEquals(cluster.getDataNodes().size(), actualNumBlocks.size());
    List<Integer> blocksOnFirstDN = actualNumBlocks.get(0);
    Collections.sort(blocksOnFirstDN);
    assertEquals(Arrays.asList(2, 2, 4, 4), blocksOnFirstDN);

    // Verify the second namespace also has the new volumes and they are empty.
    actualNumBlocks = getNumBlocksReport(1);
    assertEquals(4, actualNumBlocks.get(0).size());
    assertEquals(numNewVolumes, Collections.frequency(actualNumBlocks.get(0), 0));
}