All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.flash3388.flashlib.io.devices.DoubleSolenoidGroup Maven / Gradle / Ivy

The newest version!
package com.flash3388.flashlib.io.devices;

import com.castle.util.closeables.Closer;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;

/**
 * A group of {@link DoubleSolenoid} controlled as one.
 *
 * @since FlashLib 3.0.0.
 */
public class DoubleSolenoidGroup implements DoubleSolenoid, DeviceGroup {

    private final Collection mSolenoids;

    public DoubleSolenoidGroup(Collection solenoids) {
        if (solenoids.isEmpty()) {
            throw new IllegalArgumentException("Expected a non-empty list");
        }
        mSolenoids = new ArrayList<>(solenoids);
    }

    public DoubleSolenoidGroup(DoubleSolenoid... solenoids) {
        this(Arrays.asList(solenoids));
    }

    @Override
    public void set(Value value) {
        for (DoubleSolenoid solenoid : mSolenoids) {
            solenoid.set(value);
        }
    }

    @Override
    public Value get() {
        return mSolenoids.iterator().next().get();
    }

    @Override
    public void close() throws IOException {
        Closer closer = Closer.empty();
        closer.addAll(mSolenoids);

        try {
            closer.close();
        } catch (Exception e) {
            throw new IOException(e);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy