Skip to content

Commit bbe925b

Browse files
author
juan
committed
Merge remote-tracking branch 'upstream/master'
2 parents 911ca0f + 624f7f4 commit bbe925b

84 files changed

Lines changed: 1822 additions & 1168 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎core-java-concurrency/src/test/java/com/baeldung/concurrent/synchronize/BaeldungSychronizedBlockTest.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public void givenMultiThread_whenBlockSync() throws InterruptedException {
1818

1919
IntStream.range(0, 1000)
2020
.forEach(count -> service.submit(synchronizedBlocks::performSynchronisedTask));
21-
service.awaitTermination(100, TimeUnit.MILLISECONDS);
21+
service.awaitTermination(500, TimeUnit.MILLISECONDS);
2222

2323
assertEquals(1000, synchronizedBlocks.getCount());
2424
}
@@ -29,7 +29,7 @@ public void givenMultiThread_whenStaticSyncBlock() throws InterruptedException {
2929

3030
IntStream.range(0, 1000)
3131
.forEach(count -> service.submit(BaeldungSynchronizedBlocks::performStaticSyncTask));
32-
service.awaitTermination(100, TimeUnit.MILLISECONDS);
32+
service.awaitTermination(500, TimeUnit.MILLISECONDS);
3333

3434
assertEquals(1000, BaeldungSynchronizedBlocks.getStaticCount());
3535
}

‎core-java/pom.xml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@
239239
<artifactId>maven-surefire-plugin</artifactId>
240240
<configuration>
241241
<excludes>
242+
<exclude>**/*LiveTest.java</exclude>
242243
<exclude>**/*IntegrationTest.java</exclude>
243244
<exclude>**/*LongRunningUnitTest.java</exclude>
244245
<exclude>**/*ManualTest.java</exclude>
@@ -415,7 +416,8 @@
415416
<executions>
416417
<execution>
417418
<id>run-benchmarks</id>
418-
<phase>integration-test</phase>
419+
<!-- <phase>integration-test</phase>-->
420+
<phase>none</phase>
419421
<goals>
420422
<goal>exec</goal>
421423
</goals>

core-java/src/test/java/com/baeldung/java/nio/selector/NioEchoIntegrationTest.java renamed to core-java/src/test/java/com/baeldung/java/nio/selector/NioEchoLiveTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
import org.junit.Before;
99
import org.junit.Test;
1010

11-
public class NioEchoIntegrationTest {
11+
public class NioEchoLiveTest {
1212

13-
Process server;
14-
EchoClient client;
13+
private Process server;
14+
private EchoClient client;
1515

1616
@Before
1717
public void setup() throws IOException, InterruptedException {

core-java/src/test/java/com/baeldung/jdbc/JdbcIntegrationTest.java renamed to core-java/src/test/java/com/baeldung/jdbc/JdbcLiveTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
import org.junit.Before;
2222
import org.junit.Test;
2323

24-
public class JdbcIntegrationTest {
24+
public class JdbcLiveTest {
2525

26-
private static final Logger LOG = Logger.getLogger(JdbcIntegrationTest.class);
26+
private static final Logger LOG = Logger.getLogger(JdbcLiveTest.class);
2727

2828
private Connection con;
2929

core-java/src/test/java/com/baeldung/networking/udp/UDPIntegrationTest.java renamed to core-java/src/test/java/com/baeldung/networking/udp/UDPLiveTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import static org.junit.Assert.assertEquals;
1010
import static org.junit.Assert.assertFalse;
1111

12-
public class UDPIntegrationTest {
12+
public class UDPLiveTest {
1313
private EchoClient client;
1414

1515
@Before

core-java/src/test/java/com/baeldung/networking/udp/broadcast/BroadcastIntegrationTest.java renamed to core-java/src/test/java/com/baeldung/networking/udp/broadcast/BroadcastLiveTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import static org.junit.Assert.assertEquals;
99

10-
public class BroadcastIntegrationTest {
10+
public class BroadcastLiveTest {
1111
private BroadcastingClient client;
1212

1313
@Test

core-java/src/test/java/com/baeldung/networking/udp/multicast/MulticastIntegrationTest.java renamed to core-java/src/test/java/com/baeldung/networking/udp/multicast/MulticastLiveTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import static org.junit.Assert.assertEquals;
99

10-
public class MulticastIntegrationTest {
10+
public class MulticastLiveTest {
1111
private MulticastingClient client;
1212

1313
@Test

core-java/src/test/java/com/baeldung/printscreen/ScreenshotIntegrationTest.java renamed to core-java/src/test/java/com/baeldung/printscreen/ScreenshotLiveTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import static org.junit.Assert.assertTrue;
99

10-
public class ScreenshotIntegrationTest {
10+
public class ScreenshotLiveTest {
1111

1212
private Screenshot screenshot = new Screenshot("Screenshot.jpg");
1313
private File file = new File("Screenshot.jpg");

‎geotools/pom.xml‎

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>com.baeldung</groupId>
6+
<artifactId>geotools</artifactId>
7+
<version>0.0.1-SNAPSHOT</version>
8+
<packaging>jar</packaging>
9+
10+
<name>geotools</name>
11+
<url>http://maven.apache.org</url>
12+
13+
<dependencies>
14+
<dependency>
15+
<groupId>junit</groupId>
16+
<artifactId>junit</artifactId>
17+
<version>4.12</version>
18+
<scope>test</scope>
19+
</dependency>
20+
<dependency>
21+
<groupId>org.geotools</groupId>
22+
<artifactId>gt-shapefile</artifactId>
23+
<version>${geotools-shapefile.version}</version>
24+
</dependency>
25+
<dependency>
26+
<groupId>org.geotools</groupId>
27+
<artifactId>gt-epsg-hsql</artifactId>
28+
<version>${geotools.version}</version>
29+
</dependency>
30+
<dependency>
31+
<groupId>org.geotools</groupId>
32+
<artifactId>gt-swing</artifactId>
33+
<version>${geotools-swing.version}</version>
34+
</dependency>
35+
</dependencies>
36+
<repositories>
37+
<repository>
38+
<id>maven2-repository.dev.java.net</id>
39+
<name>Java.net repository</name>
40+
<url>http://download.java.net/maven/2</url>
41+
</repository>
42+
<repository>
43+
<id>osgeo</id>
44+
<name>Open Source Geospatial Foundation Repository</name>
45+
<url>http://download.osgeo.org/webdav/geotools/</url>
46+
</repository>
47+
<repository>
48+
<snapshots>
49+
<enabled>true</enabled>
50+
</snapshots>
51+
<id>opengeo</id>
52+
<name>OpenGeo Maven Repository</name>
53+
<url>http://repo.opengeo.org</url>
54+
</repository>
55+
</repositories>
56+
<build>
57+
<plugins>
58+
<plugin>
59+
<inherited>true</inherited>
60+
<groupId>org.apache.maven.plugins</groupId>
61+
<artifactId>maven-compiler-plugin</artifactId>
62+
<configuration>
63+
<source>1.8</source>
64+
<target>1.8</target>
65+
</configuration>
66+
</plugin>
67+
</plugins>
68+
</build>
69+
<properties>
70+
<geotools.version>15.2</geotools.version>
71+
<geotools-swing.version>15.2</geotools-swing.version>
72+
<geotools-shapefile.version>15.2</geotools-shapefile.version>
73+
</properties>
74+
</project>

libraries/src/main/java/com/baeldung/geotools/ShapeFile.java renamed to geotools/src/main/java/com/baeldung/geotools/ShapeFile.java

Lines changed: 47 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -50,42 +50,10 @@ public static void main(String[] args) throws Exception {
5050
ShapefileDataStoreFactory dataStoreFactory = new ShapefileDataStoreFactory();
5151

5252
Map<String, Serializable> params = new HashMap<String, Serializable>();
53-
params.put("url", shapeFile.toURI()
54-
.toURL());
55-
params.put("create spatial index", Boolean.TRUE);
56-
57-
ShapefileDataStore dataStore = (ShapefileDataStore) dataStoreFactory.createNewDataStore(params);
58-
dataStore.createSchema(CITY);
59-
60-
// If you decide to use the TYPE type and create a Data Store with it,
61-
// You will need to uncomment this line to set the Coordinate Reference System
62-
// newDataStore.forceSchemaCRS(DefaultGeographicCRS.WGS84);
6353

64-
Transaction transaction = new DefaultTransaction("create");
54+
ShapefileDataStore dataStore = setDataStoreParams(dataStoreFactory, params, shapeFile, CITY);
6555

66-
String typeName = dataStore.getTypeNames()[0];
67-
SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName);
68-
69-
if (featureSource instanceof SimpleFeatureStore) {
70-
SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;
71-
72-
featureStore.setTransaction(transaction);
73-
try {
74-
featureStore.addFeatures(collection);
75-
transaction.commit();
76-
77-
} catch (Exception problem) {
78-
problem.printStackTrace();
79-
transaction.rollback();
80-
81-
} finally {
82-
transaction.close();
83-
}
84-
System.exit(0); // success!
85-
} else {
86-
System.out.println(typeName + " does not support read/write access");
87-
System.exit(1);
88-
}
56+
writeToFile(dataStore, collection);
8957

9058
}
9159

@@ -152,7 +120,7 @@ public static void addLocations(SimpleFeatureBuilder featureBuilder, DefaultFeat
152120
}
153121

154122
}
155-
123+
156124
private static void addToLocationMap(String name, double lat, double lng, Map<String, List<Double>> locations) {
157125
List<Double> coordinates = new ArrayList<>();
158126

@@ -163,7 +131,6 @@ private static void addToLocationMap(String name, double lat, double lng, Map<St
163131

164132
private static File getNewShapeFile() {
165133
String filePath = new File(".").getAbsolutePath() + FILE_NAME;
166-
167134

168135
JFileDataStoreChooser chooser = new JFileDataStoreChooser("shp");
169136
chooser.setDialogTitle("Save shapefile");
@@ -176,12 +143,52 @@ private static File getNewShapeFile() {
176143
}
177144

178145
File shapeFile = chooser.getSelectedFile();
179-
if (shapeFile.equals(filePath)) {
180-
System.out.println("Error: cannot replace " + filePath);
181-
System.exit(0);
182-
}
183146

184147
return shapeFile;
185148
}
186149

150+
private static ShapefileDataStore setDataStoreParams(ShapefileDataStoreFactory dataStoreFactory, Map<String, Serializable> params, File shapeFile, SimpleFeatureType CITY) throws Exception {
151+
params.put("url", shapeFile.toURI()
152+
.toURL());
153+
params.put("create spatial index", Boolean.TRUE);
154+
155+
ShapefileDataStore dataStore = (ShapefileDataStore) dataStoreFactory.createNewDataStore(params);
156+
dataStore.createSchema(CITY);
157+
158+
return dataStore;
159+
}
160+
161+
private static void writeToFile(ShapefileDataStore dataStore, DefaultFeatureCollection collection) throws Exception {
162+
163+
// If you decide to use the TYPE type and create a Data Store with it,
164+
// You will need to uncomment this line to set the Coordinate Reference System
165+
// newDataStore.forceSchemaCRS(DefaultGeographicCRS.WGS84);
166+
167+
Transaction transaction = new DefaultTransaction("create");
168+
169+
String typeName = dataStore.getTypeNames()[0];
170+
SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName);
171+
172+
if (featureSource instanceof SimpleFeatureStore) {
173+
SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;
174+
175+
featureStore.setTransaction(transaction);
176+
try {
177+
featureStore.addFeatures(collection);
178+
transaction.commit();
179+
180+
} catch (Exception problem) {
181+
problem.printStackTrace();
182+
transaction.rollback();
183+
184+
} finally {
185+
transaction.close();
186+
}
187+
System.exit(0); // success!
188+
} else {
189+
System.out.println(typeName + " does not support read/write access");
190+
System.exit(1);
191+
}
192+
}
193+
187194
}

0 commit comments

Comments
 (0)