001package com.hfg.setting;
002
003import com.hfg.xml.XMLTag;
004
005import java.util.ArrayList;
006import java.util.List;
007
008//------------------------------------------------------------------------------
009/**
010 * An XML-serializable Integer list setting.
011 *
012 * @author J. Alex Taylor, hairyfatguy.com
013 */
014//------------------------------------------------------------------------------
015// com.hfg XML/HTML Coding Library
016//
017// This library is free software; you can redistribute it and/or
018// modify it under the terms of the GNU Lesser General Public
019// License as published by the Free Software Foundation; either
020// version 2.1 of the License, or (at your option) any later version.
021//
022// This library is distributed in the hope that it will be useful,
023// but WITHOUT ANY WARRANTY; without even the implied warranty of
024// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
025// Lesser General Public License for more details.
026//
027// You should have received a copy of the GNU Lesser General Public
028// License along with this library; if not, write to the Free Software
029// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
030//
031// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
032// jataylor@hairyfatguy.com
033//------------------------------------------------------------------------------
034
035public class IntListSetting extends ListSettingImpl implements Setting<List<Integer>>
036{
037   //###########################################################################
038   // CONSTRUCTORS
039   //###########################################################################
040
041   //---------------------------------------------------------------------------
042   public IntListSetting(String inName)
043   {
044      super(inName);
045   }
046
047   //---------------------------------------------------------------------------
048   public IntListSetting(String inName, List<Integer> inValue)
049   {
050      super(inName, inValue);
051   }
052
053   //---------------------------------------------------------------------------
054   /**
055    * Copy constructor.
056    * @param inObj2 the IntListSetting to clone
057    */
058   public IntListSetting(IntListSetting inObj2)
059   {
060      this(inObj2.name(), inObj2.getValue() == null ? null : new ArrayList<>(inObj2.getValue()));
061   }
062
063   //---------------------------------------------------------------------------
064   public IntListSetting(XMLTag inXMLTag)
065   {
066      super(inXMLTag);
067   }
068
069   //###########################################################################
070   // PUBLIC METHODS
071   //###########################################################################
072
073   //---------------------------------------------------------------------------
074   public IntListSetting setValue(List<Integer> inValue)
075   {
076      super.setObjectValue(inValue);
077      return this;
078   }
079
080   //---------------------------------------------------------------------------
081   public IntListSetting addValue(Integer inValue)
082   {
083      List<Integer> list = (List<Integer>) getObjectValue();
084      if (null == list)
085      {
086         list = new ArrayList<>(25);
087         setObjectValue(list);
088      }
089
090      list.add(inValue);
091
092      return this;
093   }
094
095   //---------------------------------------------------------------------------
096   @Override
097   public List<Integer> getValue()
098   {
099      return (List<Integer>) super.getObjectValue();
100   }
101
102   //---------------------------------------------------------------------------
103   @Override
104   public IntListSetting clone()
105   {
106      return new IntListSetting(this);
107   }
108
109   //###########################################################################
110   // PROTECTED METHODS
111   //###########################################################################
112
113   //---------------------------------------------------------------------------
114   @Override
115   protected void addValueFromString(String inValue)
116   {
117      List<Integer> list = (List<Integer>) getObjectValue();
118      if (null == list)
119      {
120         list = new ArrayList<>(25);
121         setObjectValue(list);
122      }
123
124      list.add(Integer.parseInt(inValue));
125   }
126
127}