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.apache.falcon.regression.core.util.InstanceUtil.java

/**
 * Checks that actual number of instances with different statuses are equal to expected number
 * of instances with matching statuses.//from www .  ja  va 2 s.c  om
 *
 * @param instancesResult kind of response from API which should contain information about
 *                        instances <p/>
 *                        All parameters below reflect number of expected instances with some
 *                        kind of status.
 * @param totalCount      total number of instances.
 * @param runningCount    number of running instances.
 * @param suspendedCount  number of suspended instance.
 * @param waitingCount    number of waiting instance.
 * @param killedCount     number of killed instance.
 */
public static void validateResponse(InstancesResult instancesResult, int totalCount, int runningCount,
        int suspendedCount, int waitingCount, int killedCount) {
    InstancesResult.Instance[] instances = instancesResult.getInstances();
    LOGGER.info("instances: " + Arrays.toString(instances));
    Assert.assertNotNull(instances, "instances should be not null");
    Assert.assertEquals(instances.length, totalCount, "Total Instances");
    List<InstancesResult.WorkflowStatus> statuses = new ArrayList<>();
    for (InstancesResult.Instance instance : instances) {
        final InstancesResult.WorkflowStatus status = instance.getStatus();
        LOGGER.info("status: " + status + ", instance: " + instance.getInstance());
        statuses.add(status);
    }
    Assert.assertEquals(Collections.frequency(statuses, InstancesResult.WorkflowStatus.RUNNING), runningCount,
            "Running Instances");
    Assert.assertEquals(Collections.frequency(statuses, InstancesResult.WorkflowStatus.SUSPENDED),
            suspendedCount, "Suspended Instances");
    Assert.assertEquals(Collections.frequency(statuses, InstancesResult.WorkflowStatus.WAITING), waitingCount,
            "Waiting Instances");
    Assert.assertEquals(Collections.frequency(statuses, InstancesResult.WorkflowStatus.KILLED), killedCount,
            "Killed Instances");
}

From source file:com.lines.activitys.OptionsActivity.java

/**
 * Here we get the list of characters in the database
 * /*from   www  .  jav a 2s  .  c o  m*/
 */
private void populateCharacters() {
    mCursor = mDbAdapter.fetchAllLines();

    // First get the data from "character" column and filter out unwanted
    // characters (e.g. STAGE)
    if (mCursor.moveToFirst()) {
        do {
            String character = mCursor.getString(mCursor.getColumnIndex("character"));
            if (!(character.equals("STAGE") || character.contains("and"))) {
                characters.add(character);
            }
        } while (mCursor.moveToNext());
    }

    HashMap<String, Integer> charOccur = new HashMap<String, Integer>();

    // Get the number of lines spoken by each character and store in HashMap
    Set<String> unique = new HashSet<String>(characters);
    for (String key : unique) {
        charOccur.put(key, Collections.frequency(characters, key));
    }

    characters.clear();

    // Sort character list based on the number of lines they have
    while (charOccur.size() > 0) {
        int max = Collections.max(charOccur.values());
        characters.add(getKeyByValue(charOccur, max));
        charOccur.remove(getKeyByValue(charOccur, max));
    }

    // Set contents of Character Spinner
    mAdapterChar = new ArrayAdapter<String>(OptionsActivity.this, android.R.layout.simple_spinner_item,
            characters);
    mAdapterChar.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mChar.setAdapter(mAdapterChar);

    mCursor.close();
}

From source file:org.jsweet.input.typescriptdef.visitor.JavaDefModelPrinter.java

