All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.marvinlabs.widget.floatinglabel.itempicker.ItemPrinter Maven / Gradle / Ivy

The newest version!
package com.marvinlabs.widget.floatinglabel.itempicker;

import java.util.Collection;

/**
 * Created by Vincent Mimoun-Prat @ MarvinLabs, 29/08/2014.
 */
public interface ItemPrinter {

    public String print(ItemT item);

    public String printCollection(Collection items);


    public static class ToStringItemPrinter implements ItemPrinter {

        public String print(ItemT item) {
            return item==null ? "" : item.toString();
        }

        public String printCollection(Collection items) {
            if (items.size() == 0) return "";

            StringBuilder sb = new StringBuilder();
            boolean prependSeparator = false;
            for (ItemT item : items) {
                if (prependSeparator) {
                    sb.append(", ");
                } else {
                    prependSeparator = true;
                }

                sb.append(print(item));
            }

            return sb.toString();
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy