-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add possibility to use library without Spring framework
- Loading branch information
Showing
6 changed files
with
121 additions
and
28 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
src/main/java/com/github/vbauer/herald/util/CollectionUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.github.vbauer.herald.util; | ||
|
||
import java.util.Collection; | ||
|
||
/** | ||
* @author Vladislav Bauer | ||
*/ | ||
|
||
public final class CollectionUtils { | ||
|
||
private CollectionUtils() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
|
||
public static boolean isEmpty(final Collection entries) { | ||
return size(entries) == 0; | ||
} | ||
|
||
public static boolean isEmpty(final Object... entries) { | ||
return size(entries) == 0; | ||
} | ||
|
||
public static int size(final Collection entries) { | ||
return entries == null ? 0 : entries.size(); | ||
} | ||
|
||
public static int size(final Object... entries) { | ||
return entries == null ? 0 : entries.length; | ||
} | ||
|
||
} |
1 change: 0 additions & 1 deletion
1
src/main/java/com/github/vbauer/herald/util/LogFactoryUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/test/java/com/github/vbauer/herald/util/CollectionUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.github.vbauer.herald.util; | ||
|
||
import com.github.vbauer.herald.core.BasicTest; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
|
||
/** | ||
* @author Vladislav Bauer | ||
*/ | ||
|
||
public class CollectionUtilsTest extends BasicTest { | ||
|
||
@Test | ||
public void testConstructorContract() throws Exception { | ||
checkUtilConstructorContract(CollectionUtils.class); | ||
} | ||
|
||
@Test | ||
public void testSizeArray() { | ||
Assert.assertEquals(0, CollectionUtils.size((Integer[]) null)); | ||
Assert.assertEquals(0, CollectionUtils.size(new Integer[]{})); | ||
Assert.assertEquals(1, CollectionUtils.size(new Integer[]{1})); | ||
} | ||
|
||
@Test | ||
public void testSizeCollection() { | ||
Assert.assertEquals(0, CollectionUtils.size((Collection) null)); | ||
Assert.assertEquals(0, CollectionUtils.size(Collections.emptyList())); | ||
Assert.assertEquals(0, CollectionUtils.size(Collections.emptySet())); | ||
Assert.assertEquals(1, CollectionUtils.size(Collections.singleton(1))); | ||
Assert.assertEquals(1, CollectionUtils.size(Collections.singletonList(1))); | ||
} | ||
|
||
@Test | ||
public void testIsEmptyArray() { | ||
Assert.assertTrue(CollectionUtils.isEmpty((Object[]) null)); | ||
Assert.assertTrue(CollectionUtils.isEmpty()); | ||
Assert.assertFalse(CollectionUtils.isEmpty(new Object())); | ||
Assert.assertFalse(CollectionUtils.isEmpty(new Object(), new Object())); | ||
} | ||
|
||
@Test | ||
public void testIsEmptyCollection() { | ||
Assert.assertTrue(CollectionUtils.isEmpty((Collection) null)); | ||
Assert.assertTrue(CollectionUtils.isEmpty(Collections.emptyList())); | ||
Assert.assertTrue(CollectionUtils.isEmpty(Collections.emptySet())); | ||
Assert.assertFalse(CollectionUtils.isEmpty(Collections.singleton(1))); | ||
Assert.assertFalse(CollectionUtils.isEmpty(Collections.singletonList(1))); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters