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:bs@nuxeo.com">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 } 122 list.set(i, value.toString()); 123 } 124 125 public void set(int i, Long value) { 126 if (value == null) { 127 list.remove(i); 128 } 129 list.set(i, value.toString()); 130 } 131 132 public void set(int i, Double value) { 133 if (value == null) { 134 list.remove(i); 135 } 136 list.set(i, value.toString()); 137 } 138 139 public void set(int i, Date value) { 140 if (value == null) { 141 list.remove(i); 142 } 143 list.set(i, DateUtils.formatDate(value)); 144 } 145 146 public void set(int i, PropertyList value) { 147 if (value == null) { 148 list.remove(i); 149 } 150 list.set(i, value); 151 } 152 153 public void set(int i, PropertyMap value) { 154 if (value == null) { 155 list.remove(i); 156 } 157 list.set(i, value); 158 } 159 160 public void add(String value) { 161 list.add(value); 162 } 163 164 public void add(Boolean value) { 165 list.add(value.toString()); 166 } 167 168 public void add(Long value) { 169 list.add(value.toString()); 170 } 171 172 public void add(Double value) { 173 list.add(value.toString()); 174 } 175 176 public void add(Date value) { 177 list.add(DateUtils.formatDate(value)); 178 } 179 180 public void add(PropertyList value) { 181 list.add(value); 182 } 183 184 public void add(PropertyMap value) { 185 list.add(value); 186 } 187 188 public List<Object> list() { 189 return list; 190 } 191 192 @Override 193 public String toString() { 194 return list.toString(); 195 } 196}