@Override
public void visitTypeDeclaration(TypeDeclaration typeDeclaration) {
    // typeDeclaration.setName(toJavaDeclarationName(typeDeclaration.getName()));
    if (typeDeclaration.isExternal()) {
        return;//from  w w  w. j av a2 s  .c o  m
    }
    boolean innerType = getParent() instanceof TypeDeclaration;

    StringBuilder mergedSuperTypeList = new StringBuilder();
    if (typeDeclaration.getMergedSuperTypes() != null) {
        for (TypeReference type : typeDeclaration.getMergedSuperTypes()) {
            mergedSuperTypeList.append(type.getName() + ".class,");
        }
        if (mergedSuperTypeList.length() > 1) {
            mergedSuperTypeList.deleteCharAt(mergedSuperTypeList.length() - 1);
            typeDeclaration.addStringAnnotation(JSweetDefTranslatorConfig.ANNOTATION_EXTENDS + "({"
                    + mergedSuperTypeList.toString() + "})");
        }
    }
    if (!innerType) {
        clearOutput();
        currentModuleName = getCurrentModuleName();

        print("package " + currentModuleName + ";").println();

        // dynamically create imports
        Set<String> imports = new HashSet<String>();
        new Scanner(this) {
            @Override
            public void visitTypeReference(TypeReference typeReference) {
                TypeDeclaration enclosingTypeDecl = getParent(TypeDeclaration.class);
                if (typeReference.getName() != null && enclosingTypeDecl != null
                        && typeReference.getName().equals(enclosingTypeDecl.getName())) {
                    return;
                }

                Type t = lookupType(typeReference, null);
                if (t instanceof TypeDeclaration) {
                    TypeDeclaration typeDeclaration = (TypeDeclaration) t;
                    String name = context.getTypeName(typeDeclaration);
                    if (!typeDeclaration.isExternal() && name != null && !(typeReference.getName().contains(".")
                            && typeReference.getName().equals(name))) {
                        imports.add(name);
                    }
                }
                super.visitTypeReference(typeReference);
            }
        }.visitTypeDeclaration(typeDeclaration);
        List<String> importShortNames = imports.stream().map(name -> Util.getSimpleName(name))
                .collect(Collectors.toList());
        List<String> clashes = new ArrayList<>();
        for (String typeName : imports) {
            if (!typeName.startsWith(currentModuleName + ".")) {
                if (typeName.contains(".")) {
                    if (Collections.frequency(importShortNames, Util.getSimpleName(typeName)) > 1) {
                        clashes.add(typeName);
                    } else {
                        print("import ").print(typeName).print(";").println();
                    }
                }
            }
        }
        for (String clash : clashes) {
            new Scanner(this) {
                @Override
                public void visitTypeReference(TypeReference typeReference) {
                    TypeDeclaration enclosingTypeDecl = getParent(TypeDeclaration.class);
                    if (typeReference.getName() != null && enclosingTypeDecl != null
                            && typeReference.getName().equals(enclosingTypeDecl.getName())) {
                        return;
                    }

                    Type t = lookupType(typeReference, null);
                    if (t instanceof TypeDeclaration) {
                        TypeDeclaration typeDeclaration = (TypeDeclaration) t;
                        String name = context.getTypeName(typeDeclaration);
                        if (clash.equals(name)) {
                            typeReference.setName(name);
                        }
                    }
                    super.visitTypeReference(typeReference);
                }
            }.visitTypeDeclaration(typeDeclaration);
        }

        printDocumentation(typeDeclaration);
        printAnnotations(typeDeclaration);
        print("public ");
    } else {
        printDocumentation(typeDeclaration);
        printAnnotations(typeDeclaration);
        printIndent().print("public ");
    }
    if (typeDeclaration.hasModifier("static")) {
        print("static ");
    }
    if (typeDeclaration.hasModifier("abstract")) {
        print("abstract ");
    }
    if (JSweetDefTranslatorConfig.GLOBALS_CLASS_NAME.equals(typeDeclaration.getName())) {
        print("final ");
    }
    print(typeDeclaration.getKind() + " ");
    printIdentifier(typeDeclaration.getName());
    printTypeParameters(typeDeclaration.getTypeParameters(), false);
    if ("interface".equals(typeDeclaration.getKind())) {
        if (typeDeclaration.getSuperTypes() != null && typeDeclaration.getSuperTypes().length > 0) {
            for (TypeReference r : typeDeclaration.getSuperTypes()) {
                TypeDeclaration t = (TypeDeclaration) lookupType(r, null);
                if ("interface".equals(t.getKind())) {
                    print(" extends ").print(typeDeclaration.getSuperTypes()[0]);
                } else {
                    context.reportError("wrong subclassing link between " + typeDeclaration.getName() + " and "
                            + t.getName(), typeDeclaration.getToken());
                }
            }
        }
    } else if ("class".equals(typeDeclaration.getKind())) {
        List<TypeReference> extendList = new ArrayList<TypeReference>();
        List<TypeReference> implementList = new ArrayList<TypeReference>();
        if (typeDeclaration.getSuperTypes() != null && typeDeclaration.getSuperTypes().length > 0) {
            for (TypeReference r : typeDeclaration.getSuperTypes()) {
                TypeDeclaration t = (TypeDeclaration) lookupType(r, null);
                if (t != null) {
                    if ("interface".equals(t.getKind())) {
                        implementList.add(r);
                    } else {
                        extendList.add(r);
                    }
                } else {
                    logger.warn("unresolved inheritance reference: " + r);
                }
            }
        }

        if (extendList.size() > 1) {

            context.reportError("multiple inheritance should not appear at this stage for "
                    + typeDeclaration.getName() + " extends=" + extendList, typeDeclaration.getToken());
        } else if (extendList.size() == 1) {
            print(" extends ").print(extendList.get(0));
        } else if (!JSweetDefTranslatorConfig.isJDKReplacementMode()
                && !((JSweetDefTranslatorConfig.getObjectClassName())
                        .equals(currentModuleName + "." + typeDeclaration.getName()))
                && !typeDeclaration.getName().equals(JSweetDefTranslatorConfig.GLOBALS_CLASS_NAME)) {
            print(" extends ").print(JSweetDefTranslatorConfig.getObjectClassName());
        }
        if (!implementList.isEmpty()) {
            print(" implements ");
            for (TypeReference r : implementList) {
                print(r);
                print(", ");
            }
            removeLastChars(2);
        }
    }

    print(" {");
    println().startIndent();
    scan(typeDeclaration.getMembers());
    endIndent();
    printIndent().print("}").println();
    if (!innerType) {
        String typeName = currentModuleName + "." + typeDeclaration.getName();
        File outputFile = new File(outputDir, typeName.replace('.', '/') + ".java");
        writeToFile(outputFile, getResult());
    }
}

From source file:org.iish.visualmets.services.TocDaoImp.java

public ArrayList<String> uniqueArrayList(ArrayList<String> arrl) {
    int i;/*from   w  w w .j a  v a2  s . co m*/

    for (int k = 0; k < arrl.size(); k++) {
        Object s = arrl.get(k);
        i = Collections.frequency(arrl, s);

        for (int j = 1; j < i; j++) {
            arrl.remove(s);
        }
    }

    return arrl;
}

From source file:org.wso2.carbon.ml.dataset.internal.DatasetSummary.java

/**
 * Calculate the frequencies of each category in String columns, needed to
 * plot bar graphs/histograms./*w w  w. java 2s  . com*/
 * Calculate unique value counts.
 *
 * @param noOfIntervals     Number of intervals to be calculated.
 */
private void calculateStringColumnFrequencies(int noOfIntervals) {

    Iterator<Integer> stringColumns = this.stringDataColumnPositions.iterator();
    int currentCol;
    // Iterate through all Columns with String data.
    while (stringColumns.hasNext()) {
        currentCol = stringColumns.next();
        SortedMap<String, Integer> frequencies = new TreeMap<String, Integer>();
        // Create a unique set from the column.
        Set<String> uniqueSet = new HashSet<String>(this.columnData.get(currentCol));
        // Count the frequencies in each unique value.
        this.unique[currentCol] = uniqueSet.size();
        for (String uniqueValue : uniqueSet) {
            frequencies.put(uniqueValue.toString(),
                    Collections.frequency(this.columnData.get(currentCol), uniqueValue));
        }
        graphFrequencies.set(currentCol, frequencies);
    }
}

From source file:net.yoching.android.MainActivity.java

