001/* 
002 * JKNIV, SQLegance keeping queries maintainable.
003 * 
004 * Copyright (C) 2017, the original author or authors.
005 *
006 * This library is free software; you can redistribute it and/or
007 * modify it under the terms of the GNU Lesser General Public
008 * License as published by the Free Software Foundation; either
009 * version 2.1 of the License.
010 * 
011 * This library is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014 * Lesser General Public License for more details.
015 * 
016 * You should have received a copy of the GNU Lesser General Public
017 * License along with this library; if not, write to the Free Software Foundation, Inc., 
018 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
019 */
020package net.sf.jkniv.whinstone.classification;
021
022import java.util.ArrayList;
023import java.util.Collection;
024import java.util.HashSet;
025import java.util.List;
026import java.util.Set;
027
028public class NoGroupingBy<T, R> implements Groupable<T, R>
029{
030    private final List<T>    grouped;
031    
032    public NoGroupingBy()
033    {
034        this.grouped = new ArrayList<T>();
035    }
036    
037    
038    /* (non-Javadoc)
039     * @see net.sf.jkniv.sqlegance.classifier.Groupable#classifier(R)
040     */
041    @Override
042    @SuppressWarnings("unchecked")
043    public void classifier(R row)
044    {
045        this.grouped.add((T)row);
046    }
047    
048    /* (non-Javadoc)
049     * @see net.sf.jkniv.sqlegance.classifier.Groupable#asCollection()
050     */
051    @Override
052    public Collection<T> asCollection()
053    {
054        return grouped;
055    }
056    
057    /* (non-Javadoc)
058     * @see net.sf.jkniv.sqlegance.classifier.Groupable#asList()
059     */
060    @Override
061    public List<T> asList()
062    {
063        return grouped;
064    }
065    
066    /* (non-Javadoc)
067     * @see net.sf.jkniv.sqlegance.classifier.Groupable#asSet()
068     */
069    @Override
070    public Set<T> asSet()
071    {
072        return new HashSet<T>(grouped);
073    }
074    
075}