package net.woodyfolsom.msproj.ann2;

import java.util.Arrays;

import javax.xml.bind.annotation.XmlElement;

public class Layer {
	private int[] neuronIds;
	
	public Layer() {
		neuronIds = new int[0];
	}
	
	public Layer(int numNeurons) {
		neuronIds = new int[numNeurons];
	}
	
	public int size() {
		return neuronIds.length;
	}

	public int getNeuronId(int index) {
		return neuronIds[index];
	}
	
	@XmlElement
	public int[] getNeuronIds() {
		int[] safeCopy = new int[neuronIds.length];
		System.arraycopy(neuronIds, 0, safeCopy, 0, neuronIds.length);
		return safeCopy;
	}

	public void setNeuronId(int index, int id) {
		neuronIds[index] = id;
	}
	
	public void setNeuronIds(int[] neuronIds) {
		this.neuronIds = new int[neuronIds.length];
		System.arraycopy(neuronIds, 0, this.neuronIds, 0, neuronIds.length);
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + Arrays.hashCode(neuronIds);
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Layer other = (Layer) obj;
		if (!Arrays.equals(neuronIds, other.neuronIds))
			return false;
		return true;
	}

}