Skip to content

Commit

Permalink
refactor: Migrate empty arrays from CollectionUtil to ArrayTypeUtils (d…
Browse files Browse the repository at this point in the history
…eephaven#5748)

Remaining arrays are deprecated to allow gradual removal. All other
methods have been removed, or relocated/rewritten to where they are
used.

Partial deephaven#188
  • Loading branch information
niloc132 authored Jul 15, 2024
1 parent 9776e1d commit 8f54141
Show file tree
Hide file tree
Showing 76 changed files with 375 additions and 600 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
//
package io.deephaven.benchmarking.generator;

import io.deephaven.datastructures.util.CollectionUtil;
import io.deephaven.benchmarking.generator.random.ExtendedRandom;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -50,7 +49,7 @@ public void init(@NotNull ExtendedRandom random) {
enums.add(super.get());
}

enumVals = enums.toArray(CollectionUtil.ZERO_LENGTH_STRING_ARRAY);
enumVals = enums.toArray(String[]::new);
}

public String get() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import io.deephaven.base.verify.Assert;
import io.deephaven.base.verify.Require;
import io.deephaven.datastructures.util.CollectionUtil;
import io.deephaven.io.logger.Logger;
import gnu.trove.set.TIntSet;
import gnu.trove.set.hash.TIntHashSet;
Expand All @@ -15,6 +14,7 @@

import java.io.FileInputStream;
import java.io.IOException;
import java.io.Serializable;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.BitSet;
Expand Down Expand Up @@ -474,7 +474,10 @@ public TIntHashSet getIntHashSetFromProperty(final String propertyName) {
}

public Set<String> getStringSetFromProperty(final String propertyName) {
Set<String> set = CollectionUtil.setFromArray(getProperty(propertyName).split("[, ]"));
String[] data = getProperty(propertyName).split("[, ]");
Require.neqNull(data, "data");
Set<String> set = new LinkedHashSet<>(Arrays.asList(data));
Require.eq(set.size(), "set.size()", data.length, "data.length");
set.remove("");
return set;
}
Expand All @@ -499,13 +502,101 @@ public Set<String> getNameStringSetFromProperty(final String propertyName) {
final String propertyValue = getProperty(propertyName).trim();
switch (propertyValue) {
case "*":
return CollectionUtil.universalSet();
// noinspection unchecked
return (Set<String>) UNIVERSAL_SET;
case "":
return Collections.emptySet();
default:
Set<String> result = CollectionUtil.setFromArray(propertyValue.split("[, ]+"));
result.remove("");
return result;
String[] data = propertyValue.split("[, ]+");
Require.neqNull(data, "data");
Set<String> set = new LinkedHashSet<>(Arrays.asList(data));
Require.eq(set.size(), "set.size()", data.length, "data.length");
set.remove("");
return set;
}
}


/**
* The universal set (immutable). This set is serializable.
*/
@SuppressWarnings("rawtypes")
private static final Set UNIVERSAL_SET = new UniversalSet();

/**
* A set that contains everything. Iteration is not supported - only containment checks.
*/
private static class UniversalSet<T> implements Set<T>, Serializable {

private static final long serialVersionUID = 1L;

private Object readResolve() {
return UNIVERSAL_SET;
}

@Override
public int size() {
throw new UnsupportedOperationException();
}

@Override
public boolean isEmpty() {
return false;
}

@Override
public boolean contains(Object o) {
return true;
}

@Override
public Iterator<T> iterator() {
throw new UnsupportedOperationException();
}

@Override
public Object[] toArray() {
throw new UnsupportedOperationException();
}

@Override
public boolean add(Object o) {
throw new UnsupportedOperationException();
}

@Override
public boolean remove(Object o) {
throw new UnsupportedOperationException();
}

@Override
public boolean containsAll(Collection<?> c) {
return true;
}

@Override
public boolean addAll(Collection<? extends T> c) {
throw new UnsupportedOperationException();
}

@Override
public boolean retainAll(Collection<?> c) {
throw new UnsupportedOperationException();
}

@Override
public boolean removeAll(Collection<?> c) {
throw new UnsupportedOperationException();
}

@Override
public void clear() {
throw new UnsupportedOperationException();
}

@Override
public <T> T[] toArray(T[] a) {
throw new UnsupportedOperationException();
}
}

Expand Down
Loading

0 comments on commit 8f54141

Please sign in to comment.