1 /* Copyright (c) 2012-2014. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
9 import java.util.ArrayList;
12 * Stores the information held in a bucket
15 private ArrayList<Integer> nodes;
21 public Bucket(int id) {
22 this.nodes = new ArrayList<Integer>();
26 * Returns the bucket's id.
32 * Returns how many nodes there is in the bucket
38 * Returns if the bucket contains the element
40 public boolean contains(int id) {
41 return nodes.contains(id);
44 * Add an to the front of the bucket
46 public void add(int id) {
50 * Pushs an element into the front of a bucket.
52 public void pushToFront(int id) {
53 int i = nodes.indexOf(id);
60 public int getNode(int id) {
64 * Adds the content of the bucket into a answer object.
66 public void addToAnswer(Answer answer, int destination) {
67 for (int id : this.nodes) {
68 answer.getNodes().add(new Contact(id,id ^ destination));
73 public String toString() {
74 return "Bucket [id= " + id + " nodes=" + nodes + "]";