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

org.dishevelled.commandline.argument.FileSetArgument Maven / Gradle / Ivy

There is a newer version: 1.2
Show newest version
/*

    dsh-commandline  Command line parser based on typed arguments.
    Copyright (c) 2004-2014 held jointly by the individual authors.

    This library is free software; you can redistribute it and/or modify it
    under the terms of the GNU Lesser General Public License as published
    by the Free Software Foundation; either version 3 of the License, or (at
    your option) any later version.

    This library is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
    License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with this library;  if not, write to the Free Software Foundation,
    Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA.

    > http://www.fsf.org/licensing/licenses/lgpl.html
    > http://www.opensource.org/licenses/lgpl-license.php

*/
package org.dishevelled.commandline.argument;

import java.io.File;

import java.util.Set;
import java.util.HashSet;
import java.util.StringTokenizer;

import org.apache.commons.lang.StringUtils;

/**
 * A file set argument.
 *
 * @author  Michael Heuer
 */
public final class FileSetArgument
    extends AbstractArgument>
{

    /**
     * Create a new file set argument.
     *
     * @param shortName short argument name
     * @param longName long argument name
     * @param description argument description
     * @param required true if this argument is required
     */
    public FileSetArgument(final String shortName,
                           final String longName,
                           final String description,
                           final boolean required)
    {
        super(shortName, longName, description, required);
    }


    /** {@inheritDoc} */
    protected Set convert(final String s)
        throws Exception
    {
        Set set = new HashSet();
        StringTokenizer st = new StringTokenizer(s, ",");
        while (st.hasMoreTokens())
        {
            String token = StringUtils.stripToEmpty(st.nextToken());
            File f = new File(token);
            set.add(f);
        }
        return set;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy