/*
 *  * Copyright 2016 Skymind, Inc.
 *  *
 *  *    Licensed under the Apache License, Version 2.0 (the "License");
 *  *    you may not use this file except in compliance with the License.
 *  *    You may obtain a copy of the License at
 *  *
 *  *        http://www.apache.org/licenses/LICENSE-2.0
 *  *
 *  *    Unless required by applicable law or agreed to in writing, software
 *  *    distributed under the License is distributed on an "AS IS" BASIS,
 *  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  *    See the License for the specific language governing permissions and
 *  *    limitations under the License.
 */

package org.datavec.api.transform.analysis.columns;

import org.datavec.api.transform.ColumnType;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.Collection;
import java.util.Map;

/**
 * Analysis for categorical columns
 *
 * @author Alex Black
 */
@AllArgsConstructor
@Data
public class CategoricalAnalysis implements ColumnAnalysis {

    private final Map<String, Long> mapOfCounts;


    @Override
    public String toString() {
        return "CategoricalAnalysis(CategoryCounts=" + mapOfCounts + ")";
    }

    @Override
    public long getCountTotal() {
        Collection<Long> counts = mapOfCounts.values();
        long sum = 0;
        for (Long l : counts) sum += l;
        return sum;
    }

    @Override
    public ColumnType getColumnType() {
        return ColumnType.Categorical;
    }
}

@@ -831,40 +831,9 @@
 til.
-Collection;%0Aimport java.util.Map
+*
 ;%0A%0A/
@@ -1096,72 +1096,790 @@
     
-return %22CategoricalAnalysis(CategoryCounts=%22 + mapOfCounts + %22)%22
+//Returning the counts from highest to lowest here, which seems like a useful default%0A        List%3CString%3E keys = new ArrayList%3C%3E(mapOfCounts.keySet());%0A        Collections.sort(keys, new Comparator%3CString%3E()%7B%0A            @Override%0A            public int compare(String o1, String o2) %7B%0A                return -Long.compare(mapOfCounts.get(o1), mapOfCounts.get(o2));     //Highest to lowest%0A            %7D%0A        %7D);%0A%0A        StringBuilder sb = new StringBuilder();%0A        sb.append(%22CategoricalAnalysis(CategoryCounts=%7B%22);%0A        boolean first = true;%0A        for(String s : keys)%7B%0A            if(!first) sb.append(%22, %22);%0A            first = false;%0A%0A            sb.append(s).append(%22=%22).append(mapOfCounts.get(s));%0A        %7D%0A        sb.append(%22%7D)%22);%0A%0A        return sb.toString()
 ;%0A  

Switch CategoricalAnalysis toString print order: highest to lowest counts