001/*
002 * To change this template, choose Tools | Templates
003 * and open the template in the editor.
004 */
005package org.anarres.qemu.exec.util;
006
007import java.util.ArrayList;
008import java.util.Arrays;
009import java.util.Collection;
010import java.util.List;
011import org.anarres.qemu.exec.QEmuCommandLine;
012import org.anarres.qemu.exec.QEmuOption;
013
014/**
015 * A list of {@link QEmuOption QEmuOptions}, represented as a QEmuOption.
016 *
017 * This makes a {@link QEmuCommandLine} be a tree of QEmuOptions.
018 *
019 * @author shevek
020 */
021public class QEmuOptionsList extends ArrayList<QEmuOption> implements QEmuOption, QEmuOption.Container, QEmuIdAllocator.Consumer {
022
023    public QEmuOptionsList() {
024    }
025
026    public QEmuOptionsList(Collection<? extends QEmuOption> c) {
027        super(c);
028    }
029
030    public QEmuOptionsList(QEmuOption... c) {
031        this(Arrays.asList(c));
032    }
033
034    @Override
035    public void withAllocator(QEmuIdAllocator allocator) {
036        for (QEmuOption option : this)
037            if (option instanceof QEmuIdAllocator.Consumer)
038                ((QEmuIdAllocator.Consumer) option).withAllocator(allocator);
039    }
040
041    @Override
042    public void appendTo(List<? super String> line) {
043        for (QEmuOption option : this)
044            if (option != null)
045                option.appendTo(line);
046    }
047}