X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/0e9c0448c6566825b170b98ecff716b098bda10e..347996b4a10c4e8579080692afa60e0afb88b60a:/examples/java/kademlia/Bucket.java diff --git a/examples/java/kademlia/Bucket.java b/examples/java/kademlia/Bucket.java index cd6e6351bc..41d391d63c 100644 --- a/examples/java/kademlia/Bucket.java +++ b/examples/java/kademlia/Bucket.java @@ -1,76 +1,58 @@ -/* Copyright (c) 2012-2013. 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; +package kademlia; import java.util.ArrayList; -/** - * Stores the information held in a bucket - */ public class Bucket { - private ArrayList nodes; - private int id; - - /** - * Constructor - */ - public Bucket(int id) { - this.nodes = new ArrayList(); - 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 nodes; + private int id; + + public Bucket(int id) { + this.nodes = new ArrayList(); + 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 + "]"; + } }