Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3f09fb7

Browse files
authored
Clear Sonar Blockers (iluwatar#1643)
* remove debt from CachingTesthttps://sonarcloud.io/project/issues?fileUuids=AW3G0SevwB6UiZzQNqXR&id=iluwatar_java-design-patterns&open=AXK0Ozo--CiGJS70dLl0&resolved=false Signed-off-by: Subhrodip Mohanta <subhrodipmohanta@gmail.com>* fixed few debts for Spatial Partition moduleMainly convertig Hashtable to HashMapsSigned-off-by: Subhrodip Mohanta <subhrodipmohanta@gmail.com>* fixed some logger normsSigned-off-by: Subhrodip Mohanta <subhrodipmohanta@gmail.com>* fixed few errors as it got mixed with the stashSigned-off-by: Subhrodip Mohanta <subhrodipmohanta@gmail.com>
1 parent663dbd2 commit3f09fb7

File tree

7 files changed

+40
-34
lines changed

7 files changed

+40
-34
lines changed

‎caching/src/test/java/com/iluwatar/caching/CachingTest.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@
2323

2424
packagecom.iluwatar.caching;
2525

26+
importstaticorg.junit.jupiter.api.Assertions.assertNotNull;
27+
2628
importorg.junit.jupiter.api.BeforeEach;
2729
importorg.junit.jupiter.api.Test;
2830

2931
/**
3032
* Application test
3133
*/
32-
publicclassCachingTest {
34+
classCachingTest {
3335
privateAppapp;
3436

3537
/**
@@ -47,22 +49,26 @@ public void setUp() {
4749
}
4850

4951
@Test
50-
publicvoidtestReadAndWriteThroughStrategy() {
52+
voidtestReadAndWriteThroughStrategy() {
53+
assertNotNull(app);
5154
app.useReadAndWriteThroughStrategy();
5255
}
5356

5457
@Test
55-
publicvoidtestReadThroughAndWriteAroundStrategy() {
58+
voidtestReadThroughAndWriteAroundStrategy() {
59+
assertNotNull(app);
5660
app.useReadThroughAndWriteAroundStrategy();
5761
}
5862

5963
@Test
60-
publicvoidtestReadThroughAndWriteBehindStrategy() {
64+
voidtestReadThroughAndWriteBehindStrategy() {
65+
assertNotNull(app);
6166
app.useReadThroughAndWriteBehindStrategy();
6267
}
6368

6469
@Test
65-
publicvoidtestCacheAsideStrategy() {
70+
voidtestCacheAsideStrategy() {
71+
assertNotNull(app);
6672
app.useCacheAsideStategy();
6773
}
6874
}

‎spatial-partition/src/main/java/com/iluwatar/spatialpartition/App.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
packagecom.iluwatar.spatialpartition;
2525

26-
importjava.util.Hashtable;
26+
importjava.util.HashMap;
2727
importjava.util.Random;
2828
importorg.slf4j.Logger;
2929
importorg.slf4j.LoggerFactory;
@@ -44,11 +44,11 @@
4444
* <b>{@link Rect}</b> class to define the boundary of the quadtree. We use an abstract class
4545
* <b>{@link Point}</b>
4646
* with x and y coordinate fields and also an id field so that it can easily be put and looked up in
47-
* thehashtable. This class has abstract methods to define how the object moves (move()), when to
47+
* thehashmap. This class has abstract methods to define how the object moves (move()), when to
4848
* check for collision with any object (touches(obj)) and how to handle collision
4949
* (handleCollision(obj)), and will be extended by any object whose position has to be kept track of
5050
* in the quadtree. The <b>{@link SpatialPartitionGeneric}</b> abstract class has 2 fields - a
51-
*hashtable containing all objects (we usehashtable for faster lookups, insertion and deletion)
51+
*hashmap containing all objects (we usehashmap for faster lookups, insertion and deletion)
5252
* and a quadtree, and contains an abstract method which defines how to handle interactions between
5353
* objects using the quadtree.</p>
5454
* <p>Using the quadtree data structure will reduce the time complexity of finding the objects
@@ -61,7 +61,7 @@ public class App {
6161
privatestaticfinalLoggerLOGGER =LoggerFactory.getLogger(App.class);
6262
privatestaticfinalStringBUBBLE ="Bubble ";
6363

64-
staticvoidnoSpatialPartition(intnumOfMovements,Hashtable<Integer,Bubble>bubbles) {
64+
staticvoidnoSpatialPartition(intnumOfMovements,HashMap<Integer,Bubble>bubbles) {
6565
//all bubbles have to be checked for collision for all bubbles
6666
varbubblesToCheck =bubbles.values();
6767

@@ -81,9 +81,9 @@ static void noSpatialPartition(int numOfMovements, Hashtable<Integer, Bubble> bu
8181
}
8282

8383
staticvoidwithSpatialPartition(
84-
intheight,intwidth,intnumOfMovements,Hashtable<Integer,Bubble>bubbles) {
84+
intheight,intwidth,intnumOfMovements,HashMap<Integer,Bubble>bubbles) {
8585
//creating quadtree
86-
varrect =newRect(width /2,height /2,width,height);
86+
varrect =newRect(width /2D,height /2D,width,height);
8787
varquadTree =newQuadTree(rect,4);
8888

8989
//will run numOfMovement times or till all bubbles have popped
@@ -110,15 +110,15 @@ static void withSpatialPartition(
110110
*/
111111

112112
publicstaticvoidmain(String[]args) {
113-
varbubbles1 =newHashtable<Integer,Bubble>();
114-
varbubbles2 =newHashtable<Integer,Bubble>();
113+
varbubbles1 =newHashMap<Integer,Bubble>();
114+
varbubbles2 =newHashMap<Integer,Bubble>();
115115
varrand =newRandom();
116116
for (inti =0;i <10000;i++) {
117117
varb =newBubble(rand.nextInt(300),rand.nextInt(300),i,rand.nextInt(2) +1);
118118
bubbles1.put(i,b);
119119
bubbles2.put(i,b);
120-
LOGGER.info(BUBBLE +i +" with radius " +b.radius
121-
+" added at (" +b.coordinateX +"," +b.coordinateY +")");
120+
LOGGER.info(BUBBLE,i," with radius ",b.radius,
121+
" added at (",b.coordinateX,",",b.coordinateY +")");
122122
}
123123

124124
varstart1 =System.currentTimeMillis();
@@ -127,8 +127,8 @@ public static void main(String[] args) {
127127
varstart2 =System.currentTimeMillis();
128128
App.withSpatialPartition(300,300,20,bubbles2);
129129
varend2 =System.currentTimeMillis();
130-
LOGGER.info("Without spatial partition takes " +(end1 -start1) +"ms");
131-
LOGGER.info("With spatial partition takes " +(end2 -start2) +"ms");
130+
LOGGER.info("Without spatial partition takes ",(end1 -start1),"ms");
131+
LOGGER.info("With spatial partition takes ",(end2 -start2),"ms");
132132
}
133133
}
134134

‎spatial-partition/src/main/java/com/iluwatar/spatialpartition/Bubble.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
packagecom.iluwatar.spatialpartition;
2525

2626
importjava.util.Collection;
27-
importjava.util.Hashtable;
27+
importjava.util.HashMap;
2828
importjava.util.Random;
2929
importorg.slf4j.Logger;
3030
importorg.slf4j.LoggerFactory;
@@ -58,13 +58,13 @@ boolean touches(Bubble b) {
5858
<= (this.radius +b.radius) * (this.radius +b.radius);
5959
}
6060

61-
voidpop(Hashtable<Integer,Bubble>allBubbles) {
62-
LOGGER.info("Bubble " +this.id
63-
+" popped at (" +this.coordinateX +"," +this.coordinateY +")!");
61+
voidpop(HashMap<Integer,Bubble>allBubbles) {
62+
LOGGER.info("Bubble ",this.id,
63+
" popped at (",this.coordinateX,",",this.coordinateY,")!");
6464
allBubbles.remove(this.id);
6565
}
6666

67-
voidhandleCollision(Collection<?extendsPoint>toCheck,Hashtable<Integer,Bubble>allBubbles) {
67+
voidhandleCollision(Collection<?extendsPoint>toCheck,HashMap<Integer,Bubble>allBubbles) {
6868
vartoBePopped =false;//if any other bubble collides with it, made true
6969
for (varpoint :toCheck) {
7070
varotherId =point.id;

‎spatial-partition/src/main/java/com/iluwatar/spatialpartition/Point.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
packagecom.iluwatar.spatialpartition;
2525

2626
importjava.util.Collection;
27-
importjava.util.Hashtable;
27+
importjava.util.HashMap;
2828

2929
/**
3030
* The abstract Point class which will be extended by any object in the field whose location has to
@@ -64,5 +64,5 @@ public abstract class Point<T> {
6464
* @param toCheck contains the objects which need to be checked
6565
* @param all contains hashtable of all points on field at this time
6666
*/
67-
abstractvoidhandleCollision(Collection<?extendsPoint>toCheck,Hashtable<Integer,T>all);
67+
abstractvoidhandleCollision(Collection<?extendsPoint>toCheck,HashMap<Integer,T>all);
6868
}

‎spatial-partition/src/main/java/com/iluwatar/spatialpartition/SpatialPartitionBubbles.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
packagecom.iluwatar.spatialpartition;
2525

2626
importjava.util.ArrayList;
27-
importjava.util.Hashtable;
27+
importjava.util.HashMap;
2828

2929
/**
3030
* This class extends the generic SpatialPartition abstract class and is used in our example to keep
@@ -33,18 +33,18 @@
3333

3434
publicclassSpatialPartitionBubblesextendsSpatialPartitionGeneric<Bubble> {
3535

36-
privatefinalHashtable<Integer,Bubble>bubbles;
36+
privatefinalHashMap<Integer,Bubble>bubbles;
3737
privatefinalQuadTreequadTree;
3838

39-
SpatialPartitionBubbles(Hashtable<Integer,Bubble>bubbles,QuadTreequadTree) {
39+
SpatialPartitionBubbles(HashMap<Integer,Bubble>bubbles,QuadTreequadTree) {
4040
this.bubbles =bubbles;
4141
this.quadTree =quadTree;
4242
}
4343

4444
voidhandleCollisionsUsingQt(Bubbleb) {
4545
// finding points within area of a square drawn with centre same as
4646
// centre of bubble and length = radius of bubble
47-
varrect =newRect(b.coordinateX,b.coordinateY,2 *b.radius,2 *b.radius);
47+
varrect =newRect(b.coordinateX,b.coordinateY,2D *b.radius,2D *b.radius);
4848
varquadTreeQueryResult =newArrayList<Point>();
4949
this.quadTree.query(rect,quadTreeQueryResult);
5050
//handling these collisions

‎spatial-partition/src/test/java/com/iluwatar/spatialpartition/BubbleTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
importstaticorg.junit.jupiter.api.Assertions.assertTrue;
3030

3131
importjava.util.ArrayList;
32-
importjava.util.Hashtable;
32+
importjava.util.HashMap;
3333
importorg.junit.jupiter.api.Test;
3434

3535
/**
@@ -63,11 +63,11 @@ void touchesTest() {
6363
voidpopTest() {
6464
varb1 =newBubble(10,10,1,2);
6565
varb2 =newBubble(0,0,2,2);
66-
varbubbles =newHashtable<Integer,Bubble>();
66+
varbubbles =newHashMap<Integer,Bubble>();
6767
bubbles.put(1,b1);
6868
bubbles.put(2,b2);
6969
b1.pop(bubbles);
70-
//after popping, bubble no longer inhashtable containing all bubbles
70+
//after popping, bubble no longer inhashMap containing all bubbles
7171
assertNull(bubbles.get(1));
7272
assertNotNull(bubbles.get(2));
7373
}
@@ -77,7 +77,7 @@ void handleCollisionTest() {
7777
varb1 =newBubble(0,0,1,2);
7878
varb2 =newBubble(1,1,2,1);
7979
varb3 =newBubble(10,10,3,1);
80-
varbubbles =newHashtable<Integer,Bubble>();
80+
varbubbles =newHashMap<Integer,Bubble>();
8181
bubbles.put(1,b1);
8282
bubbles.put(2,b2);
8383
bubbles.put(3,b3);

‎spatial-partition/src/test/java/com/iluwatar/spatialpartition/SpatialPartitionBubblesTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
importstaticorg.junit.jupiter.api.Assertions.assertNotNull;
2727
importstaticorg.junit.jupiter.api.Assertions.assertNull;
2828

29-
importjava.util.Hashtable;
29+
importjava.util.HashMap;
3030
importorg.junit.jupiter.api.Test;
3131

3232
/**
@@ -41,7 +41,7 @@ void handleCollisionsUsingQtTest() {
4141
varb2 =newBubble(5,5,2,1);
4242
varb3 =newBubble(9,9,3,1);
4343
varb4 =newBubble(8,8,4,2);
44-
varbubbles =newHashtable<Integer,Bubble>();
44+
varbubbles =newHashMap<Integer,Bubble>();
4545
bubbles.put(1,b1);
4646
bubbles.put(2,b2);
4747
bubbles.put(3,b3);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp