package model;

import io.Preface;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class Weights {
	double[] weights;

	public Weights() {
	}

	public Weights(String weightsFile, int numFeatures) throws IOException {
		this.weights = new double[numFeatures];

		if (!weightsFile.equals("zero")) {
			readWeights(weightsFile);
		}
	}

	public void setWeights(double[] weights) {
		this.weights = weights;
	}

	private void readWeights(String weightsFile) throws IOException {
		int ID = 0;

		BufferedReader in = new BufferedReader(new FileReader(weightsFile));
		Preface.readPreface(in);

		String line = null;
		while ((line = in.readLine()) != null) {
			double weight = Double.parseDouble(line);
			weights[ID] = weight;
			ID++;
		}

		if (ID != weights.length) {
			throw new IllegalArgumentException("number of weights != number of features!");
		}
	}

	public double getWeight(int ID) {
		return weights[ID];
	}

	public void setWeight(int ID, double weight) {
		weights[ID] = weight;
	}
}

@@ -140,16 +140,24 @@
 ghts %7B%0A%09
+private 
 double%5B%5D
@@ -443,23 +443,42 @@
 ights = 
-weights
+(double%5B%5D) weights.clone()
 ;%0A%09%7D%0A%0A%09p

Fix leaky abstraction by cloning double array instead of just copying reference.