/** * Returns a copy of this builder with the reliability of the device to be * constructed set to the specified value. The reliability is applied for * both sending and receiving messages. Reliability must be * <code>0 ≤ r ≤ 1</code>. * @param reliability The reliability to set. * @return A new instance of {@link Builder} with reliability set to the * specified value. */ @CheckReturnValue public Builder withDefaultDeviceReliability(double reliability) { checkReliability(reliability); return new AutoValue_CommModel_Builder(reliability, defaultMaxRange()); }
/** * Returns a copy of this builder with the default maximum range for all * devices set to the specified value. By default devices will only be able * to send messages to other devices that are within this max range. * @param maxRange The maxRange to set. * @return A new instance of {@link Builder} with max range set to the * specified value. */ @CheckReturnValue public Builder withDefaultDeviceMaxRange(double maxRange) { checkRangeIsPositive(maxRange); return new AutoValue_CommModel_Builder(defaultReliability(), Optional.of(maxRange)); }
/** * Set up a simple and reliable world. */ @Before public void setUp() { model = CommModel .builder() .withDefaultDeviceReliability(1.0) .build(fakeDependencies()); agent1 = new Agent(new Point(0, 0)); agent2 = new Agent(new Point(0, 10)); agent3 = new Agent(new Point(5, 10)); agent4 = new Agent(new Point(5, 5)); agent5 = new Agent(new Point(5, 0)); model.register(agent1); model.register(agent2); model.register(agent3); model.register(agent4); model.register(agent5); TestUtil.testEnum(CommModel.EventTypes.class); }
/** * Tests that comm users should create a device. */ @Test public void testIdleCommUser() { boolean fail = false; try { CommModel.builder().build(fakeDependencies()) .register(new IdleCommUser()); } catch (final IllegalStateException e) { fail = true; } assertTrue(fail); }
/** * Creates a new default builder. */ @Before public void setUp() { builder = new CommDeviceBuilder(CommModel.builder() .build(CommModelTest.fakeDependencies()), mock(CommUser.class)); }
/** * @return A new builder for creating a {@link CommModel}. */ public static Builder builder() { return Builder.create(); }
Builder() { setDependencies(RandomProvider.class); setProvidingTypes(CommModel.class); }
@Override public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof CommModel.Builder) { CommModel.Builder that = (CommModel.Builder) o; return (Double.doubleToLongBits(this.defaultReliability) == Double.doubleToLongBits(that.defaultReliability())) && (this.defaultMaxRange.equals(that.defaultMaxRange())); } return false; }
CommModel(RandomGenerator rng, Builder b) { defaultReliability = b.defaultReliability(); defaultMaxRange = b.defaultMaxRange(); usersHasChanged = false; usersDevices = Maps.synchronizedBiMap( LinkedHashBiMap.<CommUser, CommDevice>create()); unregisteredUsersDevices = LinkedHashBiMap.<CommUser, CommDevice>create(); usersDevicesSnapshot = ImmutableBiMap.of(); eventDispatcher = new EventDispatcher(EventTypes.values()); randomGenerator = rng; }
@Before public void setUp() { builders = new CommDeviceBuilder[COMMUSERS.length]; final CommModel commModel = CommModel .builder() .build(CommModelTest.fakeDependencies()); for (int i = 0; i < COMMUSERS.length; i++) { builders[i] = new CommDeviceBuilder(commModel, COMMUSERS[i]); } }