/*******************************************************************************
 * Copyright (c) 2015 Pivotal, 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, Inc. - initial API and implementation
 *******************************************************************************/
package org.springsource.ide.eclipse.commons.livexp.core;

import org.springsource.ide.eclipse.commons.livexp.core.AsyncLiveExpression;
import org.springsource.ide.eclipse.commons.livexp.core.ValueListener;

import com.google.common.collect.ImmutableSet;

/**
 * This is like LiveSet / LiveSetVariable, but it can only be 'observed' not mutated.
 */
public abstract class ObservableSet<T> extends AsyncLiveExpression<ImmutableSet<T>> {

	/**
	 * Deprecated use one of the constructors that controls synch versus async behavior explicitly.
	 */
	@Deprecated
	public ObservableSet() {
		//Make it synch as that is 'backwards' compatible. Just in case existing code expects it.
		this(ImmutableSet.<T>of(), AsyncMode.SYNC, AsyncMode.SYNC);
	}

	public ObservableSet(ImmutableSet<T> initialValue, AsyncMode refreshMode, AsyncMode eventsMode) {
		super(initialValue, refreshMode, eventsMode);
	}

	public static <T> ObservableSet<T> constant(ImmutableSet<T> value) {
		return new ObservableSet<T>(value, AsyncMode.SYNC, AsyncMode.SYNC) {
			@Override
			protected ImmutableSet<T> compute() {
				return value;
			}

			@Override
			public void addListener(ValueListener<ImmutableSet<T>> l) {
				l.gotValue(this, value);
				//Beyond the initial notification ... we ignore listeners... we will never notify again since
				//constants can't change
			}
			@Override
			public void removeListener(ValueListener<ImmutableSet<T>> l) {
				//Ignore all listeners we will never notify anyone since
				//constants can't change
			}

			@Override
			public void syncRefresh() {
				//Ignore all refreshes... no need to refresh anything since
				//constants can't change
			}
		};
	}

	public ImmutableSet<T> getValues() {
		return getValue();
	}

	public boolean contains(T e) {
		return getValues().contains(e);
	}

}

@@ -582,77 +582,39 @@
 ort 
-org.springsource.ide.eclipse.commons.livexp.core.AsyncLiveExpression;
+java.util.concurrent.Callable;%0A
 %0Aimp
@@ -665,25 +665,16 @@
 exp.
-core.ValueListene
+Activato
 r;%0A%0A
@@ -2272,10 +2272,390 @@
 e);%0A%09%7D%0A%0A
+%09/**%0A%09 * A lambda-friendly way to create a ObservableSet from a 'compute' function.%0A%09 */%0A%09public static %3CT%3E ObservableSet%3CT%3E create(Callable%3CImmutableSet%3CT%3E%3E computer) %7B%0A%09%09return new ObservableSet%3CT%3E() %7B%0A%09%09%09protected ImmutableSet%3CT%3E compute() %7B%0A%09%09%09%09try %7B%0A%09%09%09%09%09return computer.call();%0A%09%09%09%09%7D catch (Exception e) %7B%0A%09%09%09%09%09Activator.log(e);%0A%09%09%09%09%09return getValues();%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%7D;%0A%09%7D%0A%0A
 %7D%0A

Add a lambda-friendly create function to ObservableSet