Skip to content

Commit

Permalink
Disable wildcard imports within the package. (#132)
Browse files Browse the repository at this point in the history
See https://checkstyle.sourceforge.io/apidocs/com/puppycrawl/tools/checkstyle/checks/imports/AvoidStarImportCheck.html for more context

>  Rationale: Importing all classes from a package or static members from a class leads to tight coupling between packages or classes and might lead to problems when a new version of
a library introduces name clashes.

Also ran IDE-based optimize imports. Fixes a missed comment from a previous PR #129 (comment)
  • Loading branch information
baldawar committed Nov 23, 2023
1 parent 90532e3 commit 17860e0
Show file tree
Hide file tree
Showing 25 changed files with 64 additions and 51 deletions.
1 change: 1 addition & 0 deletions config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<module name="OneStatementPerLine"/>
<module name="NoFinalizer"/>
<module name="RedundantImport"/>
<module name="AvoidStarImport"/>
<module name="DefaultComesLast"/>
<module name="SuppressWarningsHolder" />
</module>
Expand Down
7 changes: 3 additions & 4 deletions src/main/software/amazon/event/ruler/ByteMachine.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import software.amazon.event.ruler.input.InputMultiByteSet;
import software.amazon.event.ruler.input.MultiByte;

import javax.annotation.concurrent.ThreadSafe;
import java.nio.charset.StandardCharsets;
import java.util.AbstractMap;
import java.util.ArrayDeque;
Expand All @@ -20,24 +21,22 @@
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
import javax.annotation.concurrent.ThreadSafe;

import static software.amazon.event.ruler.CompoundByteTransition.coalesce;
import static software.amazon.event.ruler.MatchType.ANYTHING_BUT_SUFFIX;
import static software.amazon.event.ruler.MatchType.EQUALS_IGNORE_CASE;
import static software.amazon.event.ruler.MatchType.EXACT;
import static software.amazon.event.ruler.MatchType.EXISTS;
import static software.amazon.event.ruler.MatchType.SUFFIX;
import static software.amazon.event.ruler.MatchType.ANYTHING_BUT_SUFFIX;
import static software.amazon.event.ruler.MatchType.SUFFIX_EQUALS_IGNORE_CASE;

import static software.amazon.event.ruler.input.DefaultParser.getParser;
import static software.amazon.event.ruler.input.MultiByte.MAX_CONTINUATION_BYTE;
import static software.amazon.event.ruler.input.MultiByte.MAX_FIRST_BYTE_FOR_ONE_BYTE_CHAR;
import static software.amazon.event.ruler.input.MultiByte.MAX_FIRST_BYTE_FOR_TWO_BYTE_CHAR;
import static software.amazon.event.ruler.input.MultiByte.MAX_NON_FIRST_BYTE;
import static software.amazon.event.ruler.input.MultiByte.MIN_CONTINUATION_BYTE;
import static software.amazon.event.ruler.input.MultiByte.MIN_FIRST_BYTE_FOR_ONE_BYTE_CHAR;
import static software.amazon.event.ruler.input.MultiByte.MIN_FIRST_BYTE_FOR_TWO_BYTE_CHAR;
import static software.amazon.event.ruler.input.DefaultParser.getParser;

/**
* Represents a UTF8-byte-level state machine that matches a Ruler state machine's field values.
Expand Down
1 change: 0 additions & 1 deletion src/main/software/amazon/event/ruler/ByteState.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.concurrent.ThreadSafe;

import java.util.Collections;
import java.util.Set;
import java.util.stream.Collectors;
Expand Down
3 changes: 2 additions & 1 deletion src/main/software/amazon/event/ruler/GenericMachine.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonNode;

import javax.annotation.Nonnull;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
Expand All @@ -16,7 +18,6 @@
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;

/**
* Represents a state machine used to match name/value patterns to rules.
Expand Down
6 changes: 5 additions & 1 deletion src/main/software/amazon/event/ruler/JsonRuleCompiler.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package software.amazon.event.ruler;

import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.core.StreamReadFeature;
import software.amazon.event.ruler.input.ParseException;

import java.io.IOException;
Expand Down
2 changes: 1 addition & 1 deletion src/main/software/amazon/event/ruler/NameState.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package software.amazon.event.ruler;

import javax.annotation.concurrent.ThreadSafe;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import javax.annotation.concurrent.ThreadSafe;

/**
* Represents a state in the machine.
Expand Down
10 changes: 7 additions & 3 deletions src/main/software/amazon/event/ruler/RuleCompiler.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
package software.amazon.event.ruler;

import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.core.StreamReadFeature;
import software.amazon.event.ruler.input.ParseException;

import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
Expand All @@ -12,9 +19,6 @@
import java.util.Map;
import java.util.Set;

import com.fasterxml.jackson.core.*;
import software.amazon.event.ruler.input.ParseException;

import static software.amazon.event.ruler.input.DefaultParser.getParser;

/**
Expand Down
11 changes: 5 additions & 6 deletions src/main/software/amazon/event/ruler/Ruler.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package software.amazon.event.ruler;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.ThreadSafe;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.ThreadSafe;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
* The core idea of Ruler is to match rules to events at a rate that's independent of the number of rules. This is
* achieved by compiling the rules into an automaton, at some up-front cost for compilation and memory use. There
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

import java.nio.charset.StandardCharsets;

import static software.amazon.event.ruler.MatchType.ANYTHING_BUT_IGNORE_CASE;
import static software.amazon.event.ruler.MatchType.ANYTHING_BUT_SUFFIX;
import static software.amazon.event.ruler.MatchType.EQUALS_IGNORE_CASE;
import static software.amazon.event.ruler.MatchType.ANYTHING_BUT_IGNORE_CASE;
import static software.amazon.event.ruler.MatchType.PREFIX_EQUALS_IGNORE_CASE;
import static software.amazon.event.ruler.MatchType.SUFFIX;
import static software.amazon.event.ruler.MatchType.SUFFIX_EQUALS_IGNORE_CASE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import org.junit.Test;

import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

public class ArrayMembershipTest {
@Test
Expand Down
4 changes: 3 additions & 1 deletion src/test/software/amazon/event/ruler/BigEventTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package software.amazon.event.ruler;

import java.util.List;
import org.junit.Test;

import java.util.List;

import static org.junit.Assert.assertTrue;

public class BigEventTest {
Expand Down
8 changes: 4 additions & 4 deletions src/test/software/amazon/event/ruler/ByteMachineTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package software.amazon.event.ruler;

import org.junit.Test;
import software.amazon.event.ruler.input.ParseException;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
Expand All @@ -9,10 +12,6 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import software.amazon.event.ruler.input.ParseException;
import org.junit.Test;

import static software.amazon.event.ruler.PermutationsGenerator.generateAllPermutations;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
Expand All @@ -21,6 +20,7 @@
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static software.amazon.event.ruler.PermutationsGenerator.generateAllPermutations;

public class ByteMachineTest {

Expand Down
9 changes: 4 additions & 5 deletions src/test/software/amazon/event/ruler/ByteMapTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package software.amazon.event.ruler;

import static software.amazon.event.ruler.CompoundByteTransition.coalesce;
import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.Test;

import java.util.Arrays;
import java.util.HashSet;
Expand All @@ -10,12 +10,11 @@
import java.util.NavigableMap;
import java.util.Set;

import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static software.amazon.event.ruler.CompoundByteTransition.coalesce;

public class ByteMapTest {

Expand Down
10 changes: 5 additions & 5 deletions src/test/software/amazon/event/ruler/ByteMatchTest.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package software.amazon.event.ruler;

import org.junit.Before;
import org.junit.Test;

import java.util.Collections;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;

import org.junit.Before;
import org.junit.Test;

import java.util.Collections;

public class ByteMatchTest {

private ByteMatch match;
Expand Down
2 changes: 1 addition & 1 deletion src/test/software/amazon/event/ruler/ByteStateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
import java.util.Collections;
import java.util.HashSet;

import static software.amazon.event.ruler.CompoundByteTransition.coalesce;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static software.amazon.event.ruler.CompoundByteTransition.coalesce;

public class ByteStateTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
import java.util.Arrays;
import java.util.HashSet;

import static software.amazon.event.ruler.CompoundByteTransition.coalesce;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static software.amazon.event.ruler.CompoundByteTransition.coalesce;

public class CompoundByteTransitionTest {

Expand Down
3 changes: 2 additions & 1 deletion src/test/software/amazon/event/ruler/GenericMachineTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Test;

import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Files;
Expand All @@ -10,7 +12,6 @@
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonNode;
import org.junit.Test;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import java.util.Timer;
import java.util.TimerTask;

import static software.amazon.event.ruler.PermutationsGenerator.generateAllPermutations;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static software.amazon.event.ruler.PermutationsGenerator.generateAllPermutations;

/**
* For each test, for illustrative purposes, I will provide one input string that results in the maximum number of
Expand Down
4 changes: 2 additions & 2 deletions src/test/software/amazon/event/ruler/RuleCompilerTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package software.amazon.event.ruler;

import com.fasterxml.jackson.core.JsonParseException;
import org.junit.Test;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -19,8 +21,6 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
Expand Down
6 changes: 3 additions & 3 deletions src/test/software/amazon/event/ruler/input/InputByteTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import org.junit.Test;

import static software.amazon.event.ruler.input.InputCharacterType.BYTE;
import static software.amazon.event.ruler.input.DefaultParser.ASTERISK_BYTE;
import static software.amazon.event.ruler.input.DefaultParser.BACKSLASH_BYTE;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
import static software.amazon.event.ruler.input.DefaultParser.ASTERISK_BYTE;
import static software.amazon.event.ruler.input.DefaultParser.BACKSLASH_BYTE;
import static software.amazon.event.ruler.input.InputCharacterType.BYTE;

public class InputByteTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
import java.util.HashSet;
import java.util.Set;

import static software.amazon.event.ruler.input.InputCharacterType.MULTI_BYTE_SET;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static software.amazon.event.ruler.input.InputCharacterType.MULTI_BYTE_SET;

public class InputMultiByteSetTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import org.junit.Test;

import static software.amazon.event.ruler.input.InputCharacterType.WILDCARD;
import static software.amazon.event.ruler.input.DefaultParser.ASTERISK_BYTE;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static software.amazon.event.ruler.input.DefaultParser.ASTERISK_BYTE;
import static software.amazon.event.ruler.input.InputCharacterType.WILDCARD;

public class InputWildcardTest {

Expand Down
Loading

0 comments on commit 17860e0

Please sign in to comment.