How to use probe method of org.assertj.core.test.jdk11.ImmutableCollections class

Best Assertj code snippet using org.assertj.core.test.jdk11.ImmutableCollections.probe

Source:ImmutableCollections.java Github

copy

Full Screen

...529 size = input.length; // implicit nullcheck of input530 elements = (E[]) new Object[EXPAND_FACTOR * input.length];531 for (int i = 0; i < input.length; i++) {532 E e = input[i];533 int idx = probe(e); // implicit nullcheck of e534 if (idx >= 0) {535 throw new IllegalArgumentException("duplicate element: " + e);536 } else {537 elements[-(idx + 1)] = e;538 }539 }540 }541 @Override542 public int size() {543 return size;544 }545 @Override546 public boolean contains(Object o) {547 Objects.requireNonNull(o);548 return size > 0 && probe(o) >= 0;549 }550 private final class SetNIterator implements Iterator<E> {551 private int remaining;552 private int idx;553 SetNIterator() {554 remaining = size();555 if (remaining > 0) {556 idx = Math.floorMod(SALT, elements.length);557 }558 }559 @Override560 public boolean hasNext() {561 return remaining > 0;562 }563 private int nextIndex() {564 int idx = this.idx;565 if (SALT >= 0) {566 if (++idx >= elements.length) {567 idx = 0;568 }569 } else {570 if (--idx < 0) {571 idx = elements.length - 1;572 }573 }574 return this.idx = idx;575 }576 @Override577 public E next() {578 if (hasNext()) {579 E element;580 // skip null elements581 while ((element = elements[nextIndex()]) == null) {}582 remaining--;583 return element;584 } else {585 throw new NoSuchElementException();586 }587 }588 }589 @Override590 public Iterator<E> iterator() {591 return new SetN<E>.SetNIterator();592 }593 @Override594 public int hashCode() {595 int h = 0;596 for (E e : elements) {597 if (e != null) {598 h += e.hashCode();599 }600 }601 return h;602 }603 // returns index at which element is present; or if absent,604 // (-i - 1) where i is location where element should be inserted.605 // Callers are relying on this method to perform an implicit nullcheck606 // of pe607 private int probe(Object pe) {608 int idx = Math.floorMod(pe.hashCode(), elements.length);609 while (true) {610 E ee = elements[idx];611 if (ee == null) {612 return -idx - 1;613 } else if (pe.equals(ee)) {614 return idx;615 } else if (++idx == elements.length) {616 idx = 0;617 }618 }619 }620 private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {621 throw new InvalidObjectException("not serial proxy");622 }623 private Object writeReplace() {624 Object[] array = new Object[size];625 int dest = 0;626 for (Object o : elements) {627 if (o != null) {628 array[dest++] = o;629 }630 }631 return new CollSer(CollSer.IMM_SET, array);632 }633 }634 // ---------- Map Implementations ----------635 @SuppressWarnings("unchecked")636 static <K, V> Map<K, V> emptyMap() {637 return (Map<K, V>) MapN.EMPTY_MAP;638 }639 abstract static class AbstractImmutableMap<K, V> extends AbstractMap<K, V> implements Serializable {640 @Override641 public void clear() {642 throw uoe();643 }644 @Override645 public V compute(K key, BiFunction<? super K, ? super V, ? extends V> rf) {646 throw uoe();647 }648 @Override649 public V computeIfAbsent(K key, Function<? super K, ? extends V> mf) {650 throw uoe();651 }652 @Override653 public V computeIfPresent(K key, BiFunction<? super K, ? super V, ? extends V> rf) {654 throw uoe();655 }656 @Override657 public V merge(K key, V value, BiFunction<? super V, ? super V, ? extends V> rf) {658 throw uoe();659 }660 @Override661 public V put(K key, V value) {662 throw uoe();663 }664 @Override665 public void putAll(Map<? extends K, ? extends V> m) {666 throw uoe();667 }668 @Override669 public V putIfAbsent(K key, V value) {670 throw uoe();671 }672 @Override673 public V remove(Object key) {674 throw uoe();675 }676 @Override677 public boolean remove(Object key, Object value) {678 throw uoe();679 }680 @Override681 public V replace(K key, V value) {682 throw uoe();683 }684 @Override685 public boolean replace(K key, V oldValue, V newValue) {686 throw uoe();687 }688 @Override689 public void replaceAll(BiFunction<? super K, ? super V, ? extends V> f) {690 throw uoe();691 }692 }693 static final class Map1<K, V> extends AbstractImmutableMap<K, V> {694 private final K k0;695 private final V v0;696 Map1(K k0, V v0) {697 this.k0 = Objects.requireNonNull(k0);698 this.v0 = Objects.requireNonNull(v0);699 }700 @Override701 public Set<Map.Entry<K, V>> entrySet() {702 return Jdk11.Set.of(new KeyValueHolder<>(k0, v0));703 }704 @Override705 public V get(Object o) {706 return o.equals(k0) ? v0 : null; // implicit nullcheck of o707 }708 @Override709 public boolean containsKey(Object o) {710 return o.equals(k0); // implicit nullcheck of o711 }712 @Override713 public boolean containsValue(Object o) {714 return o.equals(v0); // implicit nullcheck of o715 }716 private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {717 throw new InvalidObjectException("not serial proxy");718 }719 private Object writeReplace() {720 return new CollSer(CollSer.IMM_MAP, k0, v0);721 }722 @Override723 public int hashCode() {724 return k0.hashCode() ^ v0.hashCode();725 }726 }727 /**728 * An array-based Map implementation. There is a single array "table" that729 * contains keys and values interleaved: table[0] is kA, table[1] is vA,730 * table[2] is kB, table[3] is vB, etc. The table size must be even. It must731 * also be strictly larger than the size (the number of key-value pairs contained732 * in the map) so that at least one null key is always present.733 * @param <K> the key type734 * @param <V> the value type735 */736 static final class MapN<K, V> extends AbstractImmutableMap<K, V> {737 // EMPTY_MAP may be initialized from the CDS archive.738 static Map<?, ?> EMPTY_MAP;739 static {740 // VM.initializeFromArchive(MapN.class);741 EMPTY_MAP = new MapN<>();742 }743 final Object[] table; // pairs of key, value744 final int size; // number of pairs745 MapN(Object... input) {746 if ((input.length & 1) != 0) { // implicit nullcheck of input747 throw new InternalError("length is odd");748 }749 size = input.length >> 1;750 int len = EXPAND_FACTOR * input.length;751 len = (len + 1) & ~1; // ensure table is even length752 table = new Object[len];753 for (int i = 0; i < input.length; i += 2) {754 @SuppressWarnings("unchecked")755 K k = Objects.requireNonNull((K) input[i]);756 @SuppressWarnings("unchecked")757 V v = Objects.requireNonNull((V) input[i + 1]);758 int idx = probe(k);759 if (idx >= 0) {760 throw new IllegalArgumentException("duplicate key: " + k);761 } else {762 int dest = -(idx + 1);763 table[dest] = k;764 table[dest + 1] = v;765 }766 }767 }768 @Override769 public boolean containsKey(Object o) {770 Objects.requireNonNull(o);771 return size > 0 && probe(o) >= 0;772 }773 @Override774 public boolean containsValue(Object o) {775 Objects.requireNonNull(o);776 for (int i = 1; i < table.length; i += 2) {777 Object v = table[i];778 if (v != null && o.equals(v)) {779 return true;780 }781 }782 return false;783 }784 @Override785 public int hashCode() {786 int hash = 0;787 for (int i = 0; i < table.length; i += 2) {788 Object k = table[i];789 if (k != null) {790 hash += k.hashCode() ^ table[i + 1].hashCode();791 }792 }793 return hash;794 }795 @Override796 @SuppressWarnings("unchecked")797 public V get(Object o) {798 if (size == 0) {799 Objects.requireNonNull(o);800 return null;801 }802 int i = probe(o);803 if (i >= 0) {804 return (V) table[i + 1];805 } else {806 return null;807 }808 }809 @Override810 public int size() {811 return size;812 }813 class MapNIterator implements Iterator<Map.Entry<K, V>> {814 private int remaining;815 private int idx;816 MapNIterator() {817 remaining = size();818 if (remaining > 0) {819 idx = Math.floorMod(SALT, table.length >> 1) << 1;820 }821 }822 @Override823 public boolean hasNext() {824 return remaining > 0;825 }826 private int nextIndex() {827 int idx = this.idx;828 if (SALT >= 0) {829 if ((idx += 2) >= table.length) {830 idx = 0;831 }832 } else {833 if ((idx -= 2) < 0) {834 idx = table.length - 2;835 }836 }837 return this.idx = idx;838 }839 @Override840 public Map.Entry<K, V> next() {841 if (hasNext()) {842 while (table[nextIndex()] == null) {}843 @SuppressWarnings("unchecked")844 Map.Entry<K, V> e = new KeyValueHolder<>((K) table[idx], (V) table[idx + 1]);845 remaining--;846 return e;847 } else {848 throw new NoSuchElementException();849 }850 }851 }852 @Override853 public Set<Map.Entry<K, V>> entrySet() {854 return new AbstractSet<Map.Entry<K, V>>() {855 @Override856 public int size() {857 return MapN.this.size;858 }859 @Override860 public Iterator<Map.Entry<K, V>> iterator() {861 return new MapNIterator();862 }863 };864 }865 // returns index at which the probe key is present; or if absent,866 // (-i - 1) where i is location where element should be inserted.867 // Callers are relying on this method to perform an implicit nullcheck868 // of pk.869 private int probe(Object pk) {870 int idx = Math.floorMod(pk.hashCode(), table.length >> 1) << 1;871 while (true) {872 @SuppressWarnings("unchecked")873 K ek = (K) table[idx];874 if (ek == null) {875 return -idx - 1;876 } else if (pk.equals(ek)) {877 return idx;878 } else if ((idx += 2) == table.length) {879 idx = 0;880 }881 }882 }883 private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {...

