Skip to content

Commit a11b941

Browse files
committed
private constructors,static factory instantiations
1 parent 291cf80 commit a11b941

File tree

9 files changed

+104
-18
lines changed

9 files changed

+104
-18
lines changed

build.gradle

Lines changed: 72 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
apply plugin: 'groovy'
22
apply plugin: 'eclipse'
33
apply plugin : 'idea'
4-
4+
apply plugin: 'maven'
5+
apply plugin: 'signing'
6+
7+
58
sourceCompatibility = 1.8
9+
group ="in.ankushs"
10+
archivesBaseName = "dbip"
611
version = '1.0'
712

813
jar {
9-
baseName = "Java DbIp"
14+
baseName = "Java DB-IP"
1015
manifest {
1116
attributes 'Implementation-Title': 'Gradle Quickstart',
1217
'Implementation-Version': version
@@ -44,11 +49,73 @@ eclipse {
4449
}
4550
}
4651

52+
53+
task javadocJar(type: Jar) {
54+
classifier = 'javadoc'
55+
from javadoc
56+
}
57+
58+
task sourcesJar(type: Jar) {
59+
classifier = 'sources'
60+
from sourceSets.main.allSource
61+
}
62+
63+
artifacts {
64+
archives javadocJar, sourcesJar
65+
}
66+
67+
signing {
68+
sign configurations.archives
69+
}
70+
4771

4872
uploadArchives {
4973
repositories {
50-
flatDir {
51-
dirs 'repos'
52-
}
74+
mavenDeployer{
75+
beforeDeployment{MavenDeployment deployment->
76+
signing.signPom(deployment)
77+
}
78+
79+
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2") {
80+
authentication(userName: ossrhUsername, password: ossrhPassword)
81+
}
82+
83+
pom{
84+
project{
85+
name 'Java DbIP'
86+
description 'A Java library for the DB-IP IP address to city dataset '
87+
packaging 'jar'
88+
url 'https://github.com/ankushs92/Java-DB-IP'
89+
inceptionYear '2016'
90+
91+
scm {
92+
connection 'scm:git:git@github.com:ankushs92/Java-DB-IP.git'
93+
developerConnection 'scm:git:git@github.com:ankushs92/Java-DB-IP.git'
94+
url 'git@github.com:ankushs92/Java-DB-IP.git'
95+
}
96+
97+
licenses {
98+
license {
99+
name 'The MIT License'
100+
url 'https://github.com/ankushs92/Java-DB-IP/blob/master/LICENSE.md'
101+
}
102+
}
103+
developers {
104+
developer {
105+
name 'Ankush Sharma'
106+
email 'ankush20058@gmail.com'
107+
}
108+
}
109+
issueManagement{
110+
system 'Github'
111+
url 'https://github.com/ankushs92/Java-DB-IP/issues'
112+
113+
}
114+
}
115+
}
116+
flatDir {
117+
dirs 'repos'
118+
}
53119
}
120+
}
54121
}

gradle.properties

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#signing.keyId=
2+
#signing.password=
3+
#signing.secretKeyRingFile=
4+
#
5+
#ossrhUsername=
6+
#ossrhPassword=