public void flipCoins(View view) {

    final List<Integer> outcomes = new ArrayList<Integer>(3);
    for (int i = 0; i < 3; i++) {
        int j = Math.random() > .5 ? 1 : 2;
        outcomes.add(new Integer(j));
        animatedCoins[i].setHeadsOrTails(j);
    }// ww w.j  av a 2 s  .  c om

    int heads = Collections.frequency(outcomes, new Integer(1));

    Bitmap lineRender = null;
    if (heads >= 2) {
        lineRender = strongLine;
        outcomeBuffer.append("1");
    } else {
        lineRender = splitLine;
        outcomeBuffer.append("2");
    }
    Log.d(TAG, "wrexagram outcome buffer  : " + outcomeBuffer.toString());

    if (!imageViewStack.isEmpty()) {

        List<Long> list = new ArrayList<Long>();
        for (int i = 2; i < 6; i++) {
            list.add(new Long(i * 100)); // list contains: [2,3,4,5]
        }
        Collections.shuffle(list);

        handler.postDelayed(animatedCoins[0], list.get(0));
        handler.postDelayed(animatedCoins[1], list.get(1));
        handler.postDelayed(animatedCoins[2], list.get(2));

        final ImageView wrexaLine = imageViewStack.pop();
        wrexaLine.setImageBitmap(lineRender);
        wrexaLine.setVisibility(View.INVISIBLE);
        wrexaLine.postDelayed(new Runnable() {
            @Override
            public void run() {
                wrexaLine.setVisibility(View.VISIBLE);
            }
        }, 2300);

    }
    Intent intent = new Intent(MainActivity.this, ViewWrexagramActivity.class);
    TossListener tossListener = new TossListener(intent, outcomeBuffer);
    handler.postDelayed(tossListener, 2000);
}

From source file:com.github.drbookings.ui.controller.StatsViewController.java

private void updateUI(final BookingsByOrigin<BookingEntry> bookings, final Range<LocalDate> dateRange) {
    if (logger.isDebugEnabled()) {
        logger.debug("Statistics for\n" + BookingEntries.toBookings(bookings.getAllBookings()).stream()
                .map(i -> i.toString()).collect(Collectors.joining("\n")));
    }//  w w  w .  j  a va2 s .co m
    final float allAllNigths = BookingEntries.countNights(bookings, false);
    final NavigableSet<LocalDate> allDates = bookings.getAllBookings(true).stream().map(b -> b.getDate())
            .collect(Collectors.toCollection(TreeSet::new));
    long monthCount = TemporalQueries.countOccurrences(allDates,
            SettingsManager.getInstance().getFixCostsPaymentDay());
    if (logger.isDebugEnabled()) {
        logger.debug("Month count: " + monthCount);
    }
    if (monthCount < 1) {
        monthCount = 1;
        if (logger.isDebugEnabled()) {
            logger.debug("Month count (corrected): " + monthCount);
        }
    }
    final float additionalCosts = SettingsManager.getInstance().getAdditionalCosts() * monthCount;
    final float numberOfRooms = SettingsManager.getInstance().getNumberOfRooms();
    final float totalAdditionalCosts = additionalCosts * numberOfRooms;
    if (logger.isDebugEnabled()) {
        logger.debug("Fix costs total: " + totalAdditionalCosts);
    }
    for (final Entry<BookingOrigin, Collection<BookingEntry>> e : bookings.getMap().entrySet()) {

        final Collection<? extends BookingEntry> bookingsFilteredByPaymentDate = e.getValue().stream()
                .filter(new PaymentDateFilter(dateRange)).collect(Collectors.toList());

        final Collection<? extends BookingEntry> bookingsFilteredByCleaningDate = e.getValue().stream()
                .filter(new CleaningDateFilter(dateRange)).collect(Collectors.toList());

        final int numberOfAllBookings = (int) BookingEntries.countBookings(new BookingsByOrigin<>(e.getValue()),
                false);

        final int numberOfPayedBookings = (int) BookingEntries
                .countBookings(new BookingsByOrigin<>(e.getValue()), false);

        final int numberOfAllNights = (int) BookingEntries.countNights(new BookingsByOrigin<>(e.getValue()),
                false);

        final int numberOfPayedNights = (int) BookingEntries
                .countNights(new BookingsByOrigin<>(bookingsFilteredByPaymentDate), false);

        final float percentage;

        if (StringUtils.isBlank(e.getKey().getName())) {
            percentage = 0;
        } else {
            percentage = numberOfAllNights / allAllNigths * 100f;
        }
        if (logger.isDebugEnabled()) {
            logger.debug(e.getKey() + " percentage of all nights: " + percentage);
        }
        final double relativeFixCosts = totalAdditionalCosts * percentage / 100;
        if (logger.isDebugEnabled()) {
            logger.debug(e.getKey() + " relative fix costs " + relativeFixCosts);
        }
        if (logger.isDebugEnabled()) {
            logger.debug(e.getKey() + " number of bookings (all/payed): " + numberOfAllBookings + "/"
                    + numberOfPayedBookings);
        }
        if (logger.isDebugEnabled()) {
            logger.debug(e.getKey() + ": Number of nights (all/payed): " + numberOfAllNights + "/"
                    + numberOfPayedNights);
        }

        if (logger.isDebugEnabled()) {
            Set<Guest> set = e.getValue().stream().map(b -> b.getElement().getGuest())
                    .collect(Collectors.toCollection(LinkedHashSet::new));
            List<Guest> list = e.getValue().stream().filter(b -> !b.isCheckOut())
                    .map(b -> b.getElement().getGuest()).collect(Collectors.toCollection(ArrayList::new));
            StringBuilder sb = new StringBuilder(e.getKey() + " guest and nights (all):");
            int cnt = 1;
            int cnt2 = 0;
            for (final Guest guest : set) {
                final int cnt3 = Collections.frequency(list, guest);

                sb.append(String.format("%n%4d%20s%4d", cnt++, guest.getName(), cnt3));
                cnt2 += cnt3;
            }
            sb.append(String.format("%n%24s%4d", "Total", cnt2));

            logger.debug(sb.toString());

            set = bookingsFilteredByPaymentDate.stream().map(b -> b.getElement().getGuest())
                    .collect(Collectors.toCollection(LinkedHashSet::new));
            list = bookingsFilteredByPaymentDate.stream().filter(b -> !b.isCheckOut())
                    .map(b -> b.getElement().getGuest()).collect(Collectors.toCollection(ArrayList::new));
            sb = new StringBuilder(e.getKey() + " guest and nights (payed):");
            cnt = 1;
            cnt2 = 0;
            for (final Guest guest : set) {
                final int cnt3 = Collections.frequency(list, guest);

                sb.append(String.format("%n%4d%20s%4d", cnt++, guest.getName(), cnt3));
                cnt2 += cnt3;
            }
            sb.append(String.format("%n%24s%4d", "Total", cnt2));

            logger.debug(sb.toString());

        }

        final StatisticsTableBean b = StatisticsTableBean.build(e.getKey().getName(),
                bookingsFilteredByPaymentDate);
        StatisticsTableBean.applyCleaningStuff(b, bookingsFilteredByCleaningDate);
        b.setFixCosts((float) relativeFixCosts);
        b.setNightsPercent(percentage);
        b.setNumberOfPayedNights(numberOfPayedNights);
        b.setNumberOfAllNights(numberOfAllNights);
        b.setNumberOfPayedBookings(numberOfPayedBookings);
        b.setNumberOfAllBookings(numberOfAllBookings);
        data.add(b);
    }
    // add a total row

    final float relativeFixCosts = totalAdditionalCosts;
    final StatisticsTableBean b = StatisticsTableBean.buildSum(data);
    b.setFixCosts(relativeFixCosts);
    b.setNightsPercent(100);
    data.add(b);
}

