001package conexp.fx.core.xml;
002
003/*
004 * #%L
005 * Concept Explorer FX
006 * %%
007 * Copyright (C) 2010 - 2023 Francesco Kriegel
008 * %%
009 * This program is free software: you can redistribute it and/or modify
010 * it under the terms of the GNU General Public License as
011 * published by the Free Software Foundation, either version 3 of the
012 * License, or (at your option) any later version.
013 * 
014 * This program is distributed in the hope that it will be useful,
015 * but WITHOUT ANY WARRANTY; without even the implied warranty of
016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
017 * GNU General Public License for more details.
018 * 
019 * You should have received a copy of the GNU General Public
020 * License along with this program.  If not, see
021 * <http://www.gnu.org/licenses/gpl-3.0.html>.
022 * #L%
023 */
024
025
026import java.util.ArrayList;
027import java.util.Collection;
028import java.util.Collections;
029import java.util.Iterator;
030import java.util.LinkedList;
031import java.util.List;
032import java.util.ListIterator;
033import java.util.Map;
034
035import org.jsoup.nodes.Element;
036
037
038public class CompoundListData extends ListData<Map<String, Data<?>>> {
039
040  public CompoundListData(final String key, final String subkey) {
041    super(Datatype.COMPOUND_LIST, key, subkey, Collections.synchronizedList(new ArrayList<Map<String, Data<?>>>()));
042  }
043
044  public CompoundListData(final String key, final String subkey, final List<Map<String, Data<?>>> value) {
045    super(Datatype.COMPOUND_LIST, key, subkey, Collections.synchronizedList(new ArrayList<Map<String, Data<?>>>(value)));
046  }
047
048  public CompoundListData(final String key, final String subkey, final Element element, final Metadata metadata)
049      throws NullPointerException, IndexOutOfBoundsException {
050    super(Datatype.COMPOUND_LIST, key, subkey, readListDataFromElement(element, subkey, metadata));
051  }
052
053  private synchronized static final List<Map<String, Data<?>>> readListDataFromElement(
054      final Element element,
055      final String subkey,
056      final Metadata metadata) {
057    final List<Map<String, Data<?>>> list = new LinkedList<Map<String, Data<?>>>();
058    for (final Element subElement : JsoupUtil.childrenByTag(element, subkey))
059      list.add(AbstractCompoundData.readDataFromElement(subElement, metadata));
060    return Collections.synchronizedList(list);
061  }
062
063  @Override
064  public final boolean add(Map<String,Data<?>> value) {
065    return this.value.add(value);
066  }
067
068  @Override
069  public final void add(int index, Map<String,Data<?>> value) {
070    this.value.add(index, value);
071  }
072
073  @Override
074  public final Map<String,Data<?>> set(int index, Map<String,Data<?>> value) {
075    return this.value.set(index, value);
076  }
077
078  @Override
079  public final Map<String,Data<?>> get(int index) {
080    return value.get(index);
081  }
082
083  @Override
084  public final Map<String,Data<?>> remove(int index) {
085    return value.remove(index);
086  }
087
088  @Override
089  public final boolean remove(Object object) {
090    return value.remove(object);
091  }
092
093  @Override
094  public final boolean contains(Object object) {
095    return this.value.contains(object);
096  }
097
098  @Override
099  public final int indexOf(Object object) {
100    return this.value.indexOf(object);
101  }
102
103  @Override
104  public final int lastIndexOf(Object object) {
105    return value.lastIndexOf(object);
106  }
107
108  @Override
109  public final boolean addAll(Collection<? extends Map<String,Data<?>>> collection) {
110    return value.addAll(collection);
111  }
112
113  @Override
114  public final boolean addAll(int index, Collection<? extends Map<String,Data<?>>> collection) {
115    return value.addAll(index, collection);
116  }
117
118  @Override
119  public final boolean removeAll(Collection<?> collection) {
120    return value.removeAll(collection);
121  }
122
123  @Override
124  public final boolean retainAll(Collection<?> collection) {
125    return value.retainAll(collection);
126  }
127
128  @Override
129  public final boolean containsAll(Collection<?> collection) {
130    return value.containsAll(collection);
131  }
132
133  @Override
134  public final void clear() {
135    value.clear();
136  }
137
138  @Override
139  public final boolean isEmpty() {
140    return value.isEmpty();
141  }
142
143  @Override
144  public final int size() {
145    return value.size();
146  }
147
148  @Override
149  public final Iterator<Map<String,Data<?>>> iterator() {
150    return value.iterator();
151  }
152
153  @Override
154  public final ListIterator<Map<String,Data<?>>> listIterator() {
155    return value.listIterator();
156  }
157
158  @Override
159  public final ListIterator<Map<String,Data<?>>> listIterator(int index) {
160    return value.listIterator(index);
161  }
162
163  @Override
164  public final List<Map<String, Data<?>>> subList(int fromIndex, int toIndex) {
165    return value.subList(fromIndex, toIndex);
166  }
167
168  @Override
169  public final Object[] toArray() {
170    return value.toArray();
171  }
172
173  @Override
174  public final <T> T[] toArray(T[] array) {
175    return value.<T> toArray(array);
176  }
177
178}