From 9df126b7d4beab36a651da3f7f1fa0edadd70e1b Mon Sep 17 00:00:00 2001 From: Stefan Fleiter Date: Sun, 29 Sep 2013 23:35:46 +0200 Subject: [PATCH 1/3] remove guava dependency and transform usages of ImmutableSet to EnumSet and Collections.unmodifiableSet --- pom.xml | 4 -- .../slf4jext/ConventionalLevelHierarchy.java | 19 +++++----- .../java/uk/org/lidalia/slf4jext/Level.java | 27 ++++++------- .../uk/org/lidalia/slf4jutils/LevelTests.java | 20 +++++----- .../org/lidalia/slf4jutils/LoggerTests.java | 38 ++++++++----------- 5 files changed, 47 insertions(+), 61 deletions(-) diff --git a/pom.xml b/pom.xml index 982d7a5..7cb488d 100644 --- a/pom.xml +++ b/pom.xml @@ -40,10 +40,6 @@ org.slf4j slf4j-nop - - com.google.guava - guava - ${project.parent.groupId} standard-test-dependencies diff --git a/src/main/java/uk/org/lidalia/slf4jext/ConventionalLevelHierarchy.java b/src/main/java/uk/org/lidalia/slf4jext/ConventionalLevelHierarchy.java index a2a9e9f..c0681b5 100644 --- a/src/main/java/uk/org/lidalia/slf4jext/ConventionalLevelHierarchy.java +++ b/src/main/java/uk/org/lidalia/slf4jext/ConventionalLevelHierarchy.java @@ -1,14 +1,15 @@ package uk.org.lidalia.slf4jext; -import com.google.common.collect.ImmutableSet; - -import static com.google.common.collect.Sets.immutableEnumSet; import static uk.org.lidalia.slf4jext.Level.DEBUG; import static uk.org.lidalia.slf4jext.Level.ERROR; import static uk.org.lidalia.slf4jext.Level.INFO; import static uk.org.lidalia.slf4jext.Level.TRACE; import static uk.org.lidalia.slf4jext.Level.WARN; +import java.util.Collections; +import java.util.EnumSet; +import java.util.Set; + /** * The conventional hierarchical notion of Levels, where info being enabled implies warn and error being enabled, is not a * requirement of the SLF4J API. These constants are a shortcut if you wish to use traditional hierarchical setups. @@ -20,42 +21,42 @@ public final class ConventionalLevelHierarchy { * * An empty set. */ - public static final ImmutableSet OFF_LEVELS = ImmutableSet.of(); + public static final Set OFF_LEVELS = Collections.emptySet(); /** * Levels that would be considered enabled in Log4J/Logback if a Logger was set to ERROR. * * A set containing {@link Level#ERROR}. */ - public static final ImmutableSet ERROR_LEVELS = immutableEnumSet(ERROR); + public static final Set ERROR_LEVELS = Collections.unmodifiableSet(EnumSet.of(ERROR)); /** * Levels that would be considered enabled in Log4J/Logback if a Logger was set to WARN. * * A set containing {@link Level#ERROR} and {@link Level#WARN}. */ - public static final ImmutableSet WARN_LEVELS = immutableEnumSet(ERROR, WARN); + public static final Set WARN_LEVELS = Collections.unmodifiableSet(EnumSet.of(ERROR, WARN)); /** * Levels that would be considered enabled in Log4J/Logback if a Logger was set to INFO. * * A set containing {@link Level#ERROR}, {@link Level#WARN} and {@link Level#INFO}. */ - public static final ImmutableSet INFO_LEVELS = immutableEnumSet(ERROR, WARN, INFO); + public static final Set INFO_LEVELS = Collections.unmodifiableSet(EnumSet.of(ERROR, WARN, INFO)); /** * Levels that would be considered enabled in Log4J/Logback if a Logger was set to DEBUG. * * A set containing {@link Level#ERROR}, {@link Level#WARN}, {@link Level#INFO} and {@link Level#DEBUG}. */ - public static final ImmutableSet DEBUG_LEVELS = immutableEnumSet(ERROR, WARN, INFO, DEBUG); + public static final Set DEBUG_LEVELS = Collections.unmodifiableSet(EnumSet.of(ERROR, WARN, INFO, DEBUG)); /** * Levels that would be considered enabled in Log4J/Logback if a Logger was set to TRACE. * * A set containing {@link Level#ERROR}, {@link Level#WARN}, {@link Level#INFO}, {@link Level#DEBUG} and {@link Level#TRACE}. */ - public static final ImmutableSet TRACE_LEVELS = immutableEnumSet(ERROR, WARN, INFO, DEBUG, TRACE); + public static final Set TRACE_LEVELS = Collections.unmodifiableSet(EnumSet.of(ERROR, WARN, INFO, DEBUG, TRACE)); private ConventionalLevelHierarchy() { throw new UnsupportedOperationException("Not instantiable"); diff --git a/src/main/java/uk/org/lidalia/slf4jext/Level.java b/src/main/java/uk/org/lidalia/slf4jext/Level.java index fc1b51b..d6f91d7 100644 --- a/src/main/java/uk/org/lidalia/slf4jext/Level.java +++ b/src/main/java/uk/org/lidalia/slf4jext/Level.java @@ -1,15 +1,12 @@ package uk.org.lidalia.slf4jext; -import com.google.common.collect.ImmutableSet; +import java.util.Collections; +import java.util.EnumSet; +import java.util.Set; + import org.slf4j.Logger; import org.slf4j.Marker; -import java.util.HashSet; - -import static com.google.common.collect.Sets.immutableEnumSet; -import static com.google.common.collect.Sets.newHashSet; -import static java.util.Arrays.asList; - /** * Enum modelling the logical levels implied by the way SLF4J has the same set of methods * repeated with different names. @@ -321,8 +318,8 @@ void log(final Logger logger, final Marker marker, final String message, final T } }; - private static final ImmutableSet ALL_LEVELS = immutableEnumSet(asList(values())); - private static final ImmutableSet ENABLABLE_LEVELS = makeEnablabeValues(); + private static final Set ALL_LEVELS = Collections.unmodifiableSet(EnumSet.allOf(Level.class)); + private static final Set ENABLABLE_LEVELS = Collections.unmodifiableSet(makeEnablabeValues()); abstract boolean isEnabled(Logger logger); @@ -351,20 +348,20 @@ void log(final Logger logger, final Marker marker, final String message, final T /** * @return an ImmutableSet containing the constants of this enum type */ - public static ImmutableSet valueSet() { + public static Set valueSet() { return ALL_LEVELS; } /** * @return an ImmutableSet containing the constants of this enum type other than OFF */ - public static ImmutableSet enablableValueSet() { + public static Set enablableValueSet() { return ENABLABLE_LEVELS; } - private static ImmutableSet makeEnablabeValues() { - final HashSet levels = newHashSet(values()); - levels.remove(OFF); - return immutableEnumSet(levels); + private static Set makeEnablabeValues() { + EnumSet enabled = EnumSet.allOf(Level.class); + enabled.remove(OFF); + return enabled; } } diff --git a/src/test/java/uk/org/lidalia/slf4jutils/LevelTests.java b/src/test/java/uk/org/lidalia/slf4jutils/LevelTests.java index b70048b..5721d42 100644 --- a/src/test/java/uk/org/lidalia/slf4jutils/LevelTests.java +++ b/src/test/java/uk/org/lidalia/slf4jutils/LevelTests.java @@ -1,22 +1,20 @@ package uk.org.lidalia.slf4jutils; -import java.util.Set; - -import org.junit.Test; - -import com.google.common.collect.ImmutableSet; - -import uk.org.lidalia.slf4jext.Level; - -import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; import static uk.org.lidalia.slf4jext.Level.DEBUG; import static uk.org.lidalia.slf4jext.Level.ERROR; import static uk.org.lidalia.slf4jext.Level.INFO; import static uk.org.lidalia.slf4jext.Level.TRACE; import static uk.org.lidalia.slf4jext.Level.WARN; +import java.util.EnumSet; +import java.util.Set; + +import org.junit.Test; + +import uk.org.lidalia.slf4jext.Level; + public class LevelTests { @Test @@ -32,7 +30,7 @@ public void valueSetIsImmutable() { @Test public void enablableValueSetContains() { - assertThat(Level.enablableValueSet(), is(ImmutableSet.of(ERROR, WARN, INFO, DEBUG, TRACE))); + assertTrue(Level.enablableValueSet().equals(EnumSet.of(ERROR, WARN, INFO, DEBUG, TRACE))); } @Test(expected = UnsupportedOperationException.class) diff --git a/src/test/java/uk/org/lidalia/slf4jutils/LoggerTests.java b/src/test/java/uk/org/lidalia/slf4jutils/LoggerTests.java index 6d3e25c..d38daee 100644 --- a/src/test/java/uk/org/lidalia/slf4jutils/LoggerTests.java +++ b/src/test/java/uk/org/lidalia/slf4jutils/LoggerTests.java @@ -1,25 +1,9 @@ package uk.org.lidalia.slf4jutils; -import com.google.common.base.Function; -import com.google.common.collect.Lists; -import junitparams.JUnitParamsRunner; -import junitparams.Parameters; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.slf4j.Marker; - -import java.lang.reflect.Method; -import java.util.List; - -import uk.org.lidalia.slf4jext.Logger; - -import static java.util.Arrays.asList; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.reset; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; import static org.powermock.api.mockito.PowerMockito.mock; @@ -31,6 +15,17 @@ import static uk.org.lidalia.slf4jext.Level.WARN; import static uk.org.lidalia.test.Values.uniqueValueFor; +import java.lang.reflect.Method; + +import junitparams.JUnitParamsRunner; +import junitparams.Parameters; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.slf4j.Marker; + +import uk.org.lidalia.slf4jext.Logger; + @RunWith(JUnitParamsRunner.class) public class LoggerTests { @@ -585,11 +580,10 @@ public void errorMarkerMessageVarArgs() { private Object[] buildParamsFor(Method loggerMethod) throws Exception { Class[] parameterTypes = loggerMethod.getParameterTypes(); - List params = Lists.transform(asList(parameterTypes), new Function, Object>() { - public Object apply(Class aClass) { - return uniqueValueFor(aClass); - } - }); - return params.toArray(); + Object[] uniqueValues = new Object[parameterTypes.length]; + for (int i = 0; i < uniqueValues.length; i++) { + uniqueValues[i] = uniqueValueFor(parameterTypes[i]); + } + return uniqueValues; } } From b1903b6162417772d2dd14027452cf048b614a4c Mon Sep 17 00:00:00 2001 From: "Vladimir V. Bychkov" Date: Thu, 14 Oct 2021 13:42:32 +0200 Subject: [PATCH 2/3] guava checkNotNull replaced with java Objects.requireNonNull --- src/main/java/uk/org/lidalia/slf4jext/ConvenientLogger.java | 4 ++-- .../java/uk/org/lidalia/slf4jext/DefaultLightLogger.java | 6 +++--- .../java/uk/org/lidalia/slf4jext/DefaultLightestLogger.java | 4 ++-- src/main/java/uk/org/lidalia/slf4jext/DefaultLogger.java | 6 +++--- .../slf4jext/LightestLoggerToLightLoggerAdapter.java | 6 +++--- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main/java/uk/org/lidalia/slf4jext/ConvenientLogger.java b/src/main/java/uk/org/lidalia/slf4jext/ConvenientLogger.java index cc032e7..7bac878 100644 --- a/src/main/java/uk/org/lidalia/slf4jext/ConvenientLogger.java +++ b/src/main/java/uk/org/lidalia/slf4jext/ConvenientLogger.java @@ -2,7 +2,7 @@ import org.slf4j.Marker; -import static com.google.common.base.Preconditions.checkNotNull; +import static java.util.Objects.requireNonNull; import static uk.org.lidalia.slf4jext.Level.DEBUG; import static uk.org.lidalia.slf4jext.Level.ERROR; import static uk.org.lidalia.slf4jext.Level.INFO; @@ -24,7 +24,7 @@ public ConvenientLogger(final LightestLogger decorated) { } public ConvenientLogger(final LightLogger decorated) { - this.decorated = checkNotNull(decorated); + this.decorated = requireNonNull(decorated); } @Override diff --git a/src/main/java/uk/org/lidalia/slf4jext/DefaultLightLogger.java b/src/main/java/uk/org/lidalia/slf4jext/DefaultLightLogger.java index 34b67aa..ff6d9d2 100644 --- a/src/main/java/uk/org/lidalia/slf4jext/DefaultLightLogger.java +++ b/src/main/java/uk/org/lidalia/slf4jext/DefaultLightLogger.java @@ -1,8 +1,8 @@ package uk.org.lidalia.slf4jext; -import org.slf4j.Marker; +import static java.util.Objects.requireNonNull; -import static com.google.common.base.Preconditions.checkNotNull; +import org.slf4j.Marker; public class DefaultLightLogger implements LightLogger { @@ -16,7 +16,7 @@ public class DefaultLightLogger implements LightLogger { * @param decorated the SLF4J {@link org.slf4j.Logger} to which all logging calls will be delegated */ public DefaultLightLogger(final org.slf4j.Logger decorated) { - this.decorated = checkNotNull(decorated); + this.decorated = requireNonNull(decorated); } @Override diff --git a/src/main/java/uk/org/lidalia/slf4jext/DefaultLightestLogger.java b/src/main/java/uk/org/lidalia/slf4jext/DefaultLightestLogger.java index 239bd2a..ac4fd6b 100644 --- a/src/main/java/uk/org/lidalia/slf4jext/DefaultLightestLogger.java +++ b/src/main/java/uk/org/lidalia/slf4jext/DefaultLightestLogger.java @@ -2,14 +2,14 @@ import org.slf4j.Marker; -import static com.google.common.base.Preconditions.checkNotNull; +import static java.util.Objects.requireNonNull; public class DefaultLightestLogger implements LightestLogger { private final org.slf4j.Logger logger; public DefaultLightestLogger(org.slf4j.Logger logger) { - this.logger = checkNotNull(logger); + this.logger = requireNonNull(logger); } @Override diff --git a/src/main/java/uk/org/lidalia/slf4jext/DefaultLogger.java b/src/main/java/uk/org/lidalia/slf4jext/DefaultLogger.java index 4afee52..de2a75e 100644 --- a/src/main/java/uk/org/lidalia/slf4jext/DefaultLogger.java +++ b/src/main/java/uk/org/lidalia/slf4jext/DefaultLogger.java @@ -1,8 +1,8 @@ package uk.org.lidalia.slf4jext; -import org.slf4j.Marker; +import static java.util.Objects.requireNonNull; -import static com.google.common.base.Preconditions.checkNotNull; +import org.slf4j.Marker; /** * A decorator around an SLF4J {@link org.slf4j.Logger} that adds a set of methods called log that take an instance of Level as @@ -29,7 +29,7 @@ public DefaultLogger(final org.slf4j.Logger decorated) { public DefaultLogger(final LightLogger decorated) { super(decorated); - this.decorated = checkNotNull(decorated); + this.decorated = requireNonNull(decorated); } public DefaultLogger(final LightestLogger decorated) { diff --git a/src/main/java/uk/org/lidalia/slf4jext/LightestLoggerToLightLoggerAdapter.java b/src/main/java/uk/org/lidalia/slf4jext/LightestLoggerToLightLoggerAdapter.java index 3540b75..4d4e839 100644 --- a/src/main/java/uk/org/lidalia/slf4jext/LightestLoggerToLightLoggerAdapter.java +++ b/src/main/java/uk/org/lidalia/slf4jext/LightestLoggerToLightLoggerAdapter.java @@ -1,15 +1,15 @@ package uk.org.lidalia.slf4jext; -import org.slf4j.Marker; +import static java.util.Objects.requireNonNull; -import static com.google.common.base.Preconditions.checkNotNull; +import org.slf4j.Marker; public class LightestLoggerToLightLoggerAdapter implements LightLogger { private final LightestLogger decorated; public LightestLoggerToLightLoggerAdapter(LightestLogger decorated) { - this.decorated = checkNotNull(decorated); + this.decorated = requireNonNull(decorated); } @Override From 1b29d8c9376466e65580bf9d6403f14a0ad29d82 Mon Sep 17 00:00:00 2001 From: "Vladimir V. Bychkov" Date: Sat, 30 Oct 2021 13:07:14 +0200 Subject: [PATCH 3/3] Version 1.1.0 released --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index d9ca2d8..659f9e7 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ lidalia-slf4j-ext - 1.1.0-SNAPSHOT + 1.1.0 Lidalia Extensions to SLF4J A wrapper for an SLF4J Logger that includes methods allowing logging to