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

net.dermetfan.gdx.Multiplexer Maven / Gradle / Ivy

There is a newer version: 0.13.4
Show newest version
/** Copyright 2014 Robin Stumm ([email protected], http://dermetfan.net)
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License. */

package net.dermetfan.gdx;

import com.badlogic.gdx.utils.Array;

/** Base class for multiplexers that forward e.g. events to an Array of receivers
 *  @param  the type of the receivers
 *  @author dermetfan */
public abstract class Multiplexer {

	/** the receivers */
	protected final Array receivers;

	/** @see Array#Array() */
	public Multiplexer() {
		receivers = new Array<>();
	}

	/** @see Array#Array(int) */
	public Multiplexer(int size) {
		receivers = new Array<>(size);
	}

	/** @param receivers the {@link #receivers} to set */
	@SafeVarargs
	public Multiplexer(T... receivers) {
		this.receivers = new Array<>(receivers);
	}

	/** @param receivers the {@link #receivers} to set */
	public Multiplexer(Array receivers) {
		this.receivers = new Array<>(receivers);
	}

	/** @param receiver the receiver to add */
	public void add(T receiver) {
		receivers.add(receiver);
	}

	/** @param receiver the receiver to remove */
	public boolean remove(T receiver) {
		return receivers.removeValue(receiver, true);
	}

	/** @see Array#clear() */
	public void clear() {
		receivers.clear();
	}

	/** @see Array#size */
	public int size() {
		return receivers.size;
	}

	/** @param receivers the {@link #receivers} to set */
	public void setReceivers(Array receivers) {
		this.receivers.clear();
		this.receivers.addAll(receivers);
	}

	/** @param receivers the {@link #receivers} to set */
	@SuppressWarnings("unchecked")
	public void setReceivers(T... receivers) {
		this.receivers.clear();
		this.receivers.addAll(receivers);
	}

	/** @return the {@link #receivers} */
	public Array getReceivers() {
		return receivers;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy