Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Various cleanups in the java world (1/2)
[simgrid.git] / examples / java / kademlia / Bucket.java
index 8ad2326..41d391d 100644 (file)
@@ -1,77 +1,58 @@
-/* Copyright (c) 2012-2014. The SimGrid Team.
+/* Copyright (c) 2012-2014, 2016. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* 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. */
 
 package kademlia;
-
 import java.util.ArrayList;
 
-/**
- * Stores the information held in a bucket
- */
 public class Bucket {
-       private ArrayList<Integer> nodes;
-       private int id;
-       
-       /**
-        * Constructor
-        */
-       public Bucket(int id) {
-               this.nodes = new ArrayList<Integer>();
-               this.id = id;
-       }
-       /**
-        * Returns the bucket's id.
-        */
-       public int getId() {
-               return this.id;
-       }
-       /**
-        * Returns how many nodes there is in the bucket
-        */
-       public int size() {
-               return nodes.size();
-       }
-       /**
-        * Returns if the bucket contains the element
-        */
-       public boolean contains(int id) {
-               return nodes.contains(id);
-       }
-       /**
-        * Add an to the front of the bucket
-        */
-       public void add(int id) {
-               nodes.add(0,id);
-       }
-       /**
-        * Pushs an element into the front of a bucket.
-        */
-       public void pushToFront(int id) {
-               int i = nodes.indexOf(id);
-               nodes.remove(i);
-               nodes.add(0, id);
-       }
-       /**
-        * Returns a node
-        */
-       public int getNode(int id) {
-               return nodes.get(id);
-       }
-       /**
-        * Adds the content of the bucket into a answer object.
-        */
-       public void addToAnswer(Answer answer, int destination) {
-               for (int id : this.nodes) {
-                       answer.getNodes().add(new Contact(id,id ^ destination));
-               }
-       }
-       
-       @Override
-       public String toString() {
-               return "Bucket [id= " + id + " nodes=" + nodes + "]";
-       }
-       
+  private ArrayList<Integer> nodes;
+  private int id;
+
+  public Bucket(int id) {
+    this.nodes = new ArrayList<Integer>();
+    this.id = id;
+  }
+
+  public int getId() {
+    return this.id;
+  }
+
+  public int size() {
+    return nodes.size();
+  }
+
+  public boolean contains(int id) {
+    return nodes.contains(id);
+  }
+
+  /* Add a node to the front of the bucket */
+  public void add(int id) {
+    nodes.add(0,id);
+  }
+
+  /* Push a node to the front of a bucket */
+  public void pushToFront(int id) {
+    int i = nodes.indexOf(id);
+    nodes.remove(i);
+    nodes.add(0, id);
+  }
+
+  public int getNode(int id) {
+    return nodes.get(id);
+  }
+
+  /* Add the content of the bucket into a answer object. */
+  public void addToAnswer(Answer answer, int destination) {
+    for (int id : this.nodes) {
+      answer.getNodes().add(new Contact(id,id ^ destination));
+    }
+  }
+
+  @Override
+  public String toString() {
+    return "Bucket [id= " + id + " nodes=" + nodes + "]";
+  }
 }