package model;

import io.Preface;

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

public class Weights {
	private 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 = (double[]) weights.clone();
	}

	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;
	}
}

@@ -446,19 +446,8 @@
 ts =
- (double%5B%5D)
  wei
@@ -567,16 +567,39 @@
 der in =
+ null;%0A%0A%09%09try %7B%0A%09%09%09in =
  new Buf
@@ -640,16 +640,18 @@
 File));%0A
+%0A%09
 %09%09Prefac
@@ -670,16 +670,17 @@
 e(in);%0A%0A
+%09
 %09%09String
@@ -695,16 +695,17 @@
 null;%0A%09%09
+%09
 while ((
@@ -737,16 +737,17 @@
 null) %7B%0A
+%09
 %09%09%09doubl
@@ -783,16 +783,17 @@
 (line);%0A
+%09
 %09%09%09weigh
@@ -816,16 +816,17 @@
 %0A%09%09%09
+%09
 ID++;%0A%09%09
 %7D%0A%0A%09
@@ -821,19 +821,21 @@
 ID++;%0A%09%09
+%09
 %7D%0A%0A
+%09
 %09%09if (ID
@@ -856,16 +856,17 @@
 ngth) %7B%0A
+%09
 %09%09%09throw
@@ -940,16 +940,72 @@
 res!%22);%0A
+%09%09%09%7D%0A%09%09%7D finally %7B%0A%09%09%09if ( in != null ) %7B in.close(); %7D%0A
 %09%09%7D%0A%09%7D%0A%0A

Refactor Weights