Full Screen

Full Screen

probe

Using AI Code Generation

copy

Full Screen

1import static org.assertj.core.api.Assertions.assertThat;2import static org.assertj.core.test.jdk11.ImmutableCollections.*;3import java.util.List;4import java.util.Map;5import java.util.Set;6import org.junit.jupiter.api.Test;7public class ImmutableCollectionsTest {8 public void should_create_immutable_list() {9 List<String> immutableList = ImmutableList.of("one", "two", "three");10 assertThat(immutableList).containsExactly("one", "two", "three");11 assertThat(immutableList).isInstanceOf(List.class);12 assertThat(immutableList).isInstanceOf(ImmutableList.class);13 }14 public void should_create_immutable_set() {15 Set<String> immutableSet = ImmutableSet.of("one", "two", "three");16 assertThat(immutableSet).containsExactlyInAnyOrder("one", "two", "three");17 assertThat(immutableSet).isInstanceOf(Set.class);18 assertThat(immutableSet).isInstanceOf(ImmutableSet.class);19 }20 public void should_create_immutable_map() {21 Map<String, String> immutableMap = ImmutableMap.of("one", "ONE", "two", "TWO", "three", "THREE");22 assertThat(immutableMap).containsExactlyInAnyOrderEntriesOf(Map.of("one", "ONE", "two", "TWO", "three", "THREE"));23 assertThat(immutableMap).isInstanceOf(Map.class);24 assertThat(immutableMap).isInstanceOf(ImmutableMap.class);25 }26}27I have tried both the following import statements:28import static org.assertj.core.test.jdk11.ImmutableCollections.*;29import static org.assertj.core.api.Assertions.assertThat;30import static org.assertj.core.test.jdk11.ImmutableCollections.*;

