001package co.codewizards.cloudstore.core.dto;
002
003import java.util.ArrayList;
004import java.util.Collection;
005import java.util.List;
006import java.util.StringTokenizer;
007
008import javax.xml.bind.annotation.XmlElement;
009import javax.xml.bind.annotation.XmlRootElement;
010
011import co.codewizards.cloudstore.core.Uid;
012
013@XmlRootElement
014public class UidList extends ArrayList<Uid> {
015        private static final long serialVersionUID = 1L;
016
017        public UidList() {
018        }
019
020        public UidList(int initialCapacity) {
021                super(initialCapacity);
022        }
023
024        public UidList(Collection<? extends Uid> c) {
025                super(c);
026        }
027
028        public UidList(final String pgpKeyIdsString) {
029                if (pgpKeyIdsString == null)
030                        return;
031
032                final StringTokenizer st = new StringTokenizer(pgpKeyIdsString, ", \t", false);
033                while (st.hasMoreTokens()) {
034                        final String token = st.nextToken();
035                        if (!token.isEmpty())
036                                this.add(new Uid(token));
037                }
038        }
039
040        @Override
041        public String toString() {
042                final StringBuilder sb = new StringBuilder();
043                for (final Uid uid : this) {
044                        if (sb.length() > 0)
045                                sb.append(',');
046
047                        sb.append(uid);
048                }
049                return sb.toString();
050        }
051
052        /**
053         * Gets the elements of this list.
054         * @return {@code this}
055         * @deprecated This method should not be invoked by manually written code! It is exclusively used by JAXB.
056         */
057        @Deprecated
058        @XmlElement(name="uid")
059        public List<Uid> getElements() {
060                return this;
061        }
062}