mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-05 19:42:36 +02:00
GT-3354: Removing some Guava
This commit is contained in:
parent
3a6c3312fe
commit
2a64cf2a77
20 changed files with 91 additions and 155 deletions
|
@ -18,11 +18,14 @@ package ghidra.util;
|
|||
import java.math.BigInteger;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.stream.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.apache.commons.collections4.IteratorUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import util.CollectionUtils;
|
||||
|
||||
public final class NumericUtilities {
|
||||
public static final BigInteger MAX_UNSIGNED_LONG = new BigInteger("ffffffffffffffff", 16);
|
||||
public static final BigInteger MAX_SIGNED_LONG = new BigInteger("7fffffffffffffff", 16);
|
||||
|
@ -694,9 +697,7 @@ public final class NumericUtilities {
|
|||
* @return hex string representation
|
||||
*/
|
||||
public static String convertBytesToString(Iterable<Byte> bytes, String delimiter) {
|
||||
|
||||
Stream<Byte> stream = StreamSupport.stream(bytes.spliterator(), false);
|
||||
return convertBytesToString(stream, delimiter);
|
||||
return convertBytesToString(CollectionUtils.asStream(bytes), delimiter);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -24,24 +24,18 @@ import org.apache.commons.collections4.IteratorUtils;
|
|||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.google.common.collect.*;
|
||||
|
||||
/**
|
||||
* A collection of utility methods that prevent you from having to do unsafe casts of
|
||||
* {@link Collection} classes due to runtime type erasure.
|
||||
*
|
||||
* <P>Be sure to check Guava and Apache collection utils before using this class, as they are
|
||||
* standard utilities and often more efficient.
|
||||
* <P>Be sure to check Apache collection utils before using this class, as it's a
|
||||
* standard utility and often more efficient.
|
||||
*
|
||||
* <P>Some examples:
|
||||
* <OL>
|
||||
* <LI>{@link Iterators}</LI>
|
||||
* <LI>{@link Iterables}</LI>
|
||||
* <LI>{@link org.apache.commons.collections4.CollectionUtils}</LI>
|
||||
* <LI>{@link IterableUtils}</LI>
|
||||
* <LI>{@link IteratorUtils}</LI>
|
||||
* <LI>{@link Maps}</LI>
|
||||
* <LI>{@link Sets}</LI>
|
||||
* <LI>{@link StringUtils#join(Iterable, char)} - for pretty printing collections with newlines</LI>
|
||||
* <LI><code>Apache CollectionUtils.collect(Collection, Transformer)</code> - to turn a
|
||||
* collection in to collection of strings when the default <code>toString()</code> is lacking</LI>
|
||||
|
@ -404,21 +398,6 @@ public class CollectionUtils {
|
|||
return () -> iterator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Combines all collections passed-in, using {@link Iterables}, into a pass-through
|
||||
* (not creating a new collection) Iterable.
|
||||
*
|
||||
* <P>This is just a convenience method for {@link Iterables#concat(Iterable)}
|
||||
*
|
||||
* @param iterables the iterables to combine
|
||||
* @return the iterable
|
||||
*/
|
||||
@SafeVarargs
|
||||
public static <T> Iterable<T> asIterable(Iterable<T>... iterables) {
|
||||
Iterable<T> concat = Iterables.concat(iterables);
|
||||
return concat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns the given iterator into a stream
|
||||
*
|
||||
|
@ -430,16 +409,15 @@ public class CollectionUtils {
|
|||
}
|
||||
|
||||
/**
|
||||
* Combines all iterables passed-in, using {@link Iterables}, into a pass-through
|
||||
* (not creating a new collection) Stream.
|
||||
* Combines all iterables passed-in into a pass-through (not creating a new collection) Stream.
|
||||
*
|
||||
* @param iterables the iterables to combine
|
||||
* @return the stream
|
||||
*/
|
||||
@SafeVarargs
|
||||
public static <T> Stream<T> asStream(Iterable<T>... iterables) {
|
||||
Iterable<T> concat = Iterables.concat(iterables);
|
||||
Stream<T> s = StreamSupport.stream(concat.spliterator(), false);
|
||||
Stream<T> s = Stream.of(iterables)
|
||||
.flatMap(e -> StreamSupport.stream(e.spliterator(), false));
|
||||
return s;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
*/
|
||||
package util;
|
||||
|
||||
import static org.hamcrest.collection.IsIn.isOneOf;
|
||||
import static org.hamcrest.collection.IsIn.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.*;
|
||||
|
@ -225,21 +225,6 @@ public class CollectionUtilsTest {
|
|||
assertEquals("One", iterator.next());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAsIterable_Collections() {
|
||||
|
||||
List<String> original = Arrays.asList("One", "Two", "Three", "Four");
|
||||
Collection<String> a = Arrays.asList(original.get(0), original.get(1));
|
||||
Collection<String> b = Arrays.asList(original.get(2));
|
||||
Collection<String> c = Collections.emptyList();
|
||||
Collection<String> d = Arrays.asList(original.get(3));
|
||||
Iterable<String> iterable = CollectionUtils.asIterable(a, b, c, d);
|
||||
|
||||
List<String> result = new ArrayList<>();
|
||||
iterable.forEach(s -> result.add(s));
|
||||
assertEquals(original, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAsList_UnknownToType() {
|
||||
List<String> list = new ArrayList<>();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue