X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/f3b7e5f4b4d7c87ee3e8827313ec966ea8fc8387..6fbcdfade89b3812c24152c86f8aa3be510df7f2:/examples/deprecated/java/dht/kademlia/Answer.java diff --git a/examples/deprecated/java/dht/kademlia/Answer.java b/examples/deprecated/java/dht/kademlia/Answer.java deleted file mode 100644 index 54bd4c0525..0000000000 --- a/examples/deprecated/java/dht/kademlia/Answer.java +++ /dev/null @@ -1,73 +0,0 @@ -/* Copyright (c) 2012-2020. 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 dht.kademlia; -import java.util.ArrayList; -import java.util.Collections; - -/* Answer to a "FIND_NODE" query. Contains the nodes closest to an id given */ -public class Answer { - private int destinationId; - /* Closest nodes in the answer. */ - private ArrayList nodes; - - public Answer(int destinationId) { - this.destinationId = destinationId; - nodes = new ArrayList<>(); - } - - protected int getDestinationId() { - return destinationId; - } - - protected ArrayList getNodes() { - return nodes; - } - - protected int size() { - return nodes.size(); - } - - public void trim() { - if (nodes.size() > Common.BUCKET_SIZE) - nodes.subList(nodes.size() - Common.BUCKET_SIZE, nodes.size()).clear(); - } - - public void add(Contact contact) { - nodes.add(contact); - } - - /* Merge the contents of this answer with another answer */ - public int merge(Answer answer) { - int nbAdded = 0; - - for (Contact c: answer.getNodes()) { - if (!nodes.contains(c)) { - nbAdded++; - nodes.add(c); - } - } - Collections.sort(nodes); - //Trim the list - answer.trim(); - - return nbAdded; - } - - /* Returns if the destination has been found */ - public boolean destinationFound() { - if (nodes.isEmpty()) { - return false; - } - Contact tail = nodes.get(0); - return tail.getDistance() == 0; - } - - @Override - public String toString() { - return "Answer [destinationId=" + destinationId + ", nodes=" + nodes + "]"; - } -}