src/main/java/in/ankushs/dbip/api/DbIpClient.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ public final class DbIpClient {
2828
* The dbip-city-latest.csv.gz file
2929
* */
3030
private final File file ;
31-
32-
private final GeoEntityLookupService lookupService = new GeoEntityLookupServiceImpl();
31+
//Singleton
32+
private final GeoEntityLookupService lookupService = GeoEntityLookupServiceImpl.getInstance();
3333

3434
/*
3535
* Indicates whether the file has been loaded into the JVM.
@@ -50,7 +50,7 @@ public DbIpClient(final File gzip){
5050
if(!flag){
5151
flag = true;
5252
logger.info("Loading db ip into repository ");
53-
new ResourceImporter().load(gzip);
53+
ResourceImporter.getInstance().load(gzip);
5454
logger.info("Loading finished");
5555
}
5656
else{

src/main/java/in/ankushs/dbip/importer/ResourceImporter.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import in.ankushs.dbip.model.GeoAttributes;
1919
import in.ankushs.dbip.model.GeoAttributesImpl;
20+
import in.ankushs.dbip.parser.CsvParser;
2021
import in.ankushs.dbip.parser.CsvParserImpl;
2122
import in.ankushs.dbip.repository.DbIpRepository;
2223
import in.ankushs.dbip.repository.JavaMapDbIpRepositoryImpl;
@@ -31,10 +32,13 @@
3132
public final class ResourceImporter {
3233

3334
private static final Logger logger = LoggerFactory.getLogger(ResourceImporter.class);
34-
private final DbIpRepository repository = new JavaMapDbIpRepositoryImpl();
35-
private ResourceImporter instance = null;
35+
private final DbIpRepository repository = JavaMapDbIpRepositoryImpl.getInstance();
36+
private final CsvParser csvParser = CsvParserImpl.getInstance();
37+
private static ResourceImporter instance = null;
3638

37-
public ResourceImporter getInstance() {
39+
private ResourceImporter(){}
40+
41+
public static ResourceImporter getInstance() {
3842
if (instance == null) {
3943
return new ResourceImporter();
4044
}
@@ -66,7 +70,7 @@ public void load(final File file) {
6670
int i = 0;
6771
while ((line = reader.readLine()) != null) {
6872
i++;
69-
final String[] array = new CsvParserImpl().parseRecord(line);
73+
final String[] array = csvParser.parseRecord(line);
7074
final GeoAttributes geoAttributes = new GeoAttributesImpl.Builder().withCity(array[4])
7175
.withCountry(CountryResolver.resolveToFullName(array[2])).withProvince(array[3])
7276
.withEndIp(InetAddresses.forString(array[1])).withStartIp(InetAddresses.forString(array[0]))

src/main/java/in/ankushs/dbip/lookup/GeoEntityLookupServiceImpl.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@
1515
public final class GeoEntityLookupServiceImpl implements GeoEntityLookupService {
1616

1717
private static final String UNKNOWN = "Unknown";
18-
private final DbIpRepository repository = new JavaMapDbIpRepositoryImpl();
1918

20-
private GeoEntityLookupServiceImpl instance = null;
19+
private final DbIpRepository repository = JavaMapDbIpRepositoryImpl.getInstance();
2120

22-
public GeoEntityLookupServiceImpl getInstance(){
21+
private static GeoEntityLookupServiceImpl instance = null;
22+
23+
private GeoEntityLookupServiceImpl(){}
24+
public static GeoEntityLookupServiceImpl getInstance(){
2325
if(instance==null){
24-
return this;
26+
return new GeoEntityLookupServiceImpl();
2527
}
2628
return instance;
2729
}
@@ -37,4 +39,8 @@ public GeoEntity lookup(final InetAddress inetAddress) {
3739
}
3840
return geoEntity;
3941
}
42+
43+
public static void main(String[] args) {
44+
GeoEntityLookupService g1 = getInstance();
45+
}
4046
}

src/main/java/in/ankushs/dbip/parser/CsvParserImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public final class CsvParserImpl implements CsvParser {
88

99
public static CsvParserImpl parser = null;
1010

11+
private CsvParserImpl(){}
1112
public static CsvParserImpl getInstance(){
1213
if(parser==null){
1314
return new CsvParserImpl();

src/main/java/in/ankushs/dbip/repository/JavaMapDbIpRepositoryImpl.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
public final class JavaMapDbIpRepositoryImpl implements DbIpRepository {
2020

2121
private static JavaMapDbIpRepositoryImpl instance = null;
22+
23+
private JavaMapDbIpRepositoryImpl(){}
2224
public static JavaMapDbIpRepositoryImpl getInstance(){
2325
if(instance==null){
2426
return new JavaMapDbIpRepositoryImpl();

src/main/java/in/ankushs/dbip/utils/CountryResolver.java

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

66
public final class CountryResolver {
77
private static final Map<String, String> countries = new HashMap<String,String>();
8-
8+
private CountryResolver(){}
99
static{
1010
countries.put("AF", "Afghanistan");
1111
countries.put("AL", "Albania");

src/main/java/in/ankushs/dbip/utils/GzipUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* @author Ankush Sharma
1212
*/
1313
public class GzipUtils {
14-
14+
private GzipUtils(){}
1515
/**
1616
* Checks if the file is gzipped.
1717
* @param file The file to be tested

0 commit comments

Comments
 (0)