From source file:org.apache.pig.backend.hadoop.executionengine.tez.plan.optimizer.UnionOptimizer.java

@Override
public void visitTezOp(TezOperator tezOp) throws VisitorException {
    if (!tezOp.isUnion()) {
        return;//from w  w w .  ja v a  2  s.co m
    }

    if (!isOptimizable(tezOp)) {
        return;
    }

    TezOperator unionOp = tezOp;
    String scope = unionOp.getOperatorKey().scope;
    PhysicalPlan unionOpPlan = unionOp.plan;

    Set<OperatorKey> uniqueUnionMembers = new HashSet<OperatorKey>(unionOp.getUnionMembers());
    List<TezOperator> predecessors = new ArrayList<TezOperator>(tezPlan.getPredecessors(unionOp));
    List<TezOperator> successors = tezPlan.getSuccessors(unionOp) == null ? null
            : new ArrayList<TezOperator>(tezPlan.getSuccessors(unionOp));

    if (uniqueUnionMembers.size() != 1) {

        if (!isOptimizableStoreFunc(tezOp, supportedStoreFuncs, unsupportedStoreFuncs)) {
            return;
        }

        if (successors != null) {
            for (TezOperator succ : successors) {
                for (TezOperator pred : predecessors) {
                    if (succ.inEdges.containsKey(pred.getOperatorKey())) {
                        // Stop here, we cannot convert the node into vertex group
                        // Otherwise, we will end up with a parallel edge between pred
                        // and succ
                        return;
                    }
                }
            }
        }

        // TODO: PIG-3856 Handle replicated join and skewed join sample.
        // Replicate join small table/skewed join sample that was broadcast to union vertex
        // now needs to be broadcast to all the union predecessors. How do we do that??
        // Wait for shared edge and do it or write multiple times??
        // For now don't optimize except in the case of Split where we need to write only once
        if (predecessors.size() > unionOp.getUnionMembers().size()) {
            return;
        }
    }

    if (uniqueUnionMembers.size() == 1) {
        // We actually don't need VertexGroup in this case. The multiple
        // sub-plans of Split can write to same MROutput or the Tez LogicalOutput
        OperatorKey splitPredKey = uniqueUnionMembers.iterator().next();
        TezOperator splitPredOp = tezPlan.getOperator(splitPredKey);
        PhysicalPlan splitPredPlan = splitPredOp.plan;
        if (splitPredPlan.getLeaves().get(0) instanceof POSplit) { //It has to be. But check anyways

            try {
                connectUnionNonMemberPredecessorsToSplit(unionOp, splitPredOp, predecessors);

                // Remove POShuffledValueInputTez from union plan root
                unionOpPlan.remove(unionOpPlan.getRoots().get(0));
                // Clone union plan into split subplans
                for (int i = 0; i < Collections.frequency(unionOp.getUnionMembers(), splitPredKey); i++) {
                    cloneAndMergeUnionPlan(unionOp, splitPredOp);
                }
                copyOperatorProperties(splitPredOp, unionOp);
                tezPlan.disconnect(splitPredOp, unionOp);

                connectSplitOpToUnionSuccessors(unionOp, splitPredOp, successors);
            } catch (PlanException e) {
                throw new VisitorException(e);
            }

            //Remove union operator from the plan
            tezPlan.remove(unionOp);
            return;
        } else {
            throw new VisitorException("Expected POSplit but found " + splitPredPlan.getLeaves().get(0));
        }
    }

    // Create vertex group operator for each store. Union followed by Split
    // followed by Store could have multiple stores
    List<POStoreTez> unionStoreOutputs = PlanHelper.getPhysicalOperators(unionOpPlan, POStoreTez.class);
    TezOperator[] storeVertexGroupOps = new TezOperator[unionStoreOutputs.size()];
    for (int i = 0; i < storeVertexGroupOps.length; i++) {
        TezOperator existingVertexGroup = null;
        if (successors != null) {
            for (TezOperator succ : successors) {
                if (succ.isVertexGroup()
                        && unionStoreOutputs.get(i).getSFile().equals(succ.getVertexGroupInfo().getSFile())) {
                    existingVertexGroup = succ;
                }
            }
        }
        if (existingVertexGroup != null) {
            storeVertexGroupOps[i] = existingVertexGroup;
            existingVertexGroup.getVertexGroupMembers().remove(unionOp.getOperatorKey());
            existingVertexGroup.getVertexGroupMembers().addAll(unionOp.getUnionMembers());
            existingVertexGroup.getVertexGroupInfo().removeInput(unionOp.getOperatorKey());
        } else {
            storeVertexGroupOps[i] = new TezOperator(OperatorKey.genOpKey(scope));
            storeVertexGroupOps[i].setVertexGroupInfo(new VertexGroupInfo(unionStoreOutputs.get(i)));
            storeVertexGroupOps[i].getVertexGroupInfo().setSFile(unionStoreOutputs.get(i).getSFile());
            storeVertexGroupOps[i].setVertexGroupMembers(new ArrayList<OperatorKey>(unionOp.getUnionMembers()));
            tezPlan.add(storeVertexGroupOps[i]);
        }
    }

    // Create vertex group operator for each output. Case of split, orderby,
    // skewed join, rank, etc will have multiple outputs
    List<TezOutput> unionOutputs = PlanHelper.getPhysicalOperators(unionOpPlan, TezOutput.class);
    // One TezOutput can write to multiple LogicalOutputs (POCounterTez, POValueOutputTez, etc)
    List<String> unionOutputKeys = new ArrayList<String>();
    for (TezOutput output : unionOutputs) {
        if (output instanceof POStoreTez) {
            continue;
        }
        for (String key : output.getTezOutputs()) {
            unionOutputKeys.add(key);
        }
    }
    TezOperator[] outputVertexGroupOps = new TezOperator[unionOutputKeys.size()];
    String[] newOutputKeys = new String[unionOutputKeys.size()];
    for (int i = 0; i < outputVertexGroupOps.length; i++) {
        outputVertexGroupOps[i] = new TezOperator(OperatorKey.genOpKey(scope));
        outputVertexGroupOps[i].setVertexGroupInfo(new VertexGroupInfo());
        outputVertexGroupOps[i].getVertexGroupInfo().setOutput(unionOutputKeys.get(i));
        outputVertexGroupOps[i].setVertexGroupMembers(new ArrayList<OperatorKey>(unionOp.getUnionMembers()));
        newOutputKeys[i] = outputVertexGroupOps[i].getOperatorKey().toString();
        tezPlan.add(outputVertexGroupOps[i]);
    }

    // Change plan from Predecessors -> Union -> Successor(s) to
    // Predecessors -> Vertex Group(s) -> Successor(s)
    try {
        // Remove POShuffledValueInputTez from union plan root
        unionOpPlan.remove(unionOpPlan.getRoots().get(0));

        for (OperatorKey predKey : unionOp.getUnionMembers()) {
            TezOperator pred = tezPlan.getOperator(predKey);
            PhysicalPlan clonePlan = cloneAndMergeUnionPlan(unionOp, pred);
            connectPredecessorsToVertexGroups(unionOp, pred, clonePlan, storeVertexGroupOps,
                    outputVertexGroupOps);
        }

        connectVertexGroupsToSuccessors(unionOp, successors, unionOutputKeys, outputVertexGroupOps);

        replaceSuccessorInputsAndDisconnect(unionOp, successors, unionOutputKeys, newOutputKeys);

        //Remove union operator from the plan
        tezPlan.remove(unionOp);
    } catch (VisitorException e) {
        throw e;
    } catch (Exception e) {
        throw new VisitorException(e);
    }

}

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

