-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from Shonminh/shonminh/bugfix/issue-16
Shonminh/bugfix/issue 16
- Loading branch information
Showing
8 changed files
with
156 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ plugins { | |
} | ||
|
||
group 'org.shonminh.helper' | ||
version '1.4.1' | ||
version '1.4.2' | ||
|
||
sourceCompatibility = 1.8 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.shonminh.helper.sql; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
public class Header { | ||
private List<String> dependencyPackageList; | ||
private Set<String> existDependencySet; | ||
|
||
public Header() { | ||
this.dependencyPackageList = new ArrayList<>(); | ||
this.existDependencySet = new HashSet<>(); | ||
} | ||
|
||
public void appendDependencyPackage(String dependencyPackageName) { | ||
if (this.existDependencySet.contains(dependencyPackageName)) { | ||
return; | ||
} | ||
this.existDependencySet.add(dependencyPackageName); | ||
|
||
List<String> arrayList = this.getDependencyPackageList(); | ||
arrayList.add(dependencyPackageName); | ||
arrayList.sort(String::compareTo); | ||
this.setDependencyPackageList(arrayList); | ||
|
||
} | ||
|
||
public void appendDependencyPackageList(List<String> dependencyPackageList) { | ||
List<String> arrayList = new ArrayList<>(this.getDependencyPackageList()); | ||
for (String packageName : dependencyPackageList) { | ||
if (this.existDependencySet.contains(packageName)) { | ||
continue; | ||
} | ||
arrayList.add(packageName); | ||
} | ||
arrayList.sort(String::compareTo); | ||
this.setDependencyPackageList(arrayList); | ||
} | ||
|
||
|
||
public List<String> getDependencyPackageList() { | ||
return dependencyPackageList; | ||
} | ||
|
||
public void setDependencyPackageList(List<String> dependencyPackageList) { | ||
this.dependencyPackageList = dependencyPackageList; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
helper/src/main/java/org/shonminh/helper/util/HeaderUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.shonminh.helper.util; | ||
|
||
import java.util.List; | ||
|
||
public class HeaderUtil { | ||
public static String getDependencyPackageName(String goType) { | ||
if ("timestamp".equals(goType)) { | ||
return "time"; | ||
} | ||
return null; | ||
} | ||
|
||
public static String getHeaderCodes(List<String> dependencyPackageList) { | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append("package model\n\n"); | ||
if (dependencyPackageList == null || dependencyPackageList.size() == 0) { | ||
return sb.toString(); | ||
} | ||
sb.append("import (\n"); | ||
for (String dependencyName : | ||
dependencyPackageList) { | ||
sb.append("\t"); | ||
sb.append("\""); | ||
sb.append(dependencyName); | ||
sb.append("\""); | ||
sb.append("\n"); | ||
} | ||
sb.append(")\n\n"); | ||
return sb.toString(); | ||
} | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
helper/src/test/java/org/shonminh/helper/sql/HeaderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.shonminh.helper.sql; | ||
|
||
import org.junit.Test; | ||
import org.shonminh.helper.util.HeaderUtil; | ||
|
||
import java.util.List; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class HeaderTest { | ||
|
||
@Test | ||
public void appendDependencyPackage() { | ||
Header header = new Header(); | ||
header.appendDependencyPackage("demo.b"); | ||
header.appendDependencyPackage("demo.a"); | ||
List<String> dependencyPackageList = header.getDependencyPackageList(); | ||
assertEquals(2, dependencyPackageList.size()); | ||
assertEquals("demo.a", dependencyPackageList.get(0)); | ||
assertEquals("demo.b", dependencyPackageList.get(1)); | ||
} | ||
|
||
@Test | ||
public void getHeaderCodes() { | ||
Header header = new Header(); | ||
header.appendDependencyPackage("demo.a"); | ||
header.appendDependencyPackage("demo.b"); | ||
String headerCodes = HeaderUtil.getHeaderCodes(header.getDependencyPackageList()); | ||
assertEquals("package model\n" + | ||
"\n" + | ||
"import (\n" + | ||
"\t\"demo.a\"\n" + | ||
"\t\"demo.b\"\n" + | ||
")\n" + | ||
"\n", headerCodes); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters