/*******************************************************************************
 * Copyright (c) 2015 Pivotal Software, Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Pivotal Software, Inc. - initial API and implementation
 *******************************************************************************/
package org.springsource.ide.eclipse.commons.livexp.core;

public class OrExpression extends CompositeExpression<Boolean> {
	
	public OrExpression() {
		super(false);
	}

	@Override
	protected Boolean compute() {
		//TODO: could be smarter about how we manage dependencies on 
		// our children. As soon as value is computed we really only depend
		// on changes to the first n children used during the computation.
		for (LiveExpression<Boolean> c : getChildren()) {
			if (isTrue(c.getValue())) {
				return true;
			}
		}
		return false;
	}

	/**
	 * Null-safe check for truth value of boxed Boolean.
	 */
	private static boolean isTrue(Boolean value) {
		if (value!=null) {
			return value;
		}
		return false;
	}
	
}

@@ -653,17 +653,16 @@
 lean%3E %7B%0A
-%09
 %0A%09public
@@ -699,16 +699,157 @@
 e);%0A%09%7D%0A%0A
+%09public OrExpression(LiveExpression%3CBoolean%3E... children) %7B%0A%09%09this();%0A%09%09for (LiveExpression%3CBoolean%3E c : children) %7B%0A%09%09%09addChild(c);%0A%09%09%7D%0A%09%7D%0A%0A
 %09@Overri
@@ -944,17 +944,16 @@
 ncies on
- 
 %0A%09%09// ou
@@ -1386,12 +1386,11 @@
 lse;%0A%09%7D%0A
-%09
 %0A%7D%0A

Add a convenience constructor to LiveExp OrExpression