/**
 * Calculate the frequencies of each category in String columns, needed to plot bar graphs/histograms. Calculate
 * unique value counts.//from w w  w  .ja  v  a  2s. c om
 *
 */
protected List<SortedMap<?, Integer>> calculateStringColumnFrequencies() {

    Iterator<Integer> stringColumns = this.stringDataColumnPositions.iterator();
    int currentCol;
    // Iterate through all Columns with String data.
    while (stringColumns.hasNext()) {
        currentCol = stringColumns.next();
        SortedMap<String, Integer> frequencies = new TreeMap<String, Integer>();
        // Create a unique set from the column.
        Set<String> uniqueSet = new HashSet<String>(this.columnData.get(currentCol));
        // Count the frequencies in each unique value.
        this.unique[currentCol] = uniqueSet.size();
        for (String uniqueValue : uniqueSet) {
            if (uniqueValue != null) {
                frequencies.put(uniqueValue.toString(),
                        Collections.frequency(this.columnData.get(currentCol), uniqueValue));
            }
        }
        graphFrequencies.set(currentCol, frequencies);
    }

    return graphFrequencies;
}

From source file:org.wso2.carbon.ml.dataset.internal.DatasetSummary.java

/**
 * Calculate the frequencies of each category/interval of Numerical data columns.
 *
 * @param categoricalThreshold      Threshold for number of categories, to be considered as
 *                                  discrete data.
 * @param noOfIntervals             Number of intervals to be calculated for continuous data
 *//*  w  w w . jav a 2  s . co m*/
private void calculateNumericColumnFrequencies(int categoricalThreshold, int noOfIntervals) {
    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));
        // If the unique values are less than or equal to maximum-category-limit.
        this.unique[currentCol] = uniqueSet.size();
        if (this.unique[currentCol] <= categoricalThreshold) {
            // Change the data type to categorical.
            this.type[currentCol] = FeatureType.CATEGORICAL;
            // Calculate the category frequencies.
            SortedMap<Double, Integer> frequencies = new TreeMap<Double, Integer>();
            for (String uniqueValue : uniqueSet) {
                if (!uniqueValue.isEmpty()) {
                    frequencies.put(Double.parseDouble(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.
            claculateIntervalFreqs(currentCol, noOfIntervals);
        }
    }
}