MapExtra extends Extra<A, F> { protected boolean put(K key, @Nullable V value) { if (key == null) return false; int i = indexOfExistingKey(state(), key); if (i == -1 && factory.maxDynamicEntries == 0) { Platform.get().log("Ignoring request to add a dynamic key", null); return false; } synchronized (lock) { Object[] prior = state(); if (i == -1) i = indexOfDynamicKey(prior, key); if (i == -1) return addNewEntry(prior, key, value); if (equal(value, prior[i + 1])) return false; Object[] newState = Arrays.copyOf(prior, prior.length); newState[i + 1] = value; this.state = newState; return true; } } protected  MapExtra(F factory);   }
@Test public void put() { extra.put("1", "one"); assertThat(extra.get("1")).isEqualTo("one"); assertThat(extra.isEmpty()).isFalse(); }
@Test public void equalsAndHashCode() { assertThat(factory.create()) .isEqualTo(factory.create()); assertThat(factory.create()) .hasSameHashCodeAs(factory.create()); extra.put("1", "one"); extra.put("2", "two"); BasicMapExtra extra2 = factory.create(); extra2.put("1", "one"); extra2.put("2", "two"); assertThat(extra).isEqualTo(extra2); assertThat(extra).hasSameHashCodeAs(extra2); extra2.put("2", "three"); assertThat(extra).isNotEqualTo(extra2); assertThat(extra.hashCode()).isNotEqualTo(extra2.hashCode()); }