/*
 * Copyright (c) Centre de Calcul de l'IN2P3 du CNRS
 * Contributor(s) : Frédéric SUTER (2015)

 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the license (GNU LGPL) which comes with this package.
 */
//import java.util.Random;
import java.util.Random;
import java.util.Vector;

public class LogicalFile {
	private String name;
	private long size;
	private Vector<SE> locations;
	private Random randomGenerator;
	private int index;

	public String getName() {
		return name;
	}

	public void setSize(long size) {
		this.size = size;
	}

	public long getSize() {
		return size;
	}

	public void addLocation(SE se) {
		locations.add(se);
	}

	public boolean isNewLocation(SE se) {
		return locations.contains((Object) se);
	}

	public SE getLocation() {
		// TODO return SE randomly for now. Might be interesting to implement
		// TODO some load balancing strategy
		int selectedIndex = (index++) % locations.size();
		
//		rand = new Random();
//		int selectedIndex = rand.nextInt(locations.size());

		return locations.get(selectedIndex);
	}

	
	public Vector<SE> getReplicaLocations() {
		return this.locations;

	}
	
	public String toString() {
		return "file '" + name + "' of size " + size + " stored on "
				+ locations.toString();
	}

	@Override
	public boolean equals(Object obj) {
		LogicalFile file = (LogicalFile) obj;
		return name.equals(file.getName());
	}

	public LogicalFile(String name, long size, Vector<SE> locations) {
		super();
		this.index = 0;
		this.name = name;
		this.size = size;
		this.locations = locations;
	    this.randomGenerator = new Random();
	}

	// In most cases, this constructor with a single location will be used.
	public LogicalFile(String name, long size, SE location) {
		this(name, size, (Vector<SE>) null);
		this.locations = new Vector<SE>();
		this.locations.add(location);
	    this.randomGenerator = new Random();
	}
}

@@ -278,33 +278,8 @@
 om;%0A
-import java.util.Random;%0A
 impo
@@ -401,16 +401,19 @@
 tions;%0A%09
+// 
 private 
@@ -945,62 +945,26 @@
 ;%0A%09%09
-%0A
 //
-%09%09rand = new Random();%0A//%09%09int selectedIndex = rand
+ randomGenerator
 .nex
@@ -987,17 +987,16 @@
 ize());%0A
-%0A
 %09%09return
@@ -1034,84 +1034,8 @@
 %09%7D%0A%0A
-%09%0A%09public Vector%3CSE%3E getReplicaLocations() %7B%0A%09%09return this.locations;%0A%0A%09%7D%0A%09%0A
 %09pub
@@ -1451,19 +1451,19 @@
 tions;%0A%09
-   
+%09//
  this.ra
@@ -1740,50 +1740,8 @@
 n);%0A
-%09    this.randomGenerator = new Random();%0A
 %09%7D%0A%7D

Revert "add getReplcaLocations in LogicalFile.java"