001package jmri.jmrit.ussctc;
002
003
004import java.util.*;
005
006/**
007 * Combines multiple locks into one with an AND operation.
008 *
009 * @author Bob Jacobsen Copyright (C) 2007, 2017
010 */
011public class CombinedLock implements Lock {
012
013    public CombinedLock(List<Lock> list) {
014        this.list = list;
015    }
016
017    List<Lock> list;
018
019    /**
020     * Test the lock conditions
021     * @return True if lock is clear and operation permitted
022     */
023    @Override
024    public boolean isLockClear(LockLogger lockLogger) {
025        for (Lock lock : list)
026            if (!lock.isLockClear(lockLogger)) return false;
027        return true;
028    }
029
030    @Override
031    public String toString() {
032        String retval = isLockClear(debugLockLogger) ? "clear " : "locked";
033        retval = retval+debugLockLogger.memory.getValue();
034        return retval;
035    }
036
037}