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

com.inamik.text.tables.cell.base.Function Maven / Gradle / Ivy

The newest version!
/*
 * iNamik Text Tables for Java
 * 
 * Copyright (C) 2016 David Farrell ([email protected])
 *
 * Licensed under The MIT License (MIT), see LICENSE.txt
 */
package com.inamik.text.tables.cell.base;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

public abstract class Function
{
    public abstract Collection apply(Collection cell);

    public static final Function IDENTITY = new Function() {
        @Override
        public Collection apply(Collection cell) {
            return cell;
        }
    };

    /*
     * From line.Function
     */
    public static Function from(final com.inamik.text.tables.line.base.Function f) {
        return new Function() {
            @Override
            public Collection apply(Collection cell) {
                // map(cell, f)
                //
                final List r = new ArrayList(cell.size());
                for (String line: cell) { r.add(f.apply(line)); }
                return Collections.unmodifiableCollection(r);
            }
        };
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy