1414import org .restlet .Restlet ;
1515import org .restlet .routing .Route ;
1616
17+ import java .security .SecureRandom ;
1718import java .util .Collections ;
1819import java .util .List ;
19- import java .util .Random ;
2020import java .util .concurrent .CopyOnWriteArrayList ;
2121
2222/**
3434 * @see java.util.List
3535 */
3636public final class RouteList extends WrapperList <Route > {
37- /** The index of the last route used in the round robin mode. */
37+ /** The index of the last route used in the round- robin mode. */
3838 private volatile int lastIndex ;
39+ /** Used when asked to return a random route. */
40+ private final SecureRandom random = new SecureRandom ();
3941
4042 /**
4143 * Constructor.
4244 */
4345 public RouteList () {
44- super (new CopyOnWriteArrayList <Route >());
46+ super (new CopyOnWriteArrayList <>());
4547 this .lastIndex = -1 ;
4648 }
4749
@@ -51,7 +53,7 @@ public RouteList() {
5153 * @param delegate The delegate list.
5254 */
5355 public RouteList (List <Route > delegate ) {
54- super (new CopyOnWriteArrayList <Route >(delegate ));
56+ super (new CopyOnWriteArrayList <>(delegate ));
5557 this .lastIndex = -1 ;
5658 }
5759
@@ -120,7 +122,7 @@ public synchronized Route getLast(Request request, Response response, float requ
120122 }
121123
122124 /**
123- * Returns a next route match in a round robin mode for a given call.
125+ * Returns a next route match in a round- robin mode for a given call.
124126 *
125127 * @param request The request to score.
126128 * @param response The response to score.
@@ -159,7 +161,7 @@ public synchronized Route getRandom(Request request, Response response, float re
159161 int length = size ();
160162
161163 if (length > 0 ) {
162- int j = new Random () .nextInt (length );
164+ int j = random .nextInt (length );
163165 Route route = get (j );
164166
165167 if (route .score (request , response ) >= requiredScore ) {
@@ -169,7 +171,7 @@ public synchronized Route getRandom(Request request, Response response, float re
169171 boolean loopedAround = false ;
170172
171173 do {
172- if ((j == length ) && ( loopedAround == false ) ) {
174+ if ((j == length ) && ! loopedAround ) {
173175 j = 0 ;
174176 loopedAround = true ;
175177 }
@@ -187,7 +189,7 @@ public synchronized Route getRandom(Request request, Response response, float re
187189 }
188190
189191 /**
190- * Removes all routes routing to a given target.
192+ * Removes all routes to a given target.
191193 *
192194 * @param target The target Restlet to detach.
193195 */
0 commit comments