@Test(expected = NullPointerException.class) public void testNullIterable() { new RandomAlgorithm().choose(null, null); }
@Override public ServiceEndPoint choose(Iterable<ServiceEndPoint> endPoints, ServicePoolStatistics statistics) { Preconditions.checkNotNull(endPoints); Iterator<ServiceEndPoint> iter = endPoints.iterator(); if (!iter.hasNext()) { return null; } List<ServiceEndPoint> list = Lists.newArrayList(iter); if (list.size() == 1) { return list.get(0); } return list.get(_rnd.nextInt(list.size())); }
RandomAlgorithm implements LoadBalanceAlgorithm { @Override public ServiceEndPoint choose(Iterable<ServiceEndPoint> endPoints, ServicePoolStatistics statistics) { Preconditions.checkNotNull(endPoints); Iterator<ServiceEndPoint> iter = endPoints.iterator(); if (!iter.hasNext()) { return null; } List<ServiceEndPoint> list = Lists.newArrayList(iter); if (list.size() == 1) { return list.get(0); } return list.get(_rnd.nextInt(list.size())); } }
RandomAlgorithm implements LoadBalanceAlgorithm { @Override public ServiceEndPoint choose(Iterable<ServiceEndPoint> endPoints, ServicePoolStatistics statistics) { Preconditions.checkNotNull(endPoints); Iterator<ServiceEndPoint> iter = endPoints.iterator(); if (!iter.hasNext()) { return null; } List<ServiceEndPoint> list = Lists.newArrayList(iter); if (list.size() == 1) { return list.get(0); } return list.get(_rnd.nextInt(list.size())); }  }
RandomAlgorithm implements LoadBalanceAlgorithm { @Override public ServiceEndPoint choose(Iterable<ServiceEndPoint> endPoints, ServicePoolStatistics statistics) { Preconditions.checkNotNull(endPoints); Iterator<ServiceEndPoint> iter = endPoints.iterator(); if (!iter.hasNext()) { return null; } List<ServiceEndPoint> list = Lists.newArrayList(iter); if (list.size() == 1) { return list.get(0); } return list.get(_rnd.nextInt(list.size())); }  @Override ServiceEndPoint choose(Iterable<ServiceEndPoint> endPoints, ServicePoolStatistics statistics); }
RandomAlgorithm implements LoadBalanceAlgorithm { @Override public ServiceEndPoint choose(Iterable<ServiceEndPoint> endPoints, ServicePoolStatistics statistics) { Preconditions.checkNotNull(endPoints); Iterator<ServiceEndPoint> iter = endPoints.iterator(); if (!iter.hasNext()) { return null; } List<ServiceEndPoint> list = Lists.newArrayList(iter); if (list.size() == 1) { return list.get(0); } return list.get(_rnd.nextInt(list.size())); }  @Override ServiceEndPoint choose(Iterable<ServiceEndPoint> endPoints, ServicePoolStatistics statistics);  }