/*
 * Copyright 2020 Nikita Shakarun
 *
 * 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 javax.microedition.amms;

import java.util.ArrayList;

import javax.microedition.media.Control;
import javax.microedition.media.MediaException;
import javax.microedition.media.Player;

public class BaseModule implements Module {
	private ArrayList<Player> players;

	@Override
	public void addMIDIChannel(Player player, int channel) throws MediaException {
	}

	@Override
	public void removeMIDIChannel(Player player, int channel) {
	}

	@Override
	public void addPlayer(Player player) throws MediaException {
		if (player == null) {
			throw new IllegalArgumentException("Player is null.");
		}
		if (player.getState() == Player.CLOSED) {
			throw new IllegalStateException("Can't add Player while it's in CLOSED state.");
		}
		players.add(player);
	}

	@Override
	public void removePlayer(Player player) {
		if (player == null) {
			throw new IllegalArgumentException("Player is null.");
		}
		players.remove(player);
	}

	@Override
	public Control getControl(String controlType) {
		return null;
	}

	@Override
	public Control[] getControls() {
		return new Control[0];
	}
}

/*
 * Copyright 2020 Nikita Shakarun
 *
 * 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 javax.microedition.amms;

import java.util.ArrayList;

import javax.microedition.media.Control;
import javax.microedition.media.MediaException;
import javax.microedition.media.Player;

public class BaseModule implements Module {
	private ArrayList<Player> players;

	public BaseModule() {
		players = new ArrayList<>();
	}

	@Override
	public void addMIDIChannel(Player player, int channel) throws MediaException {
	}

	@Override
	public void removeMIDIChannel(Player player, int channel) {
	}

	@Override
	public void addPlayer(Player player) throws MediaException {
		if (player == null) {
			throw new IllegalArgumentException("Player is null.");
		}
		if (player.getState() == Player.CLOSED) {
			throw new IllegalStateException("Can't add Player while it's in CLOSED state.");
		}
		players.add(player);
	}

	@Override
	public void removePlayer(Player player) {
		if (player == null) {
			throw new IllegalArgumentException("Player is null.");
		}
		players.remove(player);
	}

	@Override
	public Control getControl(String controlType) {
		return null;
	}

	@Override
	public Control[] getControls() {
		return new Control[0];
	}
}

Fix BaseModule