Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  * Copyright (C) 2011 Tatsuhiro Tsujikawa
  * Permission is hereby granted, free of charge, to any person
  * obtaining a copy of this software and associated documentation
  * files (the "Software"), to deal in the Software without
  * restriction, including without limitation the rights to use, copy,
  * modify, merge, publish, distribute, sublicense, and/or sell copies
  * of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
package net.sourceforge.argparse4j.impl.action;

Argument action to store a list.

This action appends the value specified by net.sourceforge.argparse4j.inf.Argument.setConst(java.lang.Object) to the list. (Note that the const value defaults to null.) The list is of type java.util.List. This action is typically useful when multiple arguments need to store constants to the same list. If attrs contains non-List object for key net.sourceforge.argparse4j.inf.Argument.getDest(), it will be overwritten by the List containing value. consumeArgument() always returns false.

public class AppendConstArgumentAction implements ArgumentAction {
    public void run(ArgumentParser parserArgument arg,
            Map<StringObjectattrsString flagObject value)
            throws ArgumentParserException {
        if (attrs.containsKey(arg.getDest())) {
            Object obj = attrs.get(arg.getDest());
            if (obj instanceof List) {
                ((List<Object>) obj).add(arg.getConst());
        List<Objectlist = new ArrayList<Object>();
        attrs.put(arg.getDest(), list);
    public boolean consumeArgument() {
        return false;
    public void onAttach(Argument arg) {
New to GrepCode? Check out our FAQ X