From 250e440ad16e2da6cb777485f8f4b25de5764273 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Spasic=CC=81?= Date: Tue, 15 Sep 2020 01:01:47 +0200 Subject: [PATCH] Removed last set of classes --- src/main/java/jodd/util/ArraysUtil.java | 20 +- src/main/java/jodd/util/ClassUtil.java | 2 +- src/main/java/jodd/util/MultiComparator.java | 56 ---- src/main/java/jodd/util/StringBand.java | 294 ------------------ src/main/java/jodd/util/StringUtil.java | 2 +- .../java/jodd/util/ThreadFactoryBuilder.java | 10 +- .../java/jodd/util/ClassLoaderUtilTest.java | 2 +- src/test/java/jodd/util/ClassUtilTest.java | 21 +- .../java/jodd/util/MultiComparatorTest.java | 91 ------ src/test/java/jodd/util/StringBandTest.java | 89 ------ src/test/java/jodd/util/fixtures/StringB.java | 12 + 11 files changed, 38 insertions(+), 561 deletions(-) delete mode 100644 src/main/java/jodd/util/MultiComparator.java delete mode 100644 src/main/java/jodd/util/StringBand.java delete mode 100644 src/test/java/jodd/util/MultiComparatorTest.java delete mode 100644 src/test/java/jodd/util/StringBandTest.java create mode 100644 src/test/java/jodd/util/fixtures/StringB.java diff --git a/src/main/java/jodd/util/ArraysUtil.java b/src/main/java/jodd/util/ArraysUtil.java index febcd27..75e04f3 100644 --- a/src/main/java/jodd/util/ArraysUtil.java +++ b/src/main/java/jodd/util/ArraysUtil.java @@ -2063,7 +2063,7 @@ public static String toString(final Object[] array) { if (array.length == 0) { return StringPool.EMPTY; } - final StringBand sb = new StringBand((array.length << 1) - 1); + final StringBuilder sb = new StringBuilder(); for (int i = 0; i < array.length; i++) { if (i != 0) { sb.append(StringPool.COMMA); @@ -2084,7 +2084,7 @@ public static String toString(final String[] array) { if (array.length == 0) { return StringPool.EMPTY; } - final StringBand sb = new StringBand((array.length << 1) - 1); + final StringBuilder sb = new StringBuilder(); for (int i = 0; i < array.length; i++) { if (i != 0) { sb.append(StringPool.COMMA); @@ -2105,7 +2105,7 @@ public static String toString(final byte[] array) { if (array.length == 0) { return StringPool.EMPTY; } - final StringBand sb = new StringBand((array.length << 1) - 1); + final StringBuilder sb = new StringBuilder(); for (int i = 0; i < array.length; i++) { if (i != 0) { sb.append(StringPool.COMMA); @@ -2126,7 +2126,7 @@ public static String toString(final char[] array) { if (array.length == 0) { return StringPool.EMPTY; } - final StringBand sb = new StringBand((array.length << 1) - 1); + final StringBuilder sb = new StringBuilder(); for (int i = 0; i < array.length; i++) { if (i != 0) { sb.append(StringPool.COMMA); @@ -2147,7 +2147,7 @@ public static String toString(final short[] array) { if (array.length == 0) { return StringPool.EMPTY; } - final StringBand sb = new StringBand((array.length << 1) - 1); + final StringBuilder sb = new StringBuilder(); for (int i = 0; i < array.length; i++) { if (i != 0) { sb.append(StringPool.COMMA); @@ -2168,7 +2168,7 @@ public static String toString(final int[] array) { if (array.length == 0) { return StringPool.EMPTY; } - final StringBand sb = new StringBand((array.length << 1) - 1); + final StringBuilder sb = new StringBuilder(); for (int i = 0; i < array.length; i++) { if (i != 0) { sb.append(StringPool.COMMA); @@ -2189,7 +2189,7 @@ public static String toString(final long[] array) { if (array.length == 0) { return StringPool.EMPTY; } - final StringBand sb = new StringBand((array.length << 1) - 1); + final StringBuilder sb = new StringBuilder(); for (int i = 0; i < array.length; i++) { if (i != 0) { sb.append(StringPool.COMMA); @@ -2210,7 +2210,7 @@ public static String toString(final float[] array) { if (array.length == 0) { return StringPool.EMPTY; } - final StringBand sb = new StringBand((array.length << 1) - 1); + final StringBuilder sb = new StringBuilder(); for (int i = 0; i < array.length; i++) { if (i != 0) { sb.append(StringPool.COMMA); @@ -2231,7 +2231,7 @@ public static String toString(final double[] array) { if (array.length == 0) { return StringPool.EMPTY; } - final StringBand sb = new StringBand((array.length << 1) - 1); + final StringBuilder sb = new StringBuilder(); for (int i = 0; i < array.length; i++) { if (i != 0) { sb.append(StringPool.COMMA); @@ -2252,7 +2252,7 @@ public static String toString(final boolean[] array) { if (array.length == 0) { return StringPool.EMPTY; } - final StringBand sb = new StringBand((array.length << 1) - 1); + final StringBuilder sb = new StringBuilder(); for (int i = 0; i < array.length; i++) { if (i != 0) { sb.append(StringPool.COMMA); diff --git a/src/main/java/jodd/util/ClassUtil.java b/src/main/java/jodd/util/ClassUtil.java index 2a8539b..872a42f 100755 --- a/src/main/java/jodd/util/ClassUtil.java +++ b/src/main/java/jodd/util/ClassUtil.java @@ -1333,7 +1333,7 @@ public static String getShortClassName(final Class clazz) { } public static String getShortClassName(final Class clazz, final int shortUpTo) { final String[] chunks = StringUtil.splitc(clazz.getName(), '.'); - final StringBand stringBand = new StringBand(chunks.length); + final StringBuilder stringBand = new StringBuilder(); int ndx = chunks.length - shortUpTo; if (ndx < 0) { ndx = 0; diff --git a/src/main/java/jodd/util/MultiComparator.java b/src/main/java/jodd/util/MultiComparator.java deleted file mode 100644 index 626b85d..0000000 --- a/src/main/java/jodd/util/MultiComparator.java +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) 2003-present, Jodd Team (http://jodd.org) -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// 1. Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the distribution. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. - -package jodd.util; - -import java.io.Serializable; -import java.util.Comparator; -import java.util.List; - -/** - * Multiple comparators compares using list of comparators. - */ -public class MultiComparator implements Comparator, Serializable { - protected final List> comparators; - - public MultiComparator(final List> comparators) { - this.comparators = comparators; - } - - /** - * Compares two objects starting with first comparator; if they are equals - * proceeds to the next comparator and so on. - */ - @Override - public int compare(final T o1, final T o2) { - for (Comparator comparator : comparators) { - int result = comparator.compare(o1, o2); - if (result != 0) { - return result; - } - } - return 0; - } -} diff --git a/src/main/java/jodd/util/StringBand.java b/src/main/java/jodd/util/StringBand.java deleted file mode 100644 index 745db25..0000000 --- a/src/main/java/jodd/util/StringBand.java +++ /dev/null @@ -1,294 +0,0 @@ -// Copyright (c) 2003-present, Jodd Team (http://jodd.org) -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// 1. Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the distribution. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. - -package jodd.util; - -/** - * StringBand is a faster alternative to StringBuilder. - * Instead of adding strings, they are stored in an internal array. Only at the - * end of concatenation, when toString() is invoked, strings are - * joined together in a very fast manner. - *

- * To make StringBand even faster, predict the number of joined - * strings (and not the final string size)! - */ -public class StringBand { - - private static final int DEFAULT_ARRAY_CAPACITY = 16; - - private String[] array; - private int index; - private int length; - - /** - * Creates an empty StringBand. - */ - public StringBand() { - array = new String[DEFAULT_ARRAY_CAPACITY]; - } - - /** - * Creates an empty StringBand with provided capacity. - * Capacity refers to internal string array (i.e. number of - * joins) and not the total string size. - */ - public StringBand(final int initialCapacity) { - array = new String[initialCapacity]; - } - - /** - * Creates StringBand with provided content. - */ - public StringBand(final String s) { - this(); - array[0] = s; - index = 1; - length = s.length(); - } - - public StringBand(final Object o) { - this(String.valueOf(o)); - } - - // ---------------------------------------------------------------- append - - /** - * Appends boolean value. - */ - public StringBand append(final boolean b) { - return append(b ? StringPool.TRUE : StringPool.FALSE); - } - - /** - * Appends double value. - */ - public StringBand append(final double d) { - return append(Double.toString(d)); - } - - /** - * Appends float value. - */ - public StringBand append(final float f) { - return append(Float.toString(f)); - } - - /** - * Appends int value. - */ - public StringBand append(final int i) { - return append(Integer.toString(i)); - } - - /** - * Appends long value. - */ - public StringBand append(final long l) { - return append(Long.toString(l)); - } - - /** - * Appends short value. - */ - public StringBand append(final short s) { - return append(Short.toString(s)); - } - - /** - * Appends a character. This is not efficient - * as in StringBuilder, since new string is created. - */ - public StringBand append(final char c) { - return append(String.valueOf(c)); - } - - /** - * Appends byte value. - */ - public StringBand append(final byte b) { - return append(Byte.toString(b)); - } - - /** - * Appends string representation of an object. - * If null, the 'null' string - * will be appended. - */ - public StringBand append(final Object obj) { - return append(String.valueOf(obj)); - } - - /** - * Appends a string. - */ - public StringBand append(String s) { - if (s == null) { - s = StringPool.NULL; - } - - if (index >= array.length) { - expandCapacity(); - } - - array[index++] = s; - length += s.length(); - - return this; - } - - // ---------------------------------------------------------------- size - - /** - * Returns array capacity. - */ - public int capacity() { - return array.length; - } - - /** - * Returns total string length. - */ - public int length() { - return length; - } - - /** - * Returns current index of string array. - */ - public int index() { - return index; - } - - /** - * Specifies the new index. - */ - public void setIndex(final int newIndex) { - if (newIndex < 0) { - throw new ArrayIndexOutOfBoundsException(newIndex); - } - - if (newIndex > array.length) { - String[] newArray = new String[newIndex]; - System.arraycopy(array, 0, newArray, 0, index); - array = newArray; - } - - if (newIndex > index) { - for (int i = index; i < newIndex; i++) { - array[i] = StringPool.EMPTY; - } - } else if (newIndex < index) { - for (int i = newIndex; i < index; i++) { - array[i] = null; - } - } - - index = newIndex; - length = calculateLength(); - } - - // ---------------------------------------------------------------- values - - /** - * Returns char at given position. - * This method is not fast as it calculates - * the right string array element and the offset! - */ - public char charAt(final int pos) { - int len = 0; - for (int i = 0; i < index; i++) { - int newlen = len + array[i].length(); - if (pos < newlen) { - return array[i].charAt(pos - len); - } - len = newlen; - } - throw new IllegalArgumentException("Invalid char index"); - } - - /** - * Returns string at given position. - */ - public String stringAt(final int index) { - if (index >= this.index) { - throw new ArrayIndexOutOfBoundsException(); - } - return array[index]; - } - - /** - * Joins together all strings into one. - */ - @Override - public String toString() { - - // special cases - switch (index) { - case 0: - return StringPool.EMPTY; - case 1: - return array[0]; - case 2: - return array[0] + array[1]; - } - - // join strings - char[] destination = new char[length]; - int start = 0; - for (int i = 0; i < index; i++) { - String s = array[i]; - - int len = s.length(); - s.getChars(0, len, destination, start); - - start += len; - } - - return new String(destination); - } - - // ---------------------------------------------------------------- utils - - /** - * Expands internal string array by multiplying its size by 2. - */ - protected void expandCapacity() { - String[] newArray = new String[array.length << 1]; - System.arraycopy(array, 0, newArray, 0, index); - array = newArray; - } - - /** - * Calculates string length. - */ - protected int calculateLength() { - int len = 0; - for (int i = 0; i < index; i++) { - len += array[i].length(); - } - return len; - } - -} diff --git a/src/main/java/jodd/util/StringUtil.java b/src/main/java/jodd/util/StringUtil.java index ec46b25..166d99f 100644 --- a/src/main/java/jodd/util/StringUtil.java +++ b/src/main/java/jodd/util/StringUtil.java @@ -2521,7 +2521,7 @@ public static String insert(final String src, final String insert, int offset) { * Creates a new string that contains the provided string a number of times. */ public static String repeat(final String source, int count) { - final StringBand result = new StringBand(count); + final StringBuilder result = new StringBuilder(source.length() * count); while (count > 0) { result.append(source); count--; diff --git a/src/main/java/jodd/util/ThreadFactoryBuilder.java b/src/main/java/jodd/util/ThreadFactoryBuilder.java index 09e3175..38d7384 100644 --- a/src/main/java/jodd/util/ThreadFactoryBuilder.java +++ b/src/main/java/jodd/util/ThreadFactoryBuilder.java @@ -52,7 +52,7 @@ public static ThreadFactoryBuilder create() { * Sets the printf-compatible naming format for threads. * Use {@code %d} to replace it with the thread number. */ - public ThreadFactoryBuilder setNameFormat(final String nameFormat) { + public ThreadFactoryBuilder withNameFormat(final String nameFormat) { this.nameFormat = nameFormat; return this; } @@ -60,7 +60,7 @@ public ThreadFactoryBuilder setNameFormat(final String nameFormat) { /** * Sets if new threads will be daemon. */ - public ThreadFactoryBuilder setDaemon(final boolean daemon) { + public ThreadFactoryBuilder withDaemon(final boolean daemon) { this.daemonThread = daemon; return this; } @@ -68,7 +68,7 @@ public ThreadFactoryBuilder setDaemon(final boolean daemon) { /** * Sets the threads priority. */ - public ThreadFactoryBuilder setPriority(final int priority) { + public ThreadFactoryBuilder withPriority(final int priority) { this.priority = priority; return this; } @@ -76,7 +76,7 @@ public ThreadFactoryBuilder setPriority(final int priority) { /** * Sets the {@code UncaughtExceptionHandler} for new threads created. */ - public ThreadFactoryBuilder setUncaughtExceptionHandler( + public ThreadFactoryBuilder withUncaughtExceptionHandler( final Thread.UncaughtExceptionHandler uncaughtExceptionHandler) { this.uncaughtExceptionHandler = Objects.requireNonNull(uncaughtExceptionHandler); @@ -87,7 +87,7 @@ public ThreadFactoryBuilder setUncaughtExceptionHandler( * Sets the backing {@code ThreadFactory} for new threads. Threads * will be created by invoking {@code newThread(Runnable} on this backing factory. */ - public ThreadFactoryBuilder setBackingThreadFactory(final ThreadFactory backingThreadFactory) { + public ThreadFactoryBuilder withBackingThreadFactory(final ThreadFactory backingThreadFactory) { this.backingThreadFactory = Objects.requireNonNull(backingThreadFactory); return this; } diff --git a/src/test/java/jodd/util/ClassLoaderUtilTest.java b/src/test/java/jodd/util/ClassLoaderUtilTest.java index e1cb63d..e73e1a4 100644 --- a/src/test/java/jodd/util/ClassLoaderUtilTest.java +++ b/src/test/java/jodd/util/ClassLoaderUtilTest.java @@ -121,7 +121,7 @@ void testLoadClass() throws Exception { // special case - final ClassLoaderStrategy.DefaultClassLoaderStrategy defaultClassLoaderStrategy = (ClassLoaderStrategy.DefaultClassLoaderStrategy) ClassLoaderStrategy.get(); + final ClassLoaderStrategy.DefaultClassLoaderStrategy defaultClassLoaderStrategy = (ClassLoaderStrategy.DefaultClassLoaderStrategy) ClassLoaderUtil.classLoaderStrategy; defaultClassLoaderStrategy.setLoadArrayClassByComponentTypes(true); diff --git a/src/test/java/jodd/util/ClassUtilTest.java b/src/test/java/jodd/util/ClassUtilTest.java index 0b05b4b..5296ff8 100755 --- a/src/test/java/jodd/util/ClassUtilTest.java +++ b/src/test/java/jodd/util/ClassUtilTest.java @@ -29,6 +29,7 @@ import jodd.introspector.ClassIntrospector; import jodd.introspector.MethodDescriptor; import jodd.test.DisabledOnJava; +import jodd.util.fixtures.StringB; import jodd.util.fixtures.subclass.IBase; import jodd.util.fixtures.subclass.IExtra; import jodd.util.fixtures.subclass.IOne; @@ -873,7 +874,7 @@ void notUserDefinedMethod() throws Exception { @Test void userDefinedMethod() throws Exception { - final Method method = StringBand.class.getMethod("toString"); + final Method method = StringB.class.getMethod("toString"); final boolean actual = ClassUtil.isUserDefinedMethod(method); @@ -883,7 +884,7 @@ void userDefinedMethod() throws Exception { @Test void customObjectButMethodFromObject() throws Exception { - final Method method = StringBand.class.getMethod("hashCode"); + final Method method = StringB.class.getMethod("hashCode"); final boolean actual = ClassUtil.isUserDefinedMethod(method); @@ -942,30 +943,24 @@ class IsObjectMethod { void methodFromObject() throws Exception { final Method method = Object.class.getMethod("hashCode"); - final boolean actual = ClassUtil.isObjectMethod(method); - // asserts - assertEquals(true, actual); + assertTrue(ClassUtil.isObjectMethod(method)); } @Test void userDefinedMethod() throws Exception { - final Method method = StringBand.class.getMethod("toString"); - - final boolean actual = ClassUtil.isObjectMethod(method); + final Method method = StringB.class.getMethod("toString"); // asserts - assertEquals(false, actual); + assertFalse(ClassUtil.isObjectMethod(method)); } @Test void customObjectButMethodFromObject() throws Exception { - final Method method = StringBand.class.getMethod("hashCode"); - - final boolean actual = ClassUtil.isObjectMethod(method); + final Method method = StringB.class.getMethod("hashCode"); // asserts - assertEquals(true, actual); + assertTrue(ClassUtil.isObjectMethod(method)); } } diff --git a/src/test/java/jodd/util/MultiComparatorTest.java b/src/test/java/jodd/util/MultiComparatorTest.java deleted file mode 100644 index 559b715..0000000 --- a/src/test/java/jodd/util/MultiComparatorTest.java +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright (c) 2003-present, Jodd Team (http://jodd.org) -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// 1. Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the distribution. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. - -package jodd.util; - -import org.junit.jupiter.api.Test; - -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; -import java.util.stream.Stream; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; - -/** - * Tests for {@link MultiComparator}. - */ -class MultiComparatorTest { - - @Test - void testCompare_with_null_list() { - // asserts - assertThrows(NullPointerException.class, () -> new MultiComparator<>(null).compare(new Object(), new Object())); - } - - @Test - void testCompare_with_null_entry_in_list() { - - final List> comparators = new ArrayList<>(); - comparators.add((o1, o2) -> 0); - comparators.add(null); - - // asserts - assertThrows(NullPointerException.class, () -> new MultiComparator<>(comparators).compare(new Object(), new Object())); - } - - @Test - void testCompare_with_empty_in_list() { - - final List> comparators = new ArrayList<>(); - - // asserts - assertEquals(0, new MultiComparator<>(comparators).compare(new Object(), new Object())); - } - - @Test - void testCompare_with_expected_negative_value() { - - final List> comparators = new ArrayList<>(); - Stream.of(0, 0, 0).forEach(c -> comparators.add((o1, o2) -> c)); - comparators.add((o1, o2) -> -77); - - // asserts - assertEquals(-77, new MultiComparator<>(comparators).compare(new Object(), new Object())); - } - - @Test - void testCompare_with_expected_positive_value() { - - final List> comparators = new ArrayList<>(); - Stream.of(0, 0, 0).forEach(c -> comparators.add((o1, o2) -> c)); - comparators.add((o1, o2) -> 23); - - // asserts - assertEquals(23, new MultiComparator<>(comparators).compare(new Object(), new Object())); - } - -} \ No newline at end of file diff --git a/src/test/java/jodd/util/StringBandTest.java b/src/test/java/jodd/util/StringBandTest.java deleted file mode 100644 index c29cb36..0000000 --- a/src/test/java/jodd/util/StringBandTest.java +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright (c) 2003-present, Jodd Team (http://jodd.org) -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// 1. Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the distribution. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. - -package jodd.util; - -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -class StringBandTest { - - @Test - void testSbands() { - StringBand sb = new StringBand(5); - - assertEquals("", sb.toString()); - - assertEquals(5, sb.capacity()); - assertEquals(0, sb.index()); - assertEquals(0, sb.length()); - - sb.append("xxx"); - assertEquals(5, sb.capacity()); - assertEquals(1, sb.index()); - assertEquals(3, sb.length()); - assertEquals('x', sb.charAt(0)); - assertEquals('x', sb.charAt(1)); - assertEquals('x', sb.charAt(2)); - - sb.append("zzz"); - assertEquals(5, sb.capacity()); - assertEquals(2, sb.index()); - assertEquals(6, sb.length()); - - assertEquals("xxxzzz", sb.toString()); - assertEquals("zzz", sb.stringAt(1)); - assertEquals('x', sb.charAt(0)); - assertEquals('x', sb.charAt(1)); - assertEquals('x', sb.charAt(2)); - assertEquals('z', sb.charAt(3)); - assertEquals('z', sb.charAt(4)); - assertEquals('z', sb.charAt(5)); - - sb.append("www"); - assertEquals(5, sb.capacity()); - assertEquals(3, sb.index()); - assertEquals(9, sb.length()); - - assertEquals("xxxzzzwww", sb.toString()); - assertEquals("www", sb.stringAt(2)); - assertEquals('x', sb.charAt(2)); - assertEquals('z', sb.charAt(3)); - assertEquals('z', sb.charAt(5)); - assertEquals('w', sb.charAt(6)); - assertEquals('w', sb.charAt(8)); - - sb.setIndex(1); - - assertEquals(5, sb.capacity()); - assertEquals(1, sb.index()); - assertEquals(3, sb.length()); - - assertEquals("xxx", sb.toString()); - assertEquals('x', sb.charAt(2)); - - } -} diff --git a/src/test/java/jodd/util/fixtures/StringB.java b/src/test/java/jodd/util/fixtures/StringB.java new file mode 100644 index 0000000..d1cca86 --- /dev/null +++ b/src/test/java/jodd/util/fixtures/StringB.java @@ -0,0 +1,12 @@ +package jodd.util.fixtures; + +public class StringB { + private final String s = "name"; + + @Override + public String toString() { + return "StringB{" + + "s='" + s + '\'' + + '}'; + } +}