Java List Create createTarget(List labels)

Here you can find the source of createTarget(List labels)

Description

create Target

License

Open Source License

Declaration

public static <T> List<Double> createTarget(List<T> labels) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Main {
    public static <T> List<Double> createTarget(List<T> labels) {
        return createTarget(labels, new HashMap<T, Double>());
    }// ww  w  .j a va2  s  .  com

    public static <T> List<Double> createTarget(List<T> labels, Map<T, Double> labelMap) {
        List<Double> target = new ArrayList<Double>();
        double t = 0;

        for (T label : labels) {
            if (!labelMap.containsKey(label)) {
                t += 1;
                labelMap.put(label, t);
            }
            target.add((double) labelMap.get(label));
        }
        return target;
    }
}

Related

  1. createSubList(Collection source, Class type)
  2. createSublist(final T[] elements, final Class listImplementation)
  3. createSymbolNameString_From_Parts(List descTagName_Parts)
  4. createTable(List datas, String[] headers, int numColumns, int cellPadding, int border)
  5. createTagList(List tags, String separator)
  6. createTargetSorted(List labels, Comparator comp)
  7. createTuple(List> tuples, List entries, List> lists)
  8. createUniqueProducts(List list1, List list2)
  9. createUnmodifiableList(Collection coll)