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