Full Screen

Full Screen

probe

Using AI Code Generation

copy

Full Screen

1assertThat(ImmutableCollections.probe()).isTrue();2assertThat(ImmutableCollections.probe()).isTrue();3assertThat(ImmutableCollections.probe()).isTrue();4assertThat(ImmutableCollections.probe()).isTrue();5assertThat(ImmutableCollections.probe()).isTrue();6assertThat(ImmutableCollections.probe()).isTrue();7assertThat(ImmutableCollections.probe()).isTrue();8assertThat(ImmutableCollections.probe()).isTrue();9assertThat(ImmutableCollections.probe()).isTrue();10assertThat(ImmutableCollections.probe()).isTrue();11assertThat(ImmutableCollections.probe()).isTrue();12assertThat(ImmutableCollections.probe()).isTrue();13assertThat(ImmutableCollections.probe()).isTrue();

Full Screen

Full Screen

probe

Using AI Code Generation

copy

Full Screen

1import org.assertj.core.test.jdk11.ImmutableCollections;2import java.util.List;3import java.util.Set;4import java.util.Map;5import java.util.stream.Collectors;6import java.util.stream.Stream;7import org.assertj.core.api.Assertions;8import org.assertj.core.api.ListAssert;9import org.assertj.core.api.MapAssert;10import org.assertj.core.api.SetAssert;11import org.assertj.core.api.SoftAssertions;12import org.assertj.core.data.Index;13import org.assertj.core.data.MapEntry;14import org.assertj.core.util.Lists;15import org.assertj.core.util.Maps;16import org.assertj.core.util.Sets;17import org.junit.jupiter.api.Test;18import static org.assertj.core.api.Assertions.assertThat;19import static org.assertj.core.api.Assertions.assertThatExceptionOfType;20import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;21import static org.assertj.core.api.Assertions.assertThatNullPointerException;22import static org.assertj.core.api.Assertions.assertThatThrownBy;23import static org.assertj.core.api.BDDAssertions.then;24import static org.assertj.core.api.BDDAssertions.thenIllegalArgumentException;25import static org.assertj.core.api.BDDAssertions.thenNullPointerException;

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful