@SuppressWarnings("ConstantConditions")
    public boolean addOrReplaceAction(@NonNull Action a) {
        if (a == null) {
            throw new IllegalArgumentException("Action must be non-null");
        }
        // CopyOnWriteArrayList does not support Iterator.remove, so need to do it this way:
        List<Action> old = new ArrayList<>(1);
        List<Action> current = getActions();
        boolean found = false;
        for (Action a2 : current) {
            if (!found && a.equals(a2)) {
                found = true;
            } else  if (a2.getClass() == a.getClass()) {
                old.add(a2);
            }
        }
        current.removeAll(old);
        if (!found) {
            addAction(a);
        }
        return !found || !old.isEmpty();
    }
@SuppressWarnings("deprecation")
    @Test
    public void addOrReplaceAction() {
        CauseAction a1 = new CauseAction();
        ParametersAction a2 = new ParametersAction();
        thing.addAction(a1);
        thing.addAction(a2);
        CauseAction a3 = new CauseAction();
        assertTrue(thing.addOrReplaceAction(a3));
        assertEquals(Arrays.asList(a2, a3), thing.getActions());
        assertFalse(thing.addOrReplaceAction(a3));
        assertEquals(Arrays.asList(a2, a3), thing.getActions());
        thing.addAction(a1);
        assertEquals(Arrays.asList(a2, a3, a1), thing.getActions());
        assertTrue(thing.addOrReplaceAction(a3));
        assertEquals(Arrays.asList(a2, a3), thing.getActions());
    }