A
lgorithmique
N
umérique
D
istribuée
Public GIT Repository
projects
/
simgrid.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Update copyright lines with new year.
[simgrid.git]
/
examples
/
java
/
dht
/
kademlia
/
Answer.java
diff --git
a/examples/java/dht/kademlia/Answer.java
b/examples/java/dht/kademlia/Answer.java
index
1421529
..
28a9d4c
100644
(file)
--- a/
examples/java/dht/kademlia/Answer.java
+++ b/
examples/java/dht/kademlia/Answer.java
@@
-1,4
+1,4
@@
-/* Copyright (c) 2012-201
4, 2016
. The SimGrid Team.
+/* Copyright (c) 2012-201
9
. The SimGrid Team.
* All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
* All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
@@
-16,23
+16,24
@@
public class Answer {
public Answer(int destinationId) {
this.destinationId = destinationId;
public Answer(int destinationId) {
this.destinationId = destinationId;
- nodes = new ArrayList<
Contact
>();
+ nodes = new ArrayList<>();
}
}
- int getDestinationId() {
+
protected
int getDestinationId() {
return destinationId;
}
return destinationId;
}
- ArrayList<Contact> getNodes() {
+
protected
ArrayList<Contact> getNodes() {
return nodes;
}
return nodes;
}
- int size() {
+
protected
int size() {
return nodes.size();
}
return nodes.size();
}
- public void remove(int index) {
- nodes.remove(index);
+ public void trim() {
+ if (nodes.size() > Common.BUCKET_SIZE)
+ nodes.subList(nodes.size() - Common.BUCKET_SIZE, nodes.size()).clear();
}
public void add(Contact contact) {
}
public void add(Contact contact) {
@@
-51,15
+52,14
@@
public class Answer {
}
Collections.sort(nodes);
//Trim the list
}
Collections.sort(nodes);
//Trim the list
- while (answer.size() > Common.BUCKET_SIZE) {
- answer.remove(answer.size() - 1);
- }
+ answer.trim();
+
return nbAdded;
}
/* Returns if the destination has been found */
public boolean destinationFound() {
return nbAdded;
}
/* Returns if the destination has been found */
public boolean destinationFound() {
- if (nodes.
size() < 1
) {
+ if (nodes.
isEmpty()
) {
return false;
}
Contact tail = nodes.get(0);
return false;
}
Contact tail = nodes.get(0);