@Nonnull public Object[] toArray() { int size = size(); Object[] result = new Object[size]; if (size == 0) return result; int resultIndex = 0; int mc = modCount(); Object[] tab = table; for (int i = tab.length - 2; i >= 0; i -= 2) { E key; // noinspection unchecked if ((key = (E) (E) tab[i]) != FREE) { result[resultIndex++] = key; } } if (mc != modCount()) throw new java.util.ConcurrentModificationException(); return result; }
@SuppressWarnings("unchecked") @Nonnull public <T> T[] toArray(@Nonnull T[] a) { int size = size(); if (a.length < size) { Class<?> elementType = a.getClass().getComponentType(); a = (T[]) java.lang.reflect.Array.newInstance(elementType, size); } if (size == 0) { if (a.length > 0) a[0] = null; return a; } int resultIndex = 0; int mc = modCount(); Object[] tab = table; for (int i = tab.length - 2; i >= 0; i -= 2) { E key; // noinspection unchecked if ((key = (E) (E) tab[i]) != FREE) { a[resultIndex++] = (T) key; } } if (mc != modCount()) throw new java.util.ConcurrentModificationException(); if (a.length > resultIndex) a[resultIndex] = null; return a; }
@SuppressWarnings("unchecked") @Nonnull public <T> T[] toArray(@Nonnull T[] a) { int size = size(); if (a.length < size) { Class<?> elementType = a.getClass().getComponentType(); a = (T[]) java.lang.reflect.Array.newInstance(elementType, size); } if (size == 0) { if (a.length > 0) a[0] = null; return a; } int resultIndex = 0; int mc = modCount(); Object[] tab = table; for (int i = tab.length - 2; i >= 0; i -= 2) { E key; // noinspection unchecked if ((key = (E) (E) tab[i]) != FREE) { a[resultIndex++] = (T) key; } } if (mc != modCount()) throw new java.util.ConcurrentModificationException(); if (a.length > resultIndex) a[resultIndex] = null; return a; }
@Nonnull public Object[] toArray() { int size = size(); Object[] result = new Object[size]; if (size == 0) return result; int resultIndex = 0; int mc = modCount(); Object[] tab = table; for (int i = tab.length - 2; i >= 0; i -= 2) { E key; // noinspection unchecked if ((key = (E) (E) tab[i]) != FREE) { result[resultIndex++] = key; } } if (mc != modCount()) throw new java.util.ConcurrentModificationException(); return result; }
public String setToString() { if (isEmpty()) return "[]"; StringBuilder sb = new StringBuilder(); int elementCount = 0; int mc = modCount(); Object[] tab = table; for (int i = tab.length - 2; i >= 0; i -= 2) { E key; // noinspection unchecked if ((key = (E) (E) tab[i]) != FREE) { sb.append(' ').append(key != this ? key : "(this Collection)").append(','); if (++elementCount == 8) { int expectedLength = sb.length() * (size() / 8); sb.ensureCapacity(expectedLength + (expectedLength / 2)); } } } if (mc != modCount()) throw new java.util.ConcurrentModificationException(); sb.setCharAt(0, '['); sb.setCharAt(sb.length() - 1, ']'); return sb.toString(); }
public String setToString() { if (isEmpty()) return "[]"; StringBuilder sb = new StringBuilder(); int elementCount = 0; int mc = modCount(); Object[] tab = table; for (int i = tab.length - 2; i >= 0; i -= 2) { E key; // noinspection unchecked if ((key = (E) (E) tab[i]) != FREE) { sb.append(' ').append(key != this ? key : "(this Collection)").append(','); if (++elementCount == 8) { int expectedLength = sb.length() * (size() / 8); sb.ensureCapacity(expectedLength + (expectedLength / 2)); } } } if (mc != modCount()) throw new java.util.ConcurrentModificationException(); sb.setCharAt(0, '['); sb.setCharAt(sb.length() - 1, ']'); return sb.toString(); }