Compare commits
12 Commits
all-contri
...
all-contri
Author | SHA1 | Date | |
---|---|---|---|
806862fec0 | |||
fef7207418 | |||
cdc2a154df | |||
d620dbbc05 | |||
a86bdfd14d | |||
7408620a71 | |||
a94737075e | |||
3f09fb70bb | |||
663dbd298e | |||
8a9e26e77a | |||
462b581b34 | |||
9abfd5777c |
@ -1386,6 +1386,24 @@
|
||||
"contributions": [
|
||||
"code"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "byoungju94",
|
||||
"name": "byoungju94",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/42516378?v=4",
|
||||
"profile": "https://github.com/byoungju94",
|
||||
"contributions": [
|
||||
"code"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "moustafafarhat",
|
||||
"name": "Moustafa Farhat",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/38836727?v=4",
|
||||
"profile": "https://github.com/moustafafarhat",
|
||||
"contributions": [
|
||||
"translation"
|
||||
]
|
||||
}
|
||||
],
|
||||
"contributorsPerLine": 4,
|
||||
|
@ -1,6 +1,6 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014-2020 Ilkka Seppälä
|
||||
Copyright (c) 2014-2021 Ilkka Seppälä
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -10,12 +10,12 @@
|
||||
[](https://sonarcloud.io/dashboard?id=iluwatar_java-design-patterns)
|
||||
[](https://gitter.im/iluwatar/java-design-patterns?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
||||
[](#contributors-)
|
||||
[](#contributors-)
|
||||
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
||||
|
||||
<br/>
|
||||
|
||||
Read in different language : [**CN**](/zh/README.md),[**KR**](/ko/README.md),[**FR**](/fr/README.md),[**TR**](/tr/README.md),
|
||||
Read in different language : [**CN**](/zh/README.md),[**KR**](/ko/README.md),[**FR**](/fr/README.md),[**TR**](/tr/README.md),[**AR**](/ar/README.md),
|
||||
|
||||
<br/>
|
||||
|
||||
@ -303,6 +303,10 @@ This project is licensed under the terms of the MIT license.
|
||||
<td align="center"><a href="https://github.com/demirhalil"><img src="https://avatars1.githubusercontent.com/u/22895118?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Halil Demir</b></sub></a><br /><a href="#translation-demirhalil" title="Translation">🌍</a></td>
|
||||
<td align="center"><a href="https://github.com/rohit10000"><img src="https://avatars.githubusercontent.com/u/20845565?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Rohit Singh</b></sub></a><br /><a href="https://github.com/iluwatar/java-design-patterns/commits?author=rohit10000" title="Code">💻</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><a href="https://github.com/byoungju94"><img src="https://avatars.githubusercontent.com/u/42516378?v=4?s=100" width="100px;" alt=""/><br /><sub><b>byoungju94</b></sub></a><br /><a href="https://github.com/iluwatar/java-design-patterns/commits?author=byoungju94" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://github.com/moustafafarhat"><img src="https://avatars.githubusercontent.com/u/38836727?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Moustafa Farhat</b></sub></a><br /><a href="#translation-moustafafarhat" title="Translation">🌍</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<!-- markdownlint-restore -->
|
||||
|
@ -213,8 +213,8 @@ Example use cases
|
||||
|
||||
## Related patterns
|
||||
|
||||
[Factory Method](https://java-design-patterns.com/patterns/factory-method/)
|
||||
[Factory Kit](https://java-design-patterns.com/patterns/factory-kit/)
|
||||
* [Factory Method](https://java-design-patterns.com/patterns/factory-method/)
|
||||
* [Factory Kit](https://java-design-patterns.com/patterns/factory-kit/)
|
||||
|
||||
## Credits
|
||||
|
||||
|
42
ar/README.md
Normal file
42
ar/README.md
Normal file
@ -0,0 +1,42 @@
|
||||
# أنماط التصميم بلغة برمجة الجافا
|
||||
|
||||

|
||||
[](https://raw.githubusercontent.com/iluwatar/java-design-patterns/master/LICENSE.md)
|
||||
[](https://sonarcloud.io/dashboard?id=iluwatar_java-design-patterns)
|
||||
[](https://sonarcloud.io/dashboard?id=iluwatar_java-design-patterns)
|
||||
[](https://gitter.im/iluwatar/java-design-patterns?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
||||
[](#contributors-)
|
||||
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
||||
|
||||
|
||||
# مقدمة
|
||||
|
||||
أنماط التصميم هي أفضل التدريبات التي يمكن للمبرمج استخدامها لحل المشكلات الشائعة عند تصميم تطبيق أو نظام.
|
||||
يمكن لأنماط التصميم تسريع عملية التطوير من خلال توفير نماذج تطوير مجربة ومثبتة ومفيدة.
|
||||
تساعد إعادة استخدام أنماط التصميم في منع المشكلات الدقيقة التي تسبب مشكلات كبيرة ، كما تعمل على تحسين قابلية قراءة الكود للمهندسين البرمجيات الذين هم على دراية بالأنماط.
|
||||
|
||||
# البدء في التعلم
|
||||
|
||||
يعرض هذا الموقع أنماط تصميم جافا. تم تطوير الحلول من قبل المبرمجين والمهندسين ذوي الخبرة من مجتمع المصادر المفتوحة. يمكن تصفح الأنماط من خلال أوصافها عالية المستوى أو بالنظر إلى كود المصدر الخاص بها. تم كتابة الشرح على أمثلة الكود المصدري جيدًا ويمكن اعتبارها برامج تعليمية حول كيفية تنفيذ نمط معين. نحن نستخدم تقنيات Java مفتوحة المصدر الأكثر شيوعًا والتي أثبتت جدارتها في مشاريع الجافا.
|
||||
قبل الغوص في المادة ، يجب أن تكون على دراية [بمبادئ تصميم البرامج المختلفة](https://java-design-patterns.com/principles/).
|
||||
|
||||
يجب أن تكون جميع التصميمات بسيطة قدر الإمكان. يجب أن تبدأ بـ KISS و YAGNI وافعل أبسط شيء يمكن أن يعمل بهذه المبادىء. يجب إستخدام الأنماط فقط عند الحاجة إليها من أجل تمديد البرنامج بشكل عملي.
|
||||
|
||||
بمجرد أن تصبح معتادًا على هذه المفاهيم ، يمكنك البدء في التعمق في [أنماط التصميم المتاحة](https://java-design-patterns.com/patterns/) من خلال أي من الأساليب التالية
|
||||
|
||||
ابحث عن نمط محدد بالاسم. لا يمكنك العثور على واحد؟ الرجاء الإبلاغ عن نمط جديد [هنا](https://github.com/iluwatar/java-design-patterns/issues).
|
||||
استخدام علامات مثل Performance أو Gang of Four أو الوصول إلى البيانات.
|
||||
استخدام فئات الأنماط و Creational, Behavioral وغيرها.
|
||||
|
||||
نأمل أن تجد الحلول الموجهة للكائنات المعروضة على هذا الموقع مفيدة في مشاريعك البرمجية وأن تستمتع بتعلمها بقدر ما قمنا بتطويرها.
|
||||
|
||||
|
||||
# كيف تساهم؟
|
||||
|
||||
إذا كنت على استعداد للمساهمة في المشروع ، فستجد المعلومات ذات الصلة في [ويكي المطور الخاص بنا](https://github.com/iluwatar/java-design-patterns/wiki). سنساعدك ونجيب على أسئلتك في [غرفة الدردشة Gitter](https://gitter.im/iluwatar/java-design-patterns).
|
||||
|
||||
|
||||
# الترخيص
|
||||
|
||||
هذا المشروع مرخص بموجب شروط ترخيص MIT.
|
BIN
assets/flags/AR.png
Normal file
BIN
assets/flags/AR.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 252 B |
@ -20,12 +20,14 @@ callbacks or waiting until everything is done.
|
||||
## Applicability
|
||||
Use async method invocation pattern when
|
||||
|
||||
* you have multiple independent tasks that can run in parallel
|
||||
* you need to improve the performance of a group of sequential tasks
|
||||
* you have limited amount of processing capacity or long running tasks and the
|
||||
* You have multiple independent tasks that can run in parallel
|
||||
* You need to improve the performance of a group of sequential tasks
|
||||
* You have limited amount of processing capacity or long running tasks and the
|
||||
caller should not wait the tasks to be ready
|
||||
|
||||
## Real world examples
|
||||
|
||||
* [FutureTask](http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/FutureTask.html), [CompletableFuture](https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletableFuture.html) and [ExecutorService](http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ExecutorService.html) (Java)
|
||||
* [Task-based Asynchronous Pattern](https://msdn.microsoft.com/en-us/library/hh873175.aspx) (.NET)
|
||||
* [FutureTask](http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/FutureTask.html)
|
||||
* [CompletableFuture](https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletableFuture.html)
|
||||
* [ExecutorService](http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ExecutorService.html)
|
||||
* [Task-based Asynchronous Pattern](https://msdn.microsoft.com/en-us/library/hh873175.aspx)
|
||||
|
@ -23,13 +23,15 @@
|
||||
|
||||
package com.iluwatar.caching;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Application test
|
||||
*/
|
||||
public class CachingTest {
|
||||
class CachingTest {
|
||||
private App app;
|
||||
|
||||
/**
|
||||
@ -47,22 +49,26 @@ public class CachingTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadAndWriteThroughStrategy() {
|
||||
void testReadAndWriteThroughStrategy() {
|
||||
assertNotNull(app);
|
||||
app.useReadAndWriteThroughStrategy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadThroughAndWriteAroundStrategy() {
|
||||
void testReadThroughAndWriteAroundStrategy() {
|
||||
assertNotNull(app);
|
||||
app.useReadThroughAndWriteAroundStrategy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadThroughAndWriteBehindStrategy() {
|
||||
void testReadThroughAndWriteBehindStrategy() {
|
||||
assertNotNull(app);
|
||||
app.useReadThroughAndWriteBehindStrategy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCacheAsideStrategy() {
|
||||
void testCacheAsideStrategy() {
|
||||
assertNotNull(app);
|
||||
app.useCacheAsideStategy();
|
||||
}
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ remote calls.
|
||||
|
||||
The service architecture is as follows:
|
||||
|
||||

|
||||

|
||||
|
||||
In terms of code, the end user application is:
|
||||
|
||||
@ -292,7 +292,7 @@ public class DefaultCircuitBreaker implements CircuitBreaker {
|
||||
How does the above pattern prevent failures? Let's understand via this finite state machine
|
||||
implemented by it.
|
||||
|
||||

|
||||

|
||||
|
||||
- We initialize the Circuit Breaker object with certain parameters: `timeout`, `failureThreshold` and `retryTimePeriod` which help determine how resilient the API is.
|
||||
- Initially, we are in the `closed` state and nos remote calls to the API have occurred.
|
||||
|
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 23 KiB |
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 19 KiB |
@ -105,4 +105,4 @@ domain equivalence.
|
||||
|
||||
## Credits
|
||||
|
||||
* [Converter](http://www.xsolve.pl/blog/converter-pattern-in-java-8/)
|
||||
* [Converter Pattern in Java 8](http://www.xsolve.pl/blog/converter-pattern-in-java-8/)
|
||||
|
@ -67,7 +67,7 @@ public class DbCustomerDao implements CustomerDao {
|
||||
public Stream<Customer> getAll() throws Exception {
|
||||
try {
|
||||
var connection = getConnection();
|
||||
var statement = connection.prepareStatement("SELECT * FROM CUSTOMERS");
|
||||
var statement = connection.prepareStatement("SELECT * FROM CUSTOMERS"); // NOSONAR
|
||||
var resultSet = statement.executeQuery(); // NOSONAR
|
||||
return StreamSupport.stream(new Spliterators.AbstractSpliterator<Customer>(Long.MAX_VALUE,
|
||||
Spliterator.ORDERED) {
|
||||
|
3
pom.xml
3
pom.xml
@ -25,6 +25,7 @@
|
||||
<inceptionYear>2014-2019</inceptionYear>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<sonar-maven-plugin.version>3.8.0.2131</sonar-maven-plugin.version>
|
||||
<hibernate.version>5.2.18.Final</hibernate.version>
|
||||
<spring.version>5.0.13.RELEASE</spring.version>
|
||||
<spring-boot.version>2.0.9.RELEASE</spring-boot.version>
|
||||
@ -425,7 +426,7 @@
|
||||
<plugin>
|
||||
<groupId>org.sonarsource.scanner.maven</groupId>
|
||||
<artifactId>sonar-maven-plugin</artifactId>
|
||||
<version>3.7.0.1746</version>
|
||||
<version>${sonar-maven-plugin.version}</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
package com.iluwatar.spatialpartition;
|
||||
|
||||
import java.util.Hashtable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -44,11 +44,11 @@ import org.slf4j.LoggerFactory;
|
||||
* <b>{@link Rect}</b> class to define the boundary of the quadtree. We use an abstract class
|
||||
* <b>{@link Point}</b>
|
||||
* with x and y coordinate fields and also an id field so that it can easily be put and looked up in
|
||||
* the hashtable. This class has abstract methods to define how the object moves (move()), when to
|
||||
* the hashmap. This class has abstract methods to define how the object moves (move()), when to
|
||||
* check for collision with any object (touches(obj)) and how to handle collision
|
||||
* (handleCollision(obj)), and will be extended by any object whose position has to be kept track of
|
||||
* in the quadtree. The <b>{@link SpatialPartitionGeneric}</b> abstract class has 2 fields - a
|
||||
* hashtable containing all objects (we use hashtable for faster lookups, insertion and deletion)
|
||||
* hashmap containing all objects (we use hashmap for faster lookups, insertion and deletion)
|
||||
* and a quadtree, and contains an abstract method which defines how to handle interactions between
|
||||
* objects using the quadtree.</p>
|
||||
* <p>Using the quadtree data structure will reduce the time complexity of finding the objects
|
||||
@ -61,7 +61,7 @@ public class App {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
||||
private static final String BUBBLE = "Bubble ";
|
||||
|
||||
static void noSpatialPartition(int numOfMovements, Hashtable<Integer, Bubble> bubbles) {
|
||||
static void noSpatialPartition(int numOfMovements, HashMap<Integer, Bubble> bubbles) {
|
||||
//all bubbles have to be checked for collision for all bubbles
|
||||
var bubblesToCheck = bubbles.values();
|
||||
|
||||
@ -81,9 +81,9 @@ public class App {
|
||||
}
|
||||
|
||||
static void withSpatialPartition(
|
||||
int height, int width, int numOfMovements, Hashtable<Integer, Bubble> bubbles) {
|
||||
int height, int width, int numOfMovements, HashMap<Integer, Bubble> bubbles) {
|
||||
//creating quadtree
|
||||
var rect = new Rect(width / 2, height / 2, width, height);
|
||||
var rect = new Rect(width / 2D, height / 2D, width, height);
|
||||
var quadTree = new QuadTree(rect, 4);
|
||||
|
||||
//will run numOfMovement times or till all bubbles have popped
|
||||
@ -110,15 +110,15 @@ public class App {
|
||||
*/
|
||||
|
||||
public static void main(String[] args) {
|
||||
var bubbles1 = new Hashtable<Integer, Bubble>();
|
||||
var bubbles2 = new Hashtable<Integer, Bubble>();
|
||||
var bubbles1 = new HashMap<Integer, Bubble>();
|
||||
var bubbles2 = new HashMap<Integer, Bubble>();
|
||||
var rand = new Random();
|
||||
for (int i = 0; i < 10000; i++) {
|
||||
var b = new Bubble(rand.nextInt(300), rand.nextInt(300), i, rand.nextInt(2) + 1);
|
||||
bubbles1.put(i, b);
|
||||
bubbles2.put(i, b);
|
||||
LOGGER.info(BUBBLE + i + " with radius " + b.radius
|
||||
+ " added at (" + b.coordinateX + "," + b.coordinateY + ")");
|
||||
LOGGER.info(BUBBLE, i, " with radius ", b.radius,
|
||||
" added at (", b.coordinateX, ",", b.coordinateY + ")");
|
||||
}
|
||||
|
||||
var start1 = System.currentTimeMillis();
|
||||
@ -127,8 +127,8 @@ public class App {
|
||||
var start2 = System.currentTimeMillis();
|
||||
App.withSpatialPartition(300, 300, 20, bubbles2);
|
||||
var end2 = System.currentTimeMillis();
|
||||
LOGGER.info("Without spatial partition takes " + (end1 - start1) + "ms");
|
||||
LOGGER.info("With spatial partition takes " + (end2 - start2) + "ms");
|
||||
LOGGER.info("Without spatial partition takes ", (end1 - start1), "ms");
|
||||
LOGGER.info("With spatial partition takes ", (end2 - start2), "ms");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@
|
||||
package com.iluwatar.spatialpartition;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Hashtable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -58,13 +58,13 @@ public class Bubble extends Point<Bubble> {
|
||||
<= (this.radius + b.radius) * (this.radius + b.radius);
|
||||
}
|
||||
|
||||
void pop(Hashtable<Integer, Bubble> allBubbles) {
|
||||
LOGGER.info("Bubble " + this.id
|
||||
+ " popped at (" + this.coordinateX + "," + this.coordinateY + ")!");
|
||||
void pop(HashMap<Integer, Bubble> allBubbles) {
|
||||
LOGGER.info("Bubble ", this.id,
|
||||
" popped at (", this.coordinateX, ",", this.coordinateY, ")!");
|
||||
allBubbles.remove(this.id);
|
||||
}
|
||||
|
||||
void handleCollision(Collection<? extends Point> toCheck, Hashtable<Integer, Bubble> allBubbles) {
|
||||
void handleCollision(Collection<? extends Point> toCheck, HashMap<Integer, Bubble> allBubbles) {
|
||||
var toBePopped = false; //if any other bubble collides with it, made true
|
||||
for (var point : toCheck) {
|
||||
var otherId = point.id;
|
||||
|
@ -24,7 +24,7 @@
|
||||
package com.iluwatar.spatialpartition;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Hashtable;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* 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> {
|
||||
* @param toCheck contains the objects which need to be checked
|
||||
* @param all contains hashtable of all points on field at this time
|
||||
*/
|
||||
abstract void handleCollision(Collection<? extends Point> toCheck, Hashtable<Integer, T> all);
|
||||
abstract void handleCollision(Collection<? extends Point> toCheck, HashMap<Integer, T> all);
|
||||
}
|
||||
|
@ -24,7 +24,7 @@
|
||||
package com.iluwatar.spatialpartition;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Hashtable;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* This class extends the generic SpatialPartition abstract class and is used in our example to keep
|
||||
@ -33,10 +33,10 @@ import java.util.Hashtable;
|
||||
|
||||
public class SpatialPartitionBubbles extends SpatialPartitionGeneric<Bubble> {
|
||||
|
||||
private final Hashtable<Integer, Bubble> bubbles;
|
||||
private final HashMap<Integer, Bubble> bubbles;
|
||||
private final QuadTree quadTree;
|
||||
|
||||
SpatialPartitionBubbles(Hashtable<Integer, Bubble> bubbles, QuadTree quadTree) {
|
||||
SpatialPartitionBubbles(HashMap<Integer, Bubble> bubbles, QuadTree quadTree) {
|
||||
this.bubbles = bubbles;
|
||||
this.quadTree = quadTree;
|
||||
}
|
||||
@ -44,7 +44,7 @@ public class SpatialPartitionBubbles extends SpatialPartitionGeneric<Bubble> {
|
||||
void handleCollisionsUsingQt(Bubble b) {
|
||||
// finding points within area of a square drawn with centre same as
|
||||
// centre of bubble and length = radius of bubble
|
||||
var rect = new Rect(b.coordinateX, b.coordinateY, 2 * b.radius, 2 * b.radius);
|
||||
var rect = new Rect(b.coordinateX, b.coordinateY, 2D * b.radius, 2D * b.radius);
|
||||
var quadTreeQueryResult = new ArrayList<Point>();
|
||||
this.quadTree.query(rect, quadTreeQueryResult);
|
||||
//handling these collisions
|
||||
|
@ -29,7 +29,7 @@ import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Hashtable;
|
||||
import java.util.HashMap;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
@ -63,11 +63,11 @@ class BubbleTest {
|
||||
void popTest() {
|
||||
var b1 = new Bubble(10, 10, 1, 2);
|
||||
var b2 = new Bubble(0, 0, 2, 2);
|
||||
var bubbles = new Hashtable<Integer, Bubble>();
|
||||
var bubbles = new HashMap<Integer, Bubble>();
|
||||
bubbles.put(1, b1);
|
||||
bubbles.put(2, b2);
|
||||
b1.pop(bubbles);
|
||||
//after popping, bubble no longer in hashtable containing all bubbles
|
||||
//after popping, bubble no longer in hashMap containing all bubbles
|
||||
assertNull(bubbles.get(1));
|
||||
assertNotNull(bubbles.get(2));
|
||||
}
|
||||
@ -77,7 +77,7 @@ class BubbleTest {
|
||||
var b1 = new Bubble(0, 0, 1, 2);
|
||||
var b2 = new Bubble(1, 1, 2, 1);
|
||||
var b3 = new Bubble(10, 10, 3, 1);
|
||||
var bubbles = new Hashtable<Integer, Bubble>();
|
||||
var bubbles = new HashMap<Integer, Bubble>();
|
||||
bubbles.put(1, b1);
|
||||
bubbles.put(2, b2);
|
||||
bubbles.put(3, b3);
|
||||
|
@ -26,7 +26,7 @@ package com.iluwatar.spatialpartition;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
import java.util.Hashtable;
|
||||
import java.util.HashMap;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
@ -41,7 +41,7 @@ class SpatialPartitionBubblesTest {
|
||||
var b2 = new Bubble(5, 5, 2, 1);
|
||||
var b3 = new Bubble(9, 9, 3, 1);
|
||||
var b4 = new Bubble(8, 8, 4, 2);
|
||||
var bubbles = new Hashtable<Integer, Bubble>();
|
||||
var bubbles = new HashMap<Integer, Bubble>();
|
||||
bubbles.put(1, b1);
|
||||
bubbles.put(2, b2);
|
||||
bubbles.put(3, b3);
|
||||
|
@ -38,16 +38,13 @@ public class Db {
|
||||
*
|
||||
* @return singleton instance of Db class
|
||||
*/
|
||||
public static Db getInstance() {
|
||||
public static synchronized Db getInstance() {
|
||||
if (instance == null) {
|
||||
synchronized (Db.class) {
|
||||
if (instance == null) {
|
||||
instance = new Db();
|
||||
instance.userName2User = new HashMap<>();
|
||||
instance.user2Account = new HashMap<>();
|
||||
instance.itemName2Product = new HashMap<>();
|
||||
}
|
||||
}
|
||||
Db newInstance = new Db();
|
||||
newInstance.userName2User = new HashMap<>();
|
||||
newInstance.user2Account = new HashMap<>();
|
||||
newInstance.itemName2Product = new HashMap<>();
|
||||
instance = newInstance;
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
@ -38,13 +38,9 @@ public class MaintenanceLock {
|
||||
*
|
||||
* @return singleton instance of MaintenanceLock
|
||||
*/
|
||||
public static MaintenanceLock getInstance() {
|
||||
public static synchronized MaintenanceLock getInstance() {
|
||||
if (instance == null) {
|
||||
synchronized (MaintenanceLock.class) {
|
||||
if (instance == null) {
|
||||
instance = new MaintenanceLock();
|
||||
}
|
||||
}
|
||||
instance = new MaintenanceLock();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
@ -55,6 +51,6 @@ public class MaintenanceLock {
|
||||
|
||||
public void setLock(boolean lock) {
|
||||
this.lock = lock;
|
||||
LOGGER.info("Maintenance lock is set to: " + lock);
|
||||
LOGGER.info("Maintenance lock is set to: ", lock);
|
||||
}
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ public class HotelDaoImpl implements HotelDao {
|
||||
public Stream<Room> getAll() throws Exception {
|
||||
try {
|
||||
var connection = getConnection();
|
||||
var statement = connection.prepareStatement("SELECT * FROM ROOMS");
|
||||
var statement = connection.prepareStatement("SELECT * FROM ROOMS"); // NOSONAR
|
||||
var resultSet = statement.executeQuery(); // NOSONAR
|
||||
return StreamSupport.stream(new Spliterators.AbstractSpliterator<Room>(Long.MAX_VALUE,
|
||||
Spliterator.ORDERED) {
|
||||
|
Reference in New Issue
Block a user