001/*
002 * Copyright (c) 2006-2011 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the Eclipse Public License v1.0
006 * which accompanies this distribution, and is available at
007 * http://www.eclipse.org/legal/epl-v10.html
008 *
009 * Contributors:
010 *     bstefanescu
011 */
012package org.nuxeo.ecm.automation.client.model;
013
014import java.io.Serializable;
015import java.util.ArrayList;
016import java.util.Date;
017import java.util.List;
018
019/**
020 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
021 */
022public class PropertyList implements Serializable {
023
024    private static final long serialVersionUID = -3058252973413747313L;
025
026    protected final List<Object> list;
027
028    public PropertyList() {
029        list = new ArrayList<Object>();
030    }
031
032    public PropertyList(int size) {
033        list = new ArrayList<Object>(size);
034    }
035
036    public PropertyList(List<Object> list) {
037        this.list = new ArrayList<Object>(list);
038    }
039
040    public int size() {
041        return list.size();
042    }
043
044    public boolean isEmpty() {
045        return list.isEmpty();
046    }
047
048    public String getString(int i) {
049        return getString(i, null);
050    }
051
052    public Boolean getBoolean(int i) {
053        return getBoolean(i, null);
054    }
055
056    public Long getLong(int i) {
057        return getLong(i, null);
058    }
059
060    public Double getDouble(int i) {
061        return getDouble(i, null);
062    }
063
064    public Date getDate(int i) {
065        return getDate(i, null);
066    }
067
068    public PropertyList getList(int i) {
069        return getList(i, null);
070    }
071
072    public PropertyMap getMap(int i) {
073        return getMap(i, null);
074    }
075
076    public String getString(int i, String defValue) {
077        return PropertiesHelper.getString(list.get(i), defValue);
078    }
079
080    public Boolean getBoolean(int i, Boolean defValue) {
081        return PropertiesHelper.getBoolean(list.get(i), defValue);
082    }
083
084    public Long getLong(int i, Long defValue) {
085        return PropertiesHelper.getLong(list.get(i), defValue);
086    }
087
088    public Double getDouble(int i, Double defValue) {
089        return PropertiesHelper.getDouble(list.get(i), defValue);
090    }
091
092    public Date getDate(int i, Date defValue) {
093        return PropertiesHelper.getDate(list.get(i), defValue);
094    }
095
096    public PropertyList getList(int i, PropertyList defValue) {
097        return PropertiesHelper.getList(list.get(i), defValue);
098    }
099
100    public PropertyMap getMap(int i, PropertyMap defValue) {
101        return PropertiesHelper.getMap(list.get(i), defValue);
102    }
103
104    public void set(int i, String value) {
105        if (value == null) {
106            list.remove(i);
107        }
108        list.set(i, value);
109    }
110
111    public void set(int i, Boolean value) {
112        if (value == null) {
113            list.remove(i);
114        }
115        list.set(i, value.toString());
116    }
117
118    public void set(int i, Long value) {
119        if (value == null) {
120            list.remove(i);
121        }
122        list.set(i, value.toString());
123    }
124
125    public void set(int i, Double value) {
126        if (value == null) {
127            list.remove(i);
128        }
129        list.set(i, value.toString());
130    }
131
132    public void set(int i, Date value) {
133        if (value == null) {
134            list.remove(i);
135        }
136        list.set(i, DateUtils.formatDate(value));
137    }
138
139    public void set(int i, PropertyList value) {
140        if (value == null) {
141            list.remove(i);
142        }
143        list.set(i, value);
144    }
145
146    public void set(int i, PropertyMap value) {
147        if (value == null) {
148            list.remove(i);
149        }
150        list.set(i, value);
151    }
152
153    public void add(String value) {
154        list.add(value);
155    }
156
157    public void add(Boolean value) {
158        list.add(value.toString());
159    }
160
161    public void add(Long value) {
162        list.add(value.toString());
163    }
164
165    public void add(Double value) {
166        list.add(value.toString());
167    }
168
169    public void add(Date value) {
170        list.add(DateUtils.formatDate(value));
171    }
172
173    public void add(PropertyList value) {
174        list.add(value);
175    }
176
177    public void add(PropertyMap value) {
178        list.add(value);
179    }
180
181    public List<Object> list() {
182        return list;
183    }
184
185    @Override
186    public String toString() {
187        return list.toString();
188    }
189}