001/* 002 * (C) Copyright 2006-2011 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * bstefanescu 018 */ 019package org.nuxeo.ecm.automation.client.model; 020 021import java.io.Serializable; 022import java.util.ArrayList; 023import java.util.Date; 024import java.util.List; 025 026/** 027 * @author <a href="mailto:[email protected]">Bogdan Stefanescu</a> 028 */ 029public class PropertyList implements Serializable { 030 031 private static final long serialVersionUID = -3058252973413747313L; 032 033 protected final List<Object> list; 034 035 public PropertyList() { 036 list = new ArrayList<Object>(); 037 } 038 039 public PropertyList(int size) { 040 list = new ArrayList<Object>(size); 041 } 042 043 public PropertyList(List<Object> list) { 044 this.list = new ArrayList<Object>(list); 045 } 046 047 public int size() { 048 return list.size(); 049 } 050 051 public boolean isEmpty() { 052 return list.isEmpty(); 053 } 054 055 public String getString(int i) { 056 return getString(i, null); 057 } 058 059 public Boolean getBoolean(int i) { 060 return getBoolean(i, null); 061 } 062 063 public Long getLong(int i) { 064 return getLong(i, null); 065 } 066 067 public Double getDouble(int i) { 068 return getDouble(i, null); 069 } 070 071 public Date getDate(int i) { 072 return getDate(i, null); 073 } 074 075 public PropertyList getList(int i) { 076 return getList(i, null); 077 } 078 079 public PropertyMap getMap(int i) { 080 return getMap(i, null); 081 } 082 083 public String getString(int i, String defValue) { 084 return PropertiesHelper.getString(list.get(i), defValue); 085 } 086 087 public Boolean getBoolean(int i, Boolean defValue) { 088 return PropertiesHelper.getBoolean(list.get(i), defValue); 089 } 090 091 public Long getLong(int i, Long defValue) { 092 return PropertiesHelper.getLong(list.get(i), defValue); 093 } 094 095 public Double getDouble(int i, Double defValue) { 096 return PropertiesHelper.getDouble(list.get(i), defValue); 097 } 098 099 public Date getDate(int i, Date defValue) { 100 return PropertiesHelper.getDate(list.get(i), defValue); 101 } 102 103 public PropertyList getList(int i, PropertyList defValue) { 104 return PropertiesHelper.getList(list.get(i), defValue); 105 } 106 107 public PropertyMap getMap(int i, PropertyMap defValue) { 108 return PropertiesHelper.getMap(list.get(i), defValue); 109 } 110 111 public void set(int i, String value) { 112 if (value == null) { 113 list.remove(i); 114 } 115 list.set(i, value); 116 } 117 118 public void set(int i, Boolean value) { 119 if (value == null) { 120 list.remove(i); 121 } else { 122 list.set(i, value.toString()); 123 } 124 } 125 126 public void set(int i, Long value) { 127 if (value == null) { 128 list.remove(i); 129 } else { 130 list.set(i, value.toString()); 131 } 132 } 133 134 public void set(int i, Double value) { 135 if (value == null) { 136 list.remove(i); 137 } else { 138 list.set(i, value.toString()); 139 } 140 } 141 142 public void set(int i, Date value) { 143 if (value == null) { 144 list.remove(i); 145 } 146 list.set(i, DateUtils.formatDate(value)); 147 } 148 149 public void set(int i, PropertyList value) { 150 if (value == null) { 151 list.remove(i); 152 } 153 list.set(i, value); 154 } 155 156 public void set(int i, PropertyMap value) { 157 if (value == null) { 158 list.remove(i); 159 } 160 list.set(i, value); 161 } 162 163 public void add(String value) { 164 list.add(value); 165 } 166 167 public void add(Boolean value) { 168 list.add(value.toString()); 169 } 170 171 public void add(Long value) { 172 list.add(value.toString()); 173 } 174 175 public void add(Double value) { 176 list.add(value.toString()); 177 } 178 179 public void add(Date value) { 180 list.add(DateUtils.formatDate(value)); 181 } 182 183 public void add(PropertyList value) { 184 list.add(value); 185 } 186 187 public void add(PropertyMap value) { 188 list.add(value); 189 } 190 191 public List<Object> list() { 192 return list; 193 } 194 195 @Override 196 public String toString() { 197 return list.toString(); 198 } 199}