Merge branch 'current' of https://github.com/cwiki-us-docs/java-tutorials into HEAD
# Conflicts: # .gitignore # .idea/compiler.xml # .idea/encodings.xml # .idea/vcs.xml # pom.xml # src/main/java/com/ossez/lang/tutorial/overview/HelloWorld.java
This commit is contained in:
parent
76c7f1b984
commit
fb82d4b70f
|
@ -1,3 +1,4 @@
|
|||
<<<<<<< HEAD
|
||||
### Gradle ###
|
||||
.gradle
|
||||
build/
|
||||
|
@ -233,3 +234,93 @@ fabric.properties
|
|||
|
||||
# Sonarlint plugin
|
||||
.idea/sonarlint
|
||||
=======
|
||||
# Binaries
|
||||
*.7z
|
||||
*.dmg
|
||||
*.gz
|
||||
*.iso
|
||||
*.jar
|
||||
*.rar
|
||||
*.tar
|
||||
*.zip
|
||||
*.war
|
||||
*.ear
|
||||
*.sar
|
||||
*.class
|
||||
|
||||
# Maven
|
||||
target/
|
||||
|
||||
# eclipse project file
|
||||
.settings/
|
||||
.classpath
|
||||
.project
|
||||
|
||||
|
||||
# IntelliJ project files
|
||||
*.iml
|
||||
*.iws
|
||||
*.ipr
|
||||
.idea/
|
||||
|
||||
|
||||
|
||||
# NetBeans specific
|
||||
nbproject/private/
|
||||
build/
|
||||
nbbuild/
|
||||
dist/
|
||||
nbdist/
|
||||
nbactions.xml
|
||||
nb-configuration.xml
|
||||
|
||||
# Windows image file caches
|
||||
Thumbs.db
|
||||
ehthumbs.db
|
||||
|
||||
# Folder config file
|
||||
Desktop.ini
|
||||
|
||||
# Recycle Bin used on file shares
|
||||
$RECYCLE.BIN/
|
||||
|
||||
# Windows Installer files
|
||||
*.cab
|
||||
*.msi
|
||||
*.msm
|
||||
*.msp
|
||||
|
||||
# Windows shortcuts
|
||||
*.lnk
|
||||
|
||||
# =========================
|
||||
# Operating System Files
|
||||
# =========================
|
||||
|
||||
# OSX
|
||||
# =========================
|
||||
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
# Thumbnails
|
||||
._*
|
||||
|
||||
# Files that might appear in the root of a volume
|
||||
.DocumentRevisions-V100
|
||||
.fseventsd
|
||||
.Spotlight-V100
|
||||
.TemporaryItems
|
||||
.Trashes
|
||||
.VolumeIcon.icns
|
||||
|
||||
# Directories potentially created on remote AFP share
|
||||
.AppleDB
|
||||
.AppleDesktop
|
||||
Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
|
||||
>>>>>>> 361e407d91e00158295aadeaca0a91d84a534820
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Datasource local storage ignored files
|
||||
/../../../../../../:\WorkDir\GitHub\cwiki-us-demo\java-tutorials\.idea/dataSources/
|
||||
/dataSources.local.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
|
@ -1 +0,0 @@
|
|||
parent-modules
|
|
@ -1,7 +0,0 @@
|
|||
<component name="ProjectCodeStyleConfiguration">
|
||||
<code_scheme name="Project" version="173">
|
||||
<ScalaCodeStyleSettings>
|
||||
<option name="MULTILINE_STRING_CLOSING_QUOTES_ON_NEW_LINE" value="true" />
|
||||
</ScalaCodeStyleSettings>
|
||||
</code_scheme>
|
||||
</component>
|
|
@ -1,5 +0,0 @@
|
|||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||
</state>
|
||||
</component>
|
|
@ -1,15 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<annotationProcessing>
|
||||
<profile name="Maven default annotation processors profile" enabled="true">
|
||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||
<outputRelativeToContentRoot value="true" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
<bytecodeTargetLevel>
|
||||
<module name="lang-tutorial" target="1.8" />
|
||||
</bytecodeTargetLevel>
|
||||
</component>
|
||||
</project>
|
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding">
|
||||
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
|
@ -1,20 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RemoteRepositoriesConfiguration">
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Central Repository" />
|
||||
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Maven Central repository" />
|
||||
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="jboss.community" />
|
||||
<option name="name" value="JBoss Community repository" />
|
||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||
</remote-repository>
|
||||
</component>
|
||||
</project>
|
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
66
README.md
66
README.md
|
@ -1,60 +1,12 @@
|
|||
**UPDATE**: The price of "Learn Spring Security OAuth" will permanently change on the 11th of December, along with the upcoming OAuth2 material: http://bit.ly/github-lss
|
||||
|
||||
CWIKI.US
|
||||
==============================
|
||||
我们专注于开源信息的分享和文档的更新,并根据需求提供定制和软件开发咨询服务。<br/>
|
||||
**[>> 访问 CWIKI.US](https://www.cwiki.us/)**
|
||||
|
||||
|
||||
The Courses
|
||||
==============================
|
||||
|
||||
|
||||
Here's the new "Learn Spring" course: <br/>
|
||||
**[>> LEARN SPRING - THE MASTER CLASS](https://www.baeldung.com/learn-spring-course?utm_source=github&utm_medium=social&utm_content=tutorials&utm_campaign=ls#master-class)**
|
||||
|
||||
Here's the Master Class of "REST With Spring" (along with the new announced Boot 2 material): <br/>
|
||||
**[>> THE REST WITH SPRING - MASTER CLASS](https://www.baeldung.com/rest-with-spring-course?utm_source=github&utm_medium=social&utm_content=tutorials&utm_campaign=rws#master-class)**
|
||||
|
||||
And here's the Master Class of "Learn Spring Security": <br/>
|
||||
**[>> LEARN SPRING SECURITY - MASTER CLASS](https://www.baeldung.com/learn-spring-security-course?utm_source=github&utm_medium=social&utm_content=tutorials&utm_campaign=lss#master-class)**
|
||||
|
||||
|
||||
|
||||
Java and Spring Tutorials
|
||||
================
|
||||
|
||||
This project is **a collection of small and focused tutorials** - each covering a single and well defined area of development in the Java ecosystem.
|
||||
A strong focus of these is, of course, the Spring Framework - Spring, Spring Boot and Spring Security.
|
||||
In additional to Spring, the modules here are covering a number of aspects in Java.
|
||||
|
||||
|
||||
构建(build)项目
|
||||
====================
|
||||
如果你希望运行一个完整的构建(build),请运行命令:`mvn clean install`
|
||||
|
||||
|
||||
构建(Building)一个单独模块(module)
|
||||
====================
|
||||
如果你希望构建一个特定的模块(module)的话,请在模块目录中运行命令:`mvn clean install`
|
||||
|
||||
|
||||
运行一个 Spring Boot 模块
|
||||
====================
|
||||
如果你希望运行一个 Spring Boot 模块(module)请在模块目录中(module directory)运行命令: `mvn spring-boot:run`
|
||||
|
||||
|
||||
与 IDE 协同进行工作
|
||||
====================
|
||||
本仓库中包含有大量的模块。
|
||||
When you're working with an individual module, there's no need to import all of them (or build all of them) - you can simply import that particular module in either Eclipse or IntelliJ.
|
||||
|
||||
|
||||
运行测试
|
||||
=============
|
||||
运行 `mvn clean install` 将会在模块中运行单元测试(unit tests)。
|
||||
如果你希望运行整合测试(integration tests),请使用命令 `mvn clean install -Pintegration-lite-first`
|
||||
|
||||
<p align="center">
|
||||
<a href="https://www.hackerrank.com/huyuchengus">
|
||||
<img height=85 src="https://avatars1.githubusercontent.com/u/45009982?s=200&v=4">
|
||||
</a>
|
||||
<br>提供 CWIKI.US 项目中使用的代码
|
||||
</p>
|
||||
|
||||
所有的 Java 代码使用的是 JDK 8。
|
||||
|
||||
你可以通过单击下面连接后访问我们网站,并且访问我们提供的最新有关 Java 的开发资料。
|
||||
|
||||
* [概述](https://www.cwiki.us/pages/viewpage.action?pageId=37492282)
|
|
@ -0,0 +1,37 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
|
||||
<output url="file://$MODULE_DIR$/target/classes" />
|
||||
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.21" level="project" />
|
||||
<orderEntry type="library" name="Maven: ch.qos.logback:logback-classic:1.1.7" level="project" />
|
||||
<orderEntry type="library" name="Maven: ch.qos.logback:logback-core:1.1.7" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.slf4j:jcl-over-slf4j:1.7.21" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.11" level="project" />
|
||||
<orderEntry type="library" name="Maven: commons-cli:commons-cli:1.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.commons:commons-math3:3.6.1" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-api:5.7.0" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.apiguardian:apiguardian-api:1.1.0" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.opentest4j:opentest4j:1.2.0" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-commons:1.7.0" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-engine:5.7.0" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-engine:1.7.0" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-library:1.3" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-all:1.3" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.mockito:mockito-core:2.21.0" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: net.bytebuddy:byte-buddy:1.8.15" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: net.bytebuddy:byte-buddy-agent:1.8.15" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.objenesis:objenesis:2.6" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.apache.maven.surefire:surefire-logger-api:2.21.0" level="project" />
|
||||
</component>
|
||||
</module>
|
54
pom.xml
54
pom.xml
|
@ -1,6 +1,15 @@
|
|||
<<<<<<< HEAD
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
=======
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
>>>>>>> 361e407d91e00158295aadeaca0a91d84a534820
|
||||
<groupId>com.ossez</groupId>
|
||||
<artifactId>lang-tutorial</artifactId>
|
||||
<version>0.0.1</version>
|
||||
|
@ -38,17 +47,26 @@
|
|||
|
||||
|
||||
<dependencies>
|
||||
<<<<<<< HEAD
|
||||
<!-- OSSEZ COMMON -->
|
||||
<dependency>
|
||||
<groupId>com.ossez</groupId>
|
||||
<artifactId>reoc-common</artifactId>
|
||||
<version>0.0.1</version>
|
||||
=======
|
||||
<!-- LOG -->
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-slf4j-impl</artifactId>
|
||||
<version>2.11.0</version>
|
||||
>>>>>>> 361e407d91e00158295aadeaca0a91d84a534820
|
||||
</dependency>
|
||||
|
||||
<!-- APACHE COMMONS -->
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-compress</artifactId>
|
||||
<<<<<<< HEAD
|
||||
<version>1.10</version>
|
||||
</dependency>
|
||||
|
||||
|
@ -57,6 +75,17 @@
|
|||
<artifactId>velocity</artifactId>
|
||||
<version>1.6</version>
|
||||
</dependency>
|
||||
=======
|
||||
<version>1.19</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-math3</artifactId>
|
||||
<version>3.6.1</version>
|
||||
</dependency>
|
||||
|
||||
>>>>>>> 361e407d91e00158295aadeaca0a91d84a534820
|
||||
<dependency>
|
||||
<groupId>antlr</groupId>
|
||||
<artifactId>antlr</artifactId>
|
||||
|
@ -174,6 +203,7 @@
|
|||
<version>1.3.2</version>
|
||||
</dependency>
|
||||
|
||||
<<<<<<< HEAD
|
||||
<!-- RETS -->
|
||||
<dependency>
|
||||
<groupId>com.ossez.rets-io</groupId>
|
||||
|
@ -181,6 +211,24 @@
|
|||
<version>0.1.0</version>
|
||||
</dependency>
|
||||
|
||||
=======
|
||||
<!-- TESTS -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
>>>>>>> 361e407d91e00158295aadeaca0a91d84a534820
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -248,4 +296,8 @@
|
|||
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
<<<<<<< HEAD
|
||||
</project>
|
||||
=======
|
||||
</project>
|
||||
>>>>>>> 361e407d91e00158295aadeaca0a91d84a534820
|
||||
|
|
|
@ -0,0 +1,91 @@
|
|||
package com.ossez.lang.tutorial;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.commons.cli.CommandLine;
|
||||
import org.apache.commons.cli.CommandLineParser;
|
||||
import org.apache.commons.cli.GnuParser;
|
||||
import org.apache.commons.cli.Options;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class Main {
|
||||
private static final Logger logger = LoggerFactory.getLogger(Main.class);
|
||||
|
||||
private static Options options = new Options();
|
||||
private static Properties properties = new Properties();
|
||||
|
||||
private static CommandLine cl = null;
|
||||
|
||||
private static boolean dryRun = false;
|
||||
private static int limit = 0;
|
||||
private static boolean force = false;
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
// get the idx feed properties file
|
||||
Main.parseProperties();
|
||||
|
||||
// load console options
|
||||
Main.parseCommandLine(args);
|
||||
|
||||
logger.debug("Starting feeds...");
|
||||
System.out.println("starting feeds...");
|
||||
|
||||
// execute the feeds
|
||||
Main.executeFeeds();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the feeds specified in the feeds.properties file.
|
||||
*/
|
||||
private static void executeFeeds() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the properties file to get a list of all feeds.
|
||||
*/
|
||||
private static void parseProperties() {
|
||||
try {
|
||||
// load the properties file
|
||||
logger.debug("Parsing properties");
|
||||
Main.properties.load(Main.class.getClassLoader().getResourceAsStream("rets.properties"));
|
||||
|
||||
// load the feeds
|
||||
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
logger.error("Could not parse feed properties", ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles creation of console options.
|
||||
*/
|
||||
private static void parseCommandLine(String[] args) {
|
||||
|
||||
// parse command line options
|
||||
CommandLineParser parser = new GnuParser();
|
||||
|
||||
try {
|
||||
Main.cl = parser.parse(Main.options, args);
|
||||
|
||||
// get the dry run option
|
||||
Main.dryRun = Main.cl.hasOption("d");
|
||||
logger.trace("Value of dryRun: " + dryRun);
|
||||
|
||||
// get the limit option
|
||||
// Main.limit = Utility.parseInt(Main.cl.getOptionValue("l", "0"));
|
||||
logger.trace("Value of limit: " + Main.limit);
|
||||
|
||||
// get the force option
|
||||
Main.force = Main.cl.hasOption("u");
|
||||
logger.trace("Value of force: " + Main.force);
|
||||
} catch (Exception ex) {
|
||||
logger.error("An error ocurred parsing command line arguments", ex);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.ossez.lang.tutorial.models;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author YuCheng
|
||||
*
|
||||
*/
|
||||
public class ListNode {
|
||||
public int val;
|
||||
public ListNode next;
|
||||
|
||||
public ListNode(int x) {
|
||||
val = x;
|
||||
next = null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.ossez.lang.tutorial.models;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author YuCheng
|
||||
*
|
||||
*/
|
||||
public class TreeNode {
|
||||
public int val;
|
||||
public TreeNode left, right;
|
||||
|
||||
public TreeNode(int val) {
|
||||
this.val = val;
|
||||
this.left = this.right = null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package com.ossez.lang.tutorial.objplusclass;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author YuCheng
|
||||
*
|
||||
*/
|
||||
public class CreateObject {
|
||||
public CreateObject(String name) {
|
||||
// This constructor has one parameter, name
|
||||
System.out.println("小狗的名字是: " + name);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Following statement would create an object myPuppy
|
||||
CreateObject myPuppy = new CreateObject("Tomcat");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package com.ossez.lang.tutorial.overview;
|
||||
|
||||
/**
|
||||
* Java Tutorial
|
||||
*
|
||||
* @author YuCheng
|
||||
*
|
||||
*/
|
||||
class FreshJuice {
|
||||
enum FreshJuiceSize {
|
||||
SMALL, MEDIUM, LARGE
|
||||
}
|
||||
|
||||
FreshJuiceSize size;
|
||||
}
|
||||
|
||||
public class FreshJuiceEnums {
|
||||
public static void main(String[] args) {
|
||||
FreshJuice juice = new FreshJuice();
|
||||
juice.size = FreshJuice.FreshJuiceSize.MEDIUM;
|
||||
}
|
||||
}
|
|
@ -3,11 +3,25 @@ package com.ossez.lang.tutorial.overview;
|
|||
/**
|
||||
* Java Tutorial
|
||||
*
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
* This is my first java program. This will print 'Hello World' as the output This is an example of multi-line comments
|
||||
*
|
||||
>>>>>>> 361e407d91e00158295aadeaca0a91d84a534820
|
||||
* @author YuCheng
|
||||
*
|
||||
*/
|
||||
public class HelloWorld {
|
||||
public static void main(String[] args) {
|
||||
<<<<<<< HEAD
|
||||
System.out.println("Hello World");
|
||||
}
|
||||
}
|
||||
}
|
||||
=======
|
||||
// This is an example of single line comment
|
||||
/* This is also an example of single line comment. */
|
||||
|
||||
System.out.println("Hello World");
|
||||
}
|
||||
}
|
||||
>>>>>>> 361e407d91e00158295aadeaca0a91d84a534820
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
package com.ossez.lang.tutorial.usecases;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* variable arguments use case
|
||||
*/
|
||||
public class VarargsCase {
|
||||
private static final Logger logger = LoggerFactory.getLogger(VarargsCase.class);
|
||||
|
||||
/**
|
||||
* sumVarargs
|
||||
*
|
||||
* @param intArrays
|
||||
* @return
|
||||
*/
|
||||
static int sumVarargs(int... intArrays) {
|
||||
int sum, i;
|
||||
sum = 0;
|
||||
for (i = 0; i < intArrays.length; i++) {
|
||||
sum += intArrays[i];
|
||||
}
|
||||
return (sum);
|
||||
}
|
||||
|
||||
/**
|
||||
* Main Function
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String args[]) {
|
||||
int sum = 0;
|
||||
sum = sumVarargs(new int[]{10, 12, 33, 7});
|
||||
logger.debug("The Sum of the arrays: {}", sum);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package com.ossez.lang.tutorial.utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.ossez.lang.tutorial.models.TreeNode;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author YuCheng
|
||||
*
|
||||
*/
|
||||
public class TreeUtils {
|
||||
|
||||
public static TreeNode initTree(String data) {
|
||||
// NULL CHECK
|
||||
if (data.equals("{}")) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ArrayList<TreeNode> treeList = new ArrayList<TreeNode>();
|
||||
|
||||
data = data.replace("{", "");
|
||||
data = data.replace("}", "");
|
||||
String[] vals = data.split(",");
|
||||
|
||||
// INSERT ROOT
|
||||
TreeNode root = new TreeNode(Integer.parseInt(vals[0]));
|
||||
treeList.add(root);
|
||||
|
||||
int index = 0;
|
||||
boolean isLeftChild = true;
|
||||
for (int i = 1; i < vals.length; i++) {
|
||||
if (!vals[i].equals("#")) {
|
||||
TreeNode node = new TreeNode(Integer.parseInt(vals[i]));
|
||||
if (isLeftChild) {
|
||||
treeList.get(index).left = node;
|
||||
} else {
|
||||
treeList.get(index).right = node;
|
||||
}
|
||||
treeList.add(node);
|
||||
}
|
||||
|
||||
// LEVEL
|
||||
if (!isLeftChild) {
|
||||
index++;
|
||||
}
|
||||
|
||||
// MOVE TO RIGHT OR NEXT LEVEL
|
||||
isLeftChild = !isLeftChild;
|
||||
}
|
||||
|
||||
return root;
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,97 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE RelativeLayout>
|
||||
<Configuration status="WARN">
|
||||
|
||||
<Properties>
|
||||
<Property name="baseDir">/home/logs/reoc/services/</Property>
|
||||
</Properties>
|
||||
|
||||
<Appenders>
|
||||
<!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
<!-- C O N S O L E - A P P E N D E R -->
|
||||
<!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
<Console name="CONSOLE" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="%-d{yyyy/MM/dd HH:mm:ss} %-5p [%c] - %m%n" />
|
||||
<ThresholdFilter level="TRACE" onMatch="ACCEPT" onMismatch="DENY" />
|
||||
</Console>
|
||||
|
||||
<!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
<!-- D E B U G _ F I L E - A P P E N D E R -->
|
||||
<!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
<RollingFile name="FILE_DEBUG" append="true" fileName="${baseDir}/services_debug.log" filePattern="${baseDir}/$${date:yyyy-MM}/services-debug-%d{yyyy-MM-dd}-%i.log.gz">
|
||||
<ThresholdFilter level="DEBUG" onMatch="ACCEPT" onMismatch="DENY" />
|
||||
<PatternLayout>
|
||||
<pattern>%-d{yyyy/MM/dd HH:mm:ss} %-5p [%c] - %m%n</pattern>
|
||||
</PatternLayout>
|
||||
<Policies>
|
||||
<TimeBasedTriggeringPolicy />
|
||||
<SizeBasedTriggeringPolicy size="250 MB"></SizeBasedTriggeringPolicy>
|
||||
</Policies>
|
||||
<DefaultRolloverStrategy max="12" />
|
||||
</RollingFile>
|
||||
|
||||
<!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
<!-- I N F O _ F I L E - A P P E N D E R -->
|
||||
<!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
<RollingFile name="FILE_INFO" append="true" fileName="${baseDir}/services_info.log" filePattern="${baseDir}/$${date:yyyy-MM}/services-info-%d{yyyy-MM-dd}.log.gz">
|
||||
<ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY" />
|
||||
<PatternLayout>
|
||||
<pattern>%-d{yyyy/MM/dd HH:mm:ss} %-5p [%c] - %m%n</pattern>
|
||||
</PatternLayout>
|
||||
<Policies>
|
||||
<TimeBasedTriggeringPolicy />
|
||||
<SizeBasedTriggeringPolicy size="250 MB"></SizeBasedTriggeringPolicy>
|
||||
</Policies>
|
||||
<DefaultRolloverStrategy max="12" />
|
||||
</RollingFile>
|
||||
|
||||
<!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
<!-- F I L E _ W A R N - A P P E N D E R -->
|
||||
<!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
<RollingFile name="FILE_WARN" append="true" fileName="${baseDir}/services_info.log" filePattern="${baseDir}/$${date:yyyy-MM}/services-warn-%d{yyyy-MM-dd}.log.gz">
|
||||
<ThresholdFilter level="WARN" onMatch="ACCEPT" onMismatch="DENY" />
|
||||
<PatternLayout>
|
||||
<pattern>%-d{yyyy/MM/dd HH:mm:ss} %-5p [%c] - %m%n</pattern>
|
||||
</PatternLayout>
|
||||
<Policies>
|
||||
<TimeBasedTriggeringPolicy />
|
||||
<SizeBasedTriggeringPolicy size="250 MB"></SizeBasedTriggeringPolicy>
|
||||
</Policies>
|
||||
<DefaultRolloverStrategy max="12" />
|
||||
</RollingFile>
|
||||
|
||||
<!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
<!-- F I L E _ E R R O R - A P P E N D E R -->
|
||||
<!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
<RollingFile name="FILE_ERROR" append="true" fileName="${baseDir}/services_error.log" filePattern="${baseDir}/$${date:yyyy-MM}/services-error-%d{yyyy-MM-dd}.log.gz">
|
||||
<ThresholdFilter level="ERROR" onMatch="ACCEPT" onMismatch="DENY" />
|
||||
<PatternLayout>
|
||||
<pattern>%-d{yyyy/MM/dd HH:mm:ss} %-5p [%c] - %m%n</pattern>
|
||||
</PatternLayout>
|
||||
<Policies>
|
||||
<TimeBasedTriggeringPolicy />
|
||||
<SizeBasedTriggeringPolicy size="250 MB"></SizeBasedTriggeringPolicy>
|
||||
</Policies>
|
||||
<DefaultRolloverStrategy max="12" />
|
||||
</RollingFile>
|
||||
</Appenders>
|
||||
|
||||
<!-- LOGGERS -->
|
||||
<Loggers>
|
||||
|
||||
<Logger name="com.ossez" level="TRACE" additivity="false">
|
||||
<AppenderRef ref="CONSOLE" level="DEBUG" />
|
||||
<AppenderRef ref="FILE_DEBUG" level="DEBUG" />
|
||||
<AppenderRef ref="FILE_INFO" level="INFO" />
|
||||
<AppenderRef ref="FILE_WARN" level="WARN" />
|
||||
<AppenderRef ref="FILE_ERROR" level="ERROR" />
|
||||
</Logger>
|
||||
|
||||
|
||||
<root level="TRACE">
|
||||
|
||||
</root>
|
||||
|
||||
</Loggers>
|
||||
|
||||
</Configuration>
|
|
@ -0,0 +1,36 @@
|
|||
package com.ossez.lang.tutorial.tests;
|
||||
|
||||
import org.apache.commons.math3.util.FastMath;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author YuCheng
|
||||
*
|
||||
*/
|
||||
public class BitOperationTest {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(BitOperationTest.class);
|
||||
|
||||
/**
|
||||
* 35 https://www.lintcode.com/problem/reverse-linked-list/description
|
||||
*/
|
||||
@Test
|
||||
public void testInt2Bit() {
|
||||
logger.debug("BEGIN");
|
||||
System.out.println(Integer.toBinaryString(5));
|
||||
System.out.println(Integer.toBinaryString(2));
|
||||
|
||||
System.out.println(Integer.toBinaryString(2 << 2));
|
||||
|
||||
System.out.println(Integer.parseInt(Integer.toBinaryString(2 << 2), 2));
|
||||
|
||||
System.out.println(5 / 3);
|
||||
System.out.println(5 % 3);
|
||||
FastMath.pow(2, 3);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,137 @@
|
|||
package com.ossez.lang.tutorial.tests;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.ossez.edtestbank.common.dao.Factory;
|
||||
import com.ossez.edtestbank.common.dao.factories.PostFactory;
|
||||
import com.ossez.edtestbank.common.model.entity.BBSOssezForumAttach;
|
||||
import com.ossez.edtestbank.common.model.entity.BBSOssezForumPost;
|
||||
import com.ossez.edtestbank.common.model.request.TopicRequest;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
import org.apache.http.HttpHeaders;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
/**
|
||||
* Test Logger and function
|
||||
*
|
||||
* @author YuCheng Hu
|
||||
*/
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class PostTest {
|
||||
private static Logger logger = LoggerFactory.getLogger(PostTest.class);
|
||||
|
||||
|
||||
@BeforeAll
|
||||
protected void setUp() throws Exception {
|
||||
Factory.beginTransaction();
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
protected void tearDown() throws Exception {
|
||||
Factory.rollbackTransaction();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests search functionality for the customer object.
|
||||
*/
|
||||
@Test
|
||||
public void testPost() throws IOException, InterruptedException {
|
||||
List<String> idList = FileUtils.readLines(new File("C:\\Users\\yhu\\Pictures\\Pics\\2021-01\\1.txt"));
|
||||
for (String id : idList) {
|
||||
processPost(NumberUtils.toLong(id));
|
||||
Thread.sleep(6000);
|
||||
// break;
|
||||
|
||||
}
|
||||
|
||||
|
||||
// make sure the customer was found
|
||||
// assertNotNull(bbsOssezForumPost);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDateTime() throws IOException {
|
||||
DateTime dateTime = new DateTime(1256834117 * 1000L);
|
||||
System.out.println(dateTime.toString());
|
||||
|
||||
}
|
||||
|
||||
private void processPost(Long tid) throws IOException {
|
||||
BBSOssezForumPost bbsOssezForumPost = PostFactory.getBBSOssezForumPostTid(tid);
|
||||
if (bbsOssezForumPost == null)
|
||||
return;
|
||||
|
||||
logger.debug("Questions Content - {}", bbsOssezForumPost.getSubject());
|
||||
|
||||
String postCtx = bbsOssezForumPost.getMessage();
|
||||
// logger.debug(">>>>{}", postCtx);
|
||||
|
||||
|
||||
String pattern = "\\[attach\\]((\\d)*?)\\[\\/attach\\]";
|
||||
|
||||
// Create a Pattern object
|
||||
Pattern r = Pattern.compile(pattern);
|
||||
|
||||
// Now create matcher object.
|
||||
Matcher m = r.matcher(postCtx);
|
||||
|
||||
while (m.find()) {
|
||||
String attachId = StringUtils.substringBetween(m.group(0), "[attach]", "[/attach]");
|
||||
logger.debug("{}", attachId);
|
||||
BBSOssezForumAttach bbsOssezForumAttach = PostFactory.getBBSOssezForumAttach(NumberUtils.toLong(attachId));
|
||||
if (bbsOssezForumAttach!= null) {
|
||||
String fullURL = "![](https://cdn.ossez.com/com-ossez-www/data/attachment/forum/" + bbsOssezForumAttach.getAttachment() + ")";
|
||||
postCtx = StringUtils.replace(postCtx, m.group(0), fullURL);
|
||||
}
|
||||
}
|
||||
|
||||
logger.debug("{}", postCtx);
|
||||
|
||||
|
||||
CloseableHttpClient client = HttpClients.createDefault();
|
||||
|
||||
HttpPost httpPost = new HttpPost("https://www.ossez.com/posts.json");
|
||||
httpPost.setHeader(HttpHeaders.CONTENT_TYPE, "application/json; charset=UTF-8");
|
||||
httpPost.setHeader("Api-Key", "XXXXXX");
|
||||
httpPost.setHeader("Api-Username", "XXXXXX");
|
||||
|
||||
TopicRequest topicRequest = new TopicRequest();
|
||||
topicRequest.setTitle(bbsOssezForumPost.getSubject());
|
||||
topicRequest.setRaw(postCtx);
|
||||
topicRequest.setCreated_at(new DateTime(bbsOssezForumPost.getDateline() * 1000L).toString() );
|
||||
topicRequest.setCategory(30);
|
||||
|
||||
StringEntity postingString = new StringEntity(new Gson().toJson(topicRequest), StandardCharsets.UTF_8);
|
||||
|
||||
httpPost.setEntity(postingString);
|
||||
|
||||
|
||||
CloseableHttpResponse response = client.execute(httpPost);
|
||||
|
||||
logger.info("{}", EntityUtils.toString(response.getEntity()), StandardCharsets.UTF_8);
|
||||
client.close();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,293 @@
|
|||
package com.ossez.lang.tutorial.tests;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.TreeSet;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.management.ListenerNotFoundException;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.ossez.lang.tutorial.models.ListNode;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author YuCheng
|
||||
*
|
||||
*/
|
||||
public class LintcodeTest {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(LintcodeTest.class);
|
||||
|
||||
/**
|
||||
* 35 https://www.lintcode.com/problem/reverse-linked-list/description
|
||||
*/
|
||||
@Test
|
||||
public void test0035Reverse() {
|
||||
// INIT LINKED LIST
|
||||
ListNode head = new ListNode(1);
|
||||
head.next = new ListNode(2);
|
||||
head.next.next = new ListNode(3);
|
||||
|
||||
// CHECK BEFORE
|
||||
System.out.println(head.val);
|
||||
System.out.println(head.next.val);
|
||||
System.out.println(head.next.next.val);
|
||||
|
||||
// REVERSE
|
||||
ListNode prev = null;
|
||||
while (head != null) {
|
||||
ListNode temp = head.next;
|
||||
head.next = prev;
|
||||
prev = head;
|
||||
head = temp;
|
||||
}
|
||||
|
||||
// CHECK AFTER
|
||||
System.out.println(prev.val);
|
||||
System.out.println(prev.next.val);
|
||||
System.out.println(prev.next.next.val);
|
||||
}
|
||||
|
||||
/**
|
||||
* 1480 https://www.lintcode.com/problem/dot-product/description
|
||||
*/
|
||||
@Test
|
||||
public void test0044minSubArray() {
|
||||
|
||||
List<Integer> nums = new ArrayList<Integer>();
|
||||
nums.add(1);
|
||||
nums.add(1);
|
||||
|
||||
int min_ending_here = 0;
|
||||
int retStatus = 0;
|
||||
|
||||
for (int i = 0; i < nums.size(); i++) {
|
||||
if (min_ending_here > 0) {
|
||||
min_ending_here = nums.get(i);
|
||||
} else {
|
||||
min_ending_here += nums.get(i);
|
||||
}
|
||||
retStatus = Math.min(retStatus, min_ending_here);
|
||||
}
|
||||
|
||||
System.out.println(retStatus);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 53 https://www.lintcode.com/problem/reverse-words-in-a-string/description
|
||||
*/
|
||||
@Test
|
||||
public void test0053ReverseWords() {
|
||||
|
||||
String s = " Life doesn't always give us the joys we want.";
|
||||
|
||||
String retStr = "";
|
||||
String[] inStr = s.split(" ");
|
||||
|
||||
for (int i = inStr.length - 1; i >= 0; i--) {
|
||||
String cStr = inStr[i].trim();
|
||||
if (!cStr.isEmpty()) {
|
||||
retStr = retStr + " " + cStr;
|
||||
}
|
||||
}
|
||||
retStr = retStr.trim();
|
||||
System.out.println(retStr);
|
||||
// return retStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 56 https://www.lintcode.com/problem/two-sum/description
|
||||
*/
|
||||
@Test
|
||||
public void test0056TwoSum() {
|
||||
int[] numbers = { 2, 7, 11, 15 };
|
||||
int target = 9;
|
||||
|
||||
int[] retArray = new int[2];
|
||||
|
||||
for (int i = 0; i < numbers.length; i++) {
|
||||
int intA = numbers[i];
|
||||
int intB = 0;
|
||||
|
||||
for (int j = 1 + i; j < numbers.length; j++) {
|
||||
intB = numbers[j];
|
||||
// SUM CHECK
|
||||
if (target == intA + intB && i < j) {
|
||||
retArray[0] = i;
|
||||
retArray[1] = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println(Arrays.toString(retArray));
|
||||
}
|
||||
|
||||
/**
|
||||
* 209 https://www.lintcode.com/problem/first-unique-character-in-a-string
|
||||
*/
|
||||
@Test
|
||||
public void test0209FirstUniqChar() {
|
||||
String str = "ddjdz";
|
||||
|
||||
char retStatus = 0;
|
||||
|
||||
// LOOP CHECK
|
||||
for (int i = 0; i < 30; i++) {
|
||||
char c = str.charAt(0);
|
||||
if (str.indexOf(Character.toString(c)) == str.lastIndexOf(Character.toString(c))) {
|
||||
retStatus = c;
|
||||
break;
|
||||
}
|
||||
str = str.replaceAll(Character.toString(c), "");
|
||||
}
|
||||
|
||||
System.out.println("" + retStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
* 411
|
||||
*
|
||||
* <p>
|
||||
* <ul>
|
||||
* <li>@see
|
||||
* <a href="https://www.cwiki.us/display/ITCLASSIFICATION/Gray+Code">https://www.cwiki.us/display/ITCLASSIFICATION/Gray+Code</a>
|
||||
* <li>@see<a href="https://www.lintcode.com/problem/gray-code/description">https://www.lintcode.com/problem/gray-code/description</a>
|
||||
* </ul>
|
||||
* </p>
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void test0411GrayCode() {
|
||||
int n = 2;
|
||||
|
||||
List<Integer> retArray = new ArrayList<>();
|
||||
|
||||
if (n == 0) {
|
||||
retArray.add(0);
|
||||
}
|
||||
|
||||
for (int i = 0; i < (2 << (n - 1)); i++) {
|
||||
int g = i ^ (i / 2);
|
||||
retArray.add(g);
|
||||
}
|
||||
|
||||
System.out.println(retArray);
|
||||
}
|
||||
|
||||
/**
|
||||
* 1480 https://www.lintcode.com/problem/dot-product/description
|
||||
*/
|
||||
@Test
|
||||
public void test0423IsValidParentheses() {
|
||||
String s = "([)]";
|
||||
|
||||
boolean retStatus = false;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
s = s.replace("()", "");
|
||||
s = s.replace("{}", "");
|
||||
s = s.replace("[]", "");
|
||||
|
||||
if (s.length() == 0) {
|
||||
retStatus = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println(retStatus);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 646 https://www.lintcode.com/problem/first-position-unique-character/description
|
||||
*/
|
||||
@Test
|
||||
public void test0646FirstUniqChar() {
|
||||
String s = "saau";
|
||||
|
||||
int retStatus = -1;
|
||||
boolean breakLoop = false;
|
||||
|
||||
int[] iArray = new int[256];
|
||||
|
||||
// NULL CHECK
|
||||
if (s == null || s.length() == 0) {
|
||||
retStatus = -1;
|
||||
}
|
||||
|
||||
// LOOP CHECK
|
||||
for (char c : s.toCharArray()) {
|
||||
iArray[c]++;
|
||||
}
|
||||
for (int i = 0; i < s.length(); i++) {
|
||||
if (iArray[s.charAt(i)] == 1) {
|
||||
retStatus = i;
|
||||
breakLoop = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// LOOP BREAK CHECK
|
||||
if (!breakLoop) {
|
||||
retStatus = -1;
|
||||
}
|
||||
|
||||
System.out.println(retStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
* 767 https://www.lintcode.com/problem/reverse-array/description
|
||||
*/
|
||||
@Test
|
||||
public void test0767ReverseArray() {
|
||||
int[] nums = { 1, 2, 3, 4, 5, 6, 7 };
|
||||
|
||||
for (int i = 0; i < nums.length / 2; i++) {
|
||||
int tmp = nums[i];
|
||||
nums[i] = nums[nums.length - 1 - i];
|
||||
nums[nums.length - 1 - i] = tmp;
|
||||
}
|
||||
|
||||
System.out.println(Arrays.toString(nums));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 1480 https://www.lintcode.com/problem/dot-product/description
|
||||
*/
|
||||
@Test
|
||||
public void test1377findSubstring() {
|
||||
String str = "";
|
||||
int k = 5;
|
||||
|
||||
HashSet<String> strSet = new HashSet<String>();
|
||||
|
||||
for (int i = 0; i <= str.length() - k; i++) {
|
||||
String subStr = str.substring(i, i + k);
|
||||
|
||||
String pattern = ".*(.).*\\1.*";
|
||||
|
||||
Pattern r = Pattern.compile(pattern);
|
||||
|
||||
Matcher m = r.matcher(subStr);
|
||||
if (!m.find()) {
|
||||
strSet.add(subStr);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
System.out.println(strSet.size());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
package com.ossez.lang.tutorial.tests;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Eager Singleton
|
||||
*
|
||||
* @author YuCheng
|
||||
*
|
||||
*/
|
||||
class EagerSingleton {
|
||||
private static final EagerSingleton INSTANCE = new EagerSingleton();
|
||||
|
||||
// Private constructor suppresses
|
||||
private EagerSingleton() {
|
||||
}
|
||||
|
||||
// default public constructor
|
||||
public static EagerSingleton getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Lazy Singleton
|
||||
*
|
||||
* @author YuCheng
|
||||
*
|
||||
*/
|
||||
class LazySingleton {
|
||||
private static volatile LazySingleton INSTANCE = null;
|
||||
|
||||
// Private constructor suppresses
|
||||
// default LazySingleton constructor
|
||||
private LazySingleton() {
|
||||
}
|
||||
|
||||
// thread safe and performance promote
|
||||
public static LazySingleton getInstance() {
|
||||
if (INSTANCE == null) {
|
||||
synchronized (LazySingleton.class) {
|
||||
// when more than two threads run into the first null check same time, to avoid instanced more than one time, it needs to be
|
||||
// checked again.
|
||||
if (INSTANCE == null) {
|
||||
INSTANCE = new LazySingleton();
|
||||
}
|
||||
}
|
||||
}
|
||||
return INSTANCE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @author YuCheng
|
||||
*
|
||||
*/
|
||||
public class SingletonTest {
|
||||
private final static Logger logger = LoggerFactory.getLogger(SingletonTest.class);
|
||||
|
||||
@Test
|
||||
public void testSingleton() {
|
||||
logger.debug("TEST Singleton");
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
package com.ossez.lang.tutorial.tests;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.ossez.lang.tutorial.models.TreeNode;
|
||||
import com.ossez.lang.tutorial.utils.TreeUtils;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author YuCheng
|
||||
*
|
||||
*/
|
||||
public class TreeTest {
|
||||
private final static Logger logger = LoggerFactory.getLogger(TreeTest.class);
|
||||
private static List<Integer> loopList = new ArrayList<Integer>();
|
||||
|
||||
@Test
|
||||
public void testMain() {
|
||||
logger.debug("TREE TEST");
|
||||
String data = "{1,2,3,4,5,#,6,#,#,7,8,#,#}";
|
||||
TreeNode treeNode = TreeUtils.initTree(data);
|
||||
|
||||
// PRE
|
||||
loopList = new ArrayList<Integer>();
|
||||
preOrderTraverselRecursion(treeNode);
|
||||
System.out.println(loopList);
|
||||
|
||||
// IN
|
||||
loopList = new ArrayList<Integer>();
|
||||
inOrderTraverselRecursion(treeNode);
|
||||
System.out.println(loopList);
|
||||
|
||||
// POST
|
||||
loopList = new ArrayList<Integer>();
|
||||
postOrderTraversalRecursion(treeNode);
|
||||
System.out.println(loopList);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param root
|
||||
*/
|
||||
public void preOrderTraverselRecursion(TreeNode root) {
|
||||
if (root != null) {
|
||||
loopList.add(root.val);
|
||||
preOrderTraverselRecursion(root.left);
|
||||
preOrderTraverselRecursion(root.right);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param root
|
||||
*/
|
||||
public void inOrderTraverselRecursion(TreeNode root) {
|
||||
if (root != null) {
|
||||
inOrderTraverselRecursion(root.left);
|
||||
loopList.add(root.val);
|
||||
inOrderTraverselRecursion(root.right);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param root
|
||||
*/
|
||||
public void postOrderTraversalRecursion(TreeNode root) {
|
||||
if (root != null) {
|
||||
postOrderTraversalRecursion(root.left);
|
||||
postOrderTraversalRecursion(root.right);
|
||||
loopList.add(root.val);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
package com.ossez.lang.tutorial.tests;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Object of VariableOssez
|
||||
*
|
||||
* @author YuCheng
|
||||
*
|
||||
*/
|
||||
class OssezVariable {
|
||||
int s1, s2;
|
||||
static int s3;
|
||||
|
||||
OssezVariable(int x, int y, int z) {
|
||||
s1 = x;
|
||||
s2 = y;
|
||||
s3 = z;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @author YuCheng
|
||||
*
|
||||
*/
|
||||
public class VariableTest extends TestCase {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(VariableTest.class);
|
||||
|
||||
/**
|
||||
* Do RetsServerConnection Test
|
||||
*/
|
||||
@Test
|
||||
public void testStaticVariableChange() {
|
||||
|
||||
OssezVariable objA = new OssezVariable(1, 2, 3);
|
||||
logger.debug("s1/s2/s3 - [{}]/[{}]/[{}]", objA.s1, objA.s2, OssezVariable.s3);
|
||||
|
||||
OssezVariable objB = new OssezVariable(4, 5, 6);
|
||||
logger.debug("s1/s2/s3 - [{}]/[{}]/[{}]", objA.s1, objA.s2, OssezVariable.s3);
|
||||
logger.debug("s1/s2/s3 - [{}]/[{}]/[{}]", objB.s1, objB.s2, OssezVariable.s3);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package com.ossez.lang.tutorial.tests.codility;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* More details about question see link below
|
||||
* <ul>
|
||||
* <li>@see <a href= "https://www.cwiki.us/display/ITCLASSIFICATION/Binary+Gap">https://www.cwiki.us/display/ITCLASSIFICATION/Binary+Gap</a>
|
||||
* </li>
|
||||
* </ul>
|
||||
* </p>
|
||||
*
|
||||
* @author YuCheng
|
||||
*
|
||||
*/
|
||||
public class CodilityBinaryGapTest {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(CodilityBinaryGapTest.class);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testMain() {
|
||||
logger.debug("BEGIN");
|
||||
|
||||
int N = 529;
|
||||
String intStr = Integer.toBinaryString(N);
|
||||
|
||||
intStr = intStr.replace("1", "#1#");
|
||||
|
||||
String[] strArray = intStr.split("1");
|
||||
|
||||
int maxCount = 0;
|
||||
for (int i = 0; i < strArray.length; i++) {
|
||||
String checkStr = strArray[i];
|
||||
int countLength = 0;
|
||||
|
||||
if (checkStr.length() > 2 && checkStr.startsWith("#") && checkStr.endsWith("#")) {
|
||||
checkStr = checkStr.replace("#", "");
|
||||
countLength = checkStr.length();
|
||||
|
||||
if (maxCount < countLength) {
|
||||
maxCount = countLength;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
logger.debug("MAX COUNT: [{}]", maxCount);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,131 @@
|
|||
package com.ossez.lang.tutorial.tests.lintcode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.ossez.lang.tutorial.models.TreeNode;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 7
|
||||
* <ul>
|
||||
* <li>@see <a href=
|
||||
* "https://www.cwiki.us/display/ITCLASSIFICATION/Serialize+and+Deserialize+Binary+Tree">https://www.cwiki.us/display/ITCLASSIFICATION/Serialize+and+Deserialize+Binary+Tree</a>
|
||||
* <li>@see<a href=
|
||||
* "https://www.lintcode.com/problem/serialize-and-deserialize-binary-tree">https://www.lintcode.com/problem/serialize-and-deserialize-binary-tree</a>
|
||||
* </ul>
|
||||
* </p>
|
||||
*
|
||||
* @author YuCheng
|
||||
*
|
||||
*/
|
||||
public class LintCode0007SerializeAndDeserializeTest {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(LintCode0007SerializeAndDeserializeTest.class);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testMain() {
|
||||
logger.debug("BEGIN");
|
||||
String data = "{3,9,20,#,#,15,7}";
|
||||
|
||||
System.out.println(serialize(deserialize(data)));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserialize from array to tree
|
||||
*
|
||||
* @param data
|
||||
* @return
|
||||
*/
|
||||
private TreeNode deserialize(String data) {
|
||||
// NULL CHECK
|
||||
if (data.equals("{}")) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ArrayList<TreeNode> treeList = new ArrayList<TreeNode>();
|
||||
|
||||
data = data.replace("{", "");
|
||||
data = data.replace("}", "");
|
||||
String[] vals = data.split(",");
|
||||
|
||||
// INSERT ROOT
|
||||
TreeNode root = new TreeNode(Integer.parseInt(vals[0]));
|
||||
treeList.add(root);
|
||||
|
||||
int index = 0;
|
||||
boolean isLeftChild = true;
|
||||
for (int i = 1; i < vals.length; i++) {
|
||||
if (!vals[i].equals("#")) {
|
||||
TreeNode node = new TreeNode(Integer.parseInt(vals[i]));
|
||||
if (isLeftChild) {
|
||||
treeList.get(index).left = node;
|
||||
} else {
|
||||
treeList.get(index).right = node;
|
||||
}
|
||||
treeList.add(node);
|
||||
}
|
||||
|
||||
// LEVEL
|
||||
if (!isLeftChild) {
|
||||
index++;
|
||||
}
|
||||
|
||||
// MOVE TO RIGHT OR NEXT LEVEL
|
||||
isLeftChild = !isLeftChild;
|
||||
}
|
||||
|
||||
return root;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param root
|
||||
* @return
|
||||
*/
|
||||
public String serialize(TreeNode root) {
|
||||
// write your code here
|
||||
if (root == null) {
|
||||
return "{}";
|
||||
}
|
||||
|
||||
ArrayList<TreeNode> queue = new ArrayList<TreeNode>();
|
||||
queue.add(root);
|
||||
|
||||
for (int i = 0; i < queue.size(); i++) {
|
||||
TreeNode node = queue.get(i);
|
||||
if (node == null) {
|
||||
continue;
|
||||
}
|
||||
queue.add(node.left);
|
||||
queue.add(node.right);
|
||||
}
|
||||
|
||||
while (queue.get(queue.size() - 1) == null) {
|
||||
queue.remove(queue.size() - 1);
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("{");
|
||||
sb.append(queue.get(0).val);
|
||||
for (int i = 1; i < queue.size(); i++) {
|
||||
if (queue.get(i) == null) {
|
||||
sb.append(",#");
|
||||
} else {
|
||||
sb.append(",");
|
||||
sb.append(queue.get(i).val);
|
||||
}
|
||||
}
|
||||
sb.append("}");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,124 @@
|
|||
package com.ossez.lang.tutorial.tests.lintcode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.ossez.lang.tutorial.models.TreeNode;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 69
|
||||
* <ul>
|
||||
* <li>@see <a href=
|
||||
* "https://www.cwiki.us/display/ITCLASSIFICATION/Binary+Tree+Level+Order+Traversal">https://www.cwiki.us/display/ITCLASSIFICATION/Binary+Tree+Level+Order+Traversal</a>
|
||||
* <li>@see<a href=
|
||||
* "https://www.lintcode.com/problem/binary-tree-level-order-traversal">https://www.lintcode.com/problem/binary-tree-level-order-traversal</a>
|
||||
* </ul>
|
||||
* </p>
|
||||
*
|
||||
* @author YuCheng
|
||||
*
|
||||
*/
|
||||
public class LintCode0069LevelOrderTest {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(LintCode0069LevelOrderTest.class);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testMain() {
|
||||
logger.debug("BEGIN");
|
||||
String data = "{3,9,20,#,#,15,7}";
|
||||
|
||||
TreeNode tn = deserialize(data);
|
||||
System.out.println(levelOrder(tn));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserialize from array to tree
|
||||
*
|
||||
* @param data
|
||||
* @return
|
||||
*/
|
||||
private TreeNode deserialize(String data) {
|
||||
// NULL CHECK
|
||||
if (data.equals("{}")) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ArrayList<TreeNode> treeList = new ArrayList<TreeNode>();
|
||||
|
||||
data = data.replace("{", "");
|
||||
data = data.replace("}", "");
|
||||
String[] vals = data.split(",");
|
||||
|
||||
// INSERT ROOT
|
||||
TreeNode root = new TreeNode(Integer.parseInt(vals[0]));
|
||||
treeList.add(root);
|
||||
|
||||
int index = 0;
|
||||
boolean isLeftChild = true;
|
||||
for (int i = 1; i < vals.length; i++) {
|
||||
if (!vals[i].equals("#")) {
|
||||
TreeNode node = new TreeNode(Integer.parseInt(vals[i]));
|
||||
if (isLeftChild) {
|
||||
treeList.get(index).left = node;
|
||||
} else {
|
||||
treeList.get(index).right = node;
|
||||
}
|
||||
treeList.add(node);
|
||||
}
|
||||
|
||||
// LEVEL
|
||||
if (!isLeftChild) {
|
||||
index++;
|
||||
}
|
||||
|
||||
// MOVE TO RIGHT OR NEXT LEVEL
|
||||
isLeftChild = !isLeftChild;
|
||||
}
|
||||
|
||||
return root;
|
||||
|
||||
}
|
||||
|
||||
private List<List<Integer>> levelOrder(TreeNode root) {
|
||||
Queue<TreeNode> queue = new LinkedList<TreeNode>();
|
||||
List<List<Integer>> rs = new ArrayList<List<Integer>>();
|
||||
|
||||
// NULL CHECK
|
||||
if (root == null) {
|
||||
return rs;
|
||||
}
|
||||
|
||||
queue.offer(root);
|
||||
|
||||
while (!queue.isEmpty()) {
|
||||
int length = queue.size();
|
||||
List<Integer> list = new ArrayList<Integer>();
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
TreeNode curTN = queue.poll();
|
||||
list.add(curTN.val);
|
||||
if (curTN.left != null) {
|
||||
queue.offer(curTN.left);
|
||||
}
|
||||
if (curTN.right != null) {
|
||||
queue.offer(curTN.right);
|
||||
}
|
||||
}
|
||||
|
||||
rs.add(list);
|
||||
}
|
||||
|
||||
return rs;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
package com.ossez.lang.tutorial.tests.lintcode;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.ossez.lang.tutorial.models.ListNode;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 102
|
||||
* <ul>
|
||||
* <li>@see <a href=
|
||||
* "https://www.cwiki.us/display/ITCLASSIFICATION/Linked+List+Cycle">https://www.cwiki.us/display/ITCLASSIFICATION/Linked+List+Cycle</a>
|
||||
* <li>@see<a href= "https://www.lintcode.com/problem/linked-list-cycle/">https://www.lintcode.com/problem/linked-list-cycle/</a>
|
||||
* </ul>
|
||||
* </p>
|
||||
*
|
||||
* @author YuCheng
|
||||
*
|
||||
*/
|
||||
public class LintCode0102HasCycleTest {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(LintCode0102HasCycleTest.class);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testMain() {
|
||||
logger.debug("BEGIN");
|
||||
// INIT LINKED LIST
|
||||
ListNode head = new ListNode(1);
|
||||
head.next = new ListNode(2);
|
||||
head.next.next = new ListNode(3);
|
||||
head.next.next.next = new ListNode(4);
|
||||
|
||||
// CREATE A LOOP
|
||||
head.next.next.next.next = head.next.next.next;
|
||||
|
||||
boolean retResult = false;
|
||||
|
||||
// LIKED LIST MAY NULL:
|
||||
if (!(head == null || head.next == null)) {
|
||||
ListNode s = head;
|
||||
ListNode f = head.next;
|
||||
|
||||
while (f.next != null && f.next.next != null) {
|
||||
|
||||
s = s.next;
|
||||
f = f.next.next;
|
||||
|
||||
if (f == s) {
|
||||
retResult = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println(retResult);
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
package com.ossez.lang.tutorial.tests.lintcode;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.ossez.lang.tutorial.models.ListNode;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 102
|
||||
* <ul>
|
||||
* <li>@see <a href=
|
||||
* "https://www.cwiki.us/display/ITCLASSIFICATION/Linked+List+Cycle">https://www.cwiki.us/display/ITCLASSIFICATION/Linked+List+Cycle</a>
|
||||
* <li>@see<a href= "https://www.lintcode.com/problem/linked-list-cycle/">https://www.lintcode.com/problem/linked-list-cycle/</a>
|
||||
* </ul>
|
||||
* </p>
|
||||
*
|
||||
* @author YuCheng
|
||||
*
|
||||
*/
|
||||
public class LintCode0165MergeTwoListsTest {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(LintCode0165MergeTwoListsTest.class);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testMain() {
|
||||
logger.debug("BEGIN");
|
||||
// INIT LINKED LIST l1
|
||||
ListNode l1 = new ListNode(1);
|
||||
l1.next = new ListNode(3);
|
||||
l1.next.next = new ListNode(8);
|
||||
l1.next.next.next = new ListNode(11);
|
||||
l1.next.next.next.next = new ListNode(15);
|
||||
|
||||
// INIT LINKED LIST l2
|
||||
ListNode l2 = new ListNode(2);
|
||||
|
||||
// RETURN RESULT
|
||||
ListNode retResult = new ListNode(0);
|
||||
|
||||
// NULL CHECK
|
||||
// if (l1 == null && l2 == null) {
|
||||
// retResult = null;
|
||||
// }
|
||||
//
|
||||
// if (l1 == null) {
|
||||
// retResult = l2;
|
||||
// }
|
||||
//
|
||||
// if (l2 == null) {
|
||||
// retResult = l1;
|
||||
// }
|
||||
|
||||
// MERGE
|
||||
retResult = new ListNode(0);
|
||||
ListNode tmpNode = new ListNode(0);
|
||||
retResult = tmpNode;
|
||||
while (l1 != null & l2 != null) {
|
||||
if (l1.val <= l2.val) {
|
||||
tmpNode.next = l1;
|
||||
l1 = l1.next;
|
||||
} else {
|
||||
tmpNode.next = l2;
|
||||
l2 = l2.next;
|
||||
}
|
||||
|
||||
tmpNode = tmpNode.next;
|
||||
}
|
||||
|
||||
if (l1 == null) {
|
||||
tmpNode.next = l2;
|
||||
}
|
||||
|
||||
if (l2 == null) {
|
||||
tmpNode.next = l1;
|
||||
}
|
||||
|
||||
retResult = retResult.next;
|
||||
|
||||
System.out.println(retResult.val);
|
||||
System.out.println(retResult.next.val);
|
||||
System.out.println(retResult.next.next.val);
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
package com.ossez.lang.tutorial.tests.lintcode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 425
|
||||
* <ul>
|
||||
* <li>@see <a href=
|
||||
* "https://www.cwiki.us/display/ITCLASSIFICATION/Letter+Combinations+of+a+Phone+Number">https://www.cwiki.us/display/ITCLASSIFICATION/Letter+Combinations+of+a+Phone+Number</a>
|
||||
* <li>@see<a href=
|
||||
* "https://www.lintcode.com/problem/letter-combinations-of-a-phone-number/description">https://www.lintcode.com/problem/letter-combinations-of-a-phone-number/description</a>
|
||||
* </ul>
|
||||
* </p>
|
||||
*
|
||||
* @author YuCheng
|
||||
*
|
||||
*/
|
||||
public class LintCode0425LetterCombinationsTest {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(LintCode0425LetterCombinationsTest.class);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testMain() {
|
||||
logger.debug("LetterCombinationsTest");
|
||||
String digits = "23";
|
||||
|
||||
HashMap<String, String> phoneKeyMap = new HashMap<String, String>();
|
||||
phoneKeyMap.put("0", "");
|
||||
phoneKeyMap.put("1", "");
|
||||
phoneKeyMap.put("2", "abc");
|
||||
phoneKeyMap.put("3", "def");
|
||||
phoneKeyMap.put("4", "ghi");
|
||||
phoneKeyMap.put("5", "jkl");
|
||||
phoneKeyMap.put("6", "mno");
|
||||
phoneKeyMap.put("7", "pqrs");
|
||||
phoneKeyMap.put("8", "tuv");
|
||||
phoneKeyMap.put("9", "wxyz");
|
||||
|
||||
List<String> retStatus = new ArrayList<>();
|
||||
|
||||
if (digits != null && digits.length() != 0) {
|
||||
phoneRecursive(digits, retStatus, phoneKeyMap, "", 0);
|
||||
}
|
||||
|
||||
System.out.println(retStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
* phoneRecursive
|
||||
*
|
||||
* @param digits
|
||||
* @param retStatus
|
||||
* @param phoneKeyMap
|
||||
* @param comb
|
||||
* @param index
|
||||
*/
|
||||
private void phoneRecursive(String digits, List<String> retStatus, HashMap<String, String> phoneKeyMap, String comb, int index) {
|
||||
if (index == digits.length()) {
|
||||
retStatus.add(comb);
|
||||
return;
|
||||
}
|
||||
|
||||
char pos = digits.charAt(index);
|
||||
for (char c : ((String) phoneKeyMap.get(String.valueOf(pos))).toCharArray()) {
|
||||
phoneRecursive(digits, retStatus, phoneKeyMap, comb + c, index + 1);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,94 @@
|
|||
package com.ossez.lang.tutorial.tests.lintcode;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 433
|
||||
* <ul>
|
||||
* <li>@see <a href=
|
||||
* "https://www.cwiki.us/display/ITCLASSIFICATION/Number+of+Islands">https://www.cwiki.us/display/ITCLASSIFICATION/Number+of+Islands</a>
|
||||
* <li>@see<a href="https://www.lintcode.com/problem/number-of-islands/">https://www.lintcode.com/problem/number-of-islands/</a>
|
||||
* </ul>
|
||||
* </p>
|
||||
*
|
||||
* @author YuCheng
|
||||
*
|
||||
*/
|
||||
public class LintCode0433NumIslandsTest {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(LintCode0433NumIslandsTest.class);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testMain() {
|
||||
logger.debug("BEGIN");
|
||||
// INIT GRID
|
||||
boolean[][] grid = { { true, true, false, false, false }, { false, true, false, false, true }, { false, false, false, true, true },
|
||||
{ false, false, false, false, false }, { false, false, false, false, true }
|
||||
|
||||
};
|
||||
|
||||
// NULL CHECK
|
||||
if (grid.length == 0 || grid[0].length == 0) {
|
||||
System.out.println("NULL");
|
||||
// return 0;
|
||||
}
|
||||
|
||||
// GET SIZE
|
||||
int n = grid.length;
|
||||
int m = grid[0].length;
|
||||
|
||||
// ARRAY FOR VISITED LOG
|
||||
boolean[][] visited = new boolean[n][m];
|
||||
|
||||
int count = 0;
|
||||
|
||||
// LOOP FOR GRID
|
||||
for (int i = 0; i < n; i++) {
|
||||
for (int j = 0; j < m; j++) {
|
||||
if (grid[i][j] && !visited[i][j]) {
|
||||
numIslandsDFS(grid, visited, i, j);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println(count);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param grid
|
||||
* @param visited
|
||||
* @param x
|
||||
* @param y
|
||||
*/
|
||||
public void numIslandsDFS(boolean[][] grid, boolean[][] visited, int x, int y) {
|
||||
if (x < 0 || x >= grid.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (y < 0 || y >= grid[0].length) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (grid[x][y] != true || visited[x][y]) {
|
||||
return;
|
||||
}
|
||||
|
||||
visited[x][y] = true;
|
||||
|
||||
// Recursive call
|
||||
numIslandsDFS(grid, visited, x - 1, y);
|
||||
numIslandsDFS(grid, visited, x + 1, y);
|
||||
numIslandsDFS(grid, visited, x, y - 1);
|
||||
numIslandsDFS(grid, visited, x, y + 1);
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package com.ossez.lang.tutorial.tests.lintcode;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 1480
|
||||
* <ul>
|
||||
* <li>@see
|
||||
* <a href= "https://www.cwiki.us/display/ITCLASSIFICATION/Dot+Product">https://www.cwiki.us/display/ITCLASSIFICATION/Dot+Product</a>
|
||||
* <li>@see<a href= "https://www.lintcode.com/problem/dot-product/">https://www.lintcode.com/problem/dot-product/</a>
|
||||
* </ul>
|
||||
* </p>
|
||||
*
|
||||
* @author YuCheng
|
||||
*
|
||||
*/
|
||||
public class LintCode1480DotProductTest {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(LintCode1480DotProductTest.class);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testMain() {
|
||||
logger.debug("BEGIN");
|
||||
int t = 87;
|
||||
int[] dur = { 20, 25, 19, 37 };
|
||||
// Write your code here
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,97 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE RelativeLayout>
|
||||
<Configuration status="WARN">
|
||||
|
||||
<Properties>
|
||||
<Property name="baseDir">/home/logs/reoc/services/</Property>
|
||||
</Properties>
|
||||
|
||||
<Appenders>
|
||||
<!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
<!-- C O N S O L E - A P P E N D E R -->
|
||||
<!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
<Console name="CONSOLE" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="%-d{yyyy/MM/dd HH:mm:ss} %-5p [%c] - %m%n" />
|
||||
<ThresholdFilter level="TRACE" onMatch="ACCEPT" onMismatch="DENY" />
|
||||
</Console>
|
||||
|
||||
<!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
<!-- D E B U G _ F I L E - A P P E N D E R -->
|
||||
<!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
<RollingFile name="FILE_DEBUG" append="true" fileName="${baseDir}/services_debug.log" filePattern="${baseDir}/$${date:yyyy-MM}/services-debug-%d{yyyy-MM-dd}-%i.log.gz">
|
||||
<ThresholdFilter level="DEBUG" onMatch="ACCEPT" onMismatch="DENY" />
|
||||
<PatternLayout>
|
||||
<pattern>%-d{yyyy/MM/dd HH:mm:ss} %-5p [%c] - %m%n</pattern>
|
||||
</PatternLayout>
|
||||
<Policies>
|
||||
<TimeBasedTriggeringPolicy />
|
||||
<SizeBasedTriggeringPolicy size="250 MB"></SizeBasedTriggeringPolicy>
|
||||
</Policies>
|
||||
<DefaultRolloverStrategy max="12" />
|
||||
</RollingFile>
|
||||
|
||||
<!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
<!-- I N F O _ F I L E - A P P E N D E R -->
|
||||
<!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
<RollingFile name="FILE_INFO" append="true" fileName="${baseDir}/services_info.log" filePattern="${baseDir}/$${date:yyyy-MM}/services-info-%d{yyyy-MM-dd}.log.gz">
|
||||
<ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY" />
|
||||
<PatternLayout>
|
||||
<pattern>%-d{yyyy/MM/dd HH:mm:ss} %-5p [%c] - %m%n</pattern>
|
||||
</PatternLayout>
|
||||
<Policies>
|
||||
<TimeBasedTriggeringPolicy />
|
||||
<SizeBasedTriggeringPolicy size="250 MB"></SizeBasedTriggeringPolicy>
|
||||
</Policies>
|
||||
<DefaultRolloverStrategy max="12" />
|
||||
</RollingFile>
|
||||
|
||||
<!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
<!-- F I L E _ W A R N - A P P E N D E R -->
|
||||
<!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
<RollingFile name="FILE_WARN" append="true" fileName="${baseDir}/services_info.log" filePattern="${baseDir}/$${date:yyyy-MM}/services-warn-%d{yyyy-MM-dd}.log.gz">
|
||||
<ThresholdFilter level="WARN" onMatch="ACCEPT" onMismatch="DENY" />
|
||||
<PatternLayout>
|
||||
<pattern>%-d{yyyy/MM/dd HH:mm:ss} %-5p [%c] - %m%n</pattern>
|
||||
</PatternLayout>
|
||||
<Policies>
|
||||
<TimeBasedTriggeringPolicy />
|
||||
<SizeBasedTriggeringPolicy size="250 MB"></SizeBasedTriggeringPolicy>
|
||||
</Policies>
|
||||
<DefaultRolloverStrategy max="12" />
|
||||
</RollingFile>
|
||||
|
||||
<!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
<!-- F I L E _ E R R O R - A P P E N D E R -->
|
||||
<!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
<RollingFile name="FILE_ERROR" append="true" fileName="${baseDir}/services_error.log" filePattern="${baseDir}/$${date:yyyy-MM}/services-error-%d{yyyy-MM-dd}.log.gz">
|
||||
<ThresholdFilter level="ERROR" onMatch="ACCEPT" onMismatch="DENY" />
|
||||
<PatternLayout>
|
||||
<pattern>%-d{yyyy/MM/dd HH:mm:ss} %-5p [%c] - %m%n</pattern>
|
||||
</PatternLayout>
|
||||
<Policies>
|
||||
<TimeBasedTriggeringPolicy />
|
||||
<SizeBasedTriggeringPolicy size="250 MB"></SizeBasedTriggeringPolicy>
|
||||
</Policies>
|
||||
<DefaultRolloverStrategy max="12" />
|
||||
</RollingFile>
|
||||
</Appenders>
|
||||
|
||||
<!-- LOGGERS -->
|
||||
<Loggers>
|
||||
|
||||
<Logger name="com.ossez" level="TRACE" additivity="false">
|
||||
<AppenderRef ref="CONSOLE" level="DEBUG" />
|
||||
<AppenderRef ref="FILE_DEBUG" level="DEBUG" />
|
||||
<AppenderRef ref="FILE_INFO" level="INFO" />
|
||||
<AppenderRef ref="FILE_WARN" level="WARN" />
|
||||
<AppenderRef ref="FILE_ERROR" level="ERROR" />
|
||||
</Logger>
|
||||
|
||||
|
||||
<root level="TRACE">
|
||||
|
||||
</root>
|
||||
|
||||
</Loggers>
|
||||
|
||||
</Configuration>
|
|
@ -0,0 +1,235 @@
|
|||
### Gradle ###
|
||||
.gradle
|
||||
build/
|
||||
|
||||
# Ignore Gradle GUI config
|
||||
gradle-app.setting
|
||||
|
||||
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
|
||||
!gradle-wrapper.jar
|
||||
|
||||
# Cache of project
|
||||
.gradletasknamecache
|
||||
|
||||
# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
|
||||
# gradle/wrapper/gradle-wrapper.properties
|
||||
|
||||
### Gradle Patch ###
|
||||
**/build/
|
||||
|
||||
### Intellij ###
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
|
||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||
|
||||
# User-specific stuff
|
||||
.idea/**/workspace.xml
|
||||
.idea/**/tasks.xml
|
||||
.idea/**/usage.statistics.xml
|
||||
.idea/**/dictionaries
|
||||
.idea/**/shelf
|
||||
|
||||
# Generated files
|
||||
.idea/**/contentModel.xml
|
||||
|
||||
# Sensitive or high-churn files
|
||||
.idea/**/dataSources/
|
||||
.idea/**/dataSources.ids
|
||||
.idea/**/dataSources.local.xml
|
||||
.idea/**/sqlDataSources.xml
|
||||
.idea/**/dynamic.xml
|
||||
.idea/**/uiDesigner.xml
|
||||
.idea/**/dbnavigator.xml
|
||||
|
||||
# Gradle
|
||||
.idea/**/gradle.xml
|
||||
.idea/**/libraries
|
||||
|
||||
# Gradle and Maven with auto-import
|
||||
# When using Gradle or Maven with auto-import, you should exclude module files,
|
||||
# since they will be recreated, and may cause churn. Uncomment if using
|
||||
# auto-import.
|
||||
# .idea/modules.xml
|
||||
# .idea/*.iml
|
||||
# .idea/modules
|
||||
# *.iml
|
||||
# *.ipr
|
||||
|
||||
# CMake
|
||||
cmake-build-*/
|
||||
|
||||
# Mongo Explorer plugin
|
||||
.idea/**/mongoSettings.xml
|
||||
|
||||
# File-based project format
|
||||
*.iws
|
||||
|
||||
# IntelliJ
|
||||
out/
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Cursive Clojure plugin
|
||||
.idea/replstate.xml
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
|
||||
# Editor-based Rest Client
|
||||
.idea/httpRequests
|
||||
|
||||
# Android studio 3.1+ serialized cache file
|
||||
.idea/caches/build_file_checksums.ser
|
||||
|
||||
### Intellij Patch ###
|
||||
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
|
||||
|
||||
# *.iml
|
||||
# modules.xml
|
||||
# .idea/misc.xml
|
||||
# *.ipr
|
||||
|
||||
# Sonarlint plugin
|
||||
.idea/sonarlint
|
||||
|
||||
|
||||
### Intellij+iml ###
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
|
||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||
|
||||
# User-specific stuff
|
||||
.idea/**/workspace.xml
|
||||
.idea/**/tasks.xml
|
||||
.idea/**/usage.statistics.xml
|
||||
.idea/**/dictionaries
|
||||
.idea/**/shelf
|
||||
|
||||
# Generated files
|
||||
.idea/**/contentModel.xml
|
||||
|
||||
# Sensitive or high-churn files
|
||||
.idea/**/dataSources/
|
||||
.idea/**/dataSources.ids
|
||||
.idea/**/dataSources.local.xml
|
||||
.idea/**/sqlDataSources.xml
|
||||
.idea/**/dynamic.xml
|
||||
.idea/**/uiDesigner.xml
|
||||
.idea/**/dbnavigator.xml
|
||||
|
||||
# Gradle
|
||||
.idea/**/gradle.xml
|
||||
.idea/**/libraries
|
||||
|
||||
# Gradle and Maven with auto-import
|
||||
# When using Gradle or Maven with auto-import, you should exclude module files,
|
||||
# since they will be recreated, and may cause churn. Uncomment if using
|
||||
# auto-import.
|
||||
# .idea/modules.xml
|
||||
# .idea/*.iml
|
||||
# .idea/modules
|
||||
# *.iml
|
||||
# *.ipr
|
||||
|
||||
# CMake
|
||||
cmake-build-*/
|
||||
|
||||
# Mongo Explorer plugin
|
||||
.idea/**/mongoSettings.xml
|
||||
|
||||
# File-based project format
|
||||
*.iws
|
||||
|
||||
# IntelliJ
|
||||
out/
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Cursive Clojure plugin
|
||||
.idea/replstate.xml
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
|
||||
# Editor-based Rest Client
|
||||
.idea/httpRequests
|
||||
|
||||
# Android studio 3.1+ serialized cache file
|
||||
.idea/caches/build_file_checksums.ser
|
||||
|
||||
### Intellij+iml Patch ###
|
||||
# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023
|
||||
|
||||
*.iml
|
||||
modules.xml
|
||||
.idea/misc.xml
|
||||
*.ipr
|
||||
|
||||
### Maven ###
|
||||
target/
|
||||
pom.xml.tag
|
||||
pom.xml.releaseBackup
|
||||
pom.xml.versionsBackup
|
||||
pom.xml.next
|
||||
release.properties
|
||||
dependency-reduced-pom.xml
|
||||
buildNumber.properties
|
||||
.mvn/timing.properties
|
||||
.mvn/wrapper/maven-wrapper.jar
|
||||
.flattened-pom.xml
|
||||
|
||||
# CMake
|
||||
cmake-build-*/
|
||||
|
||||
# Mongo Explorer plugin
|
||||
.idea/**/mongoSettings.xml
|
||||
|
||||
# File-based project format
|
||||
*.iws
|
||||
|
||||
# IntelliJ
|
||||
out/
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Cursive Clojure plugin
|
||||
.idea/replstate.xml
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
|
||||
# Editor-based Rest Client
|
||||
.idea/httpRequests
|
||||
|
||||
# Android studio 3.1+ serialized cache file
|
||||
.idea/caches/build_file_checksums.ser
|
||||
|
||||
### Intellij Patch ###
|
||||
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
|
||||
|
||||
# *.iml
|
||||
# modules.xml
|
||||
# .idea/misc.xml
|
||||
# *.ipr
|
||||
|
||||
# Sonarlint plugin
|
||||
.idea/sonarlint
|
|
@ -0,0 +1,79 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.ossez</groupId>
|
||||
<artifactId>discourse</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<name>discourse</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.ossez</groupId>
|
||||
<artifactId>parent-java</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../parent-java</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.11</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>4.5.13</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.8.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>joda-time</groupId>
|
||||
<artifactId>joda-time</artifactId>
|
||||
<version>2.10.10</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.persistence</groupId>
|
||||
<artifactId>javax.persistence-api</artifactId>
|
||||
<version>2.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>discourse</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>${maven-compiler-plugin.version}</version>
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<!-- testing -->
|
||||
<assertj.version>3.6.1</assertj.version>
|
||||
<asspectj.version>1.8.9</asspectj.version>
|
||||
<jmh-core.version>1.19</jmh-core.version>
|
||||
<jmh-generator.version>1.19</jmh-generator.version>
|
||||
<!-- plugins -->
|
||||
<maven-surefire-plugin.version>2.22.1</maven-surefire-plugin.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,55 @@
|
|||
package com.ossez.toolkits.discourse.common.model.entity;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
@Entity
|
||||
@Table(catalog = "ossez_bbs", name = "bbsossez_forum_attach")
|
||||
public class BBSOssezForumAttach implements Serializable {
|
||||
private static final long serialVersionUID = 5530454436970805656L;
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(BBSOssezForumAttach.class);
|
||||
|
||||
|
||||
@Id
|
||||
@Column(name = "aid")
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private long id = 0;
|
||||
|
||||
@Column(name = "attachment")
|
||||
private String attachment;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public BBSOssezForumAttach() {
|
||||
|
||||
}
|
||||
|
||||
public static long getSerialVersionUID() {
|
||||
return serialVersionUID;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
||||
public String getAttachment() {
|
||||
return attachment;
|
||||
}
|
||||
|
||||
public void setAttachment(String attachment) {
|
||||
this.attachment = attachment;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
package com.ossez.toolkits.discourse.common.model.entity;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
@Entity
|
||||
@Table(catalog = "ossez_bbs", name = "bbsossez_forum_post")
|
||||
public class BBSOssezForumPost implements Serializable {
|
||||
private static final long serialVersionUID = 5530454436970805656L;
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(BBSOssezForumPost.class);
|
||||
|
||||
|
||||
@Id
|
||||
@Column(name = "pid")
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private long id = 0;
|
||||
|
||||
@Column(name = "subject")
|
||||
private String subject;
|
||||
|
||||
@Column(name = "message")
|
||||
private String message;
|
||||
|
||||
@Column(name = "tid")
|
||||
private Long tid;
|
||||
|
||||
@Column(name = "dateline")
|
||||
private Long dateline;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public BBSOssezForumPost() {
|
||||
|
||||
}
|
||||
|
||||
public static long getSerialVersionUID() {
|
||||
return serialVersionUID;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getSubject() {
|
||||
return subject;
|
||||
}
|
||||
|
||||
public void setSubject(String subject) {
|
||||
this.subject = subject;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public Long getTid() {
|
||||
return tid;
|
||||
}
|
||||
|
||||
public void setTid(Long tid) {
|
||||
this.tid = tid;
|
||||
}
|
||||
|
||||
public Long getDateline() {
|
||||
return dateline;
|
||||
}
|
||||
|
||||
public void setDateline(Long dateline) {
|
||||
this.dateline = dateline;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
package com.ossez.toolkits.discourse.common.model.request;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
/**
|
||||
* SearchRequest Object, UI can send search String and related pagination
|
||||
*
|
||||
* @author YuCheng Hu
|
||||
*/
|
||||
public class TopicRequest implements Serializable {
|
||||
private static final long serialVersionUID = 6474765081240948885L;
|
||||
|
||||
|
||||
private String title;
|
||||
private Integer topic_id;
|
||||
private String raw;
|
||||
private Integer category;
|
||||
private String target_recipients;
|
||||
private String archetype;
|
||||
private String created_at;
|
||||
|
||||
public static long getSerialVersionUID() {
|
||||
return serialVersionUID;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public Integer getTopic_id() {
|
||||
return topic_id;
|
||||
}
|
||||
|
||||
public void setTopic_id(Integer topic_id) {
|
||||
this.topic_id = topic_id;
|
||||
}
|
||||
|
||||
public String getRaw() {
|
||||
return raw;
|
||||
}
|
||||
|
||||
public void setRaw(String raw) {
|
||||
this.raw = raw;
|
||||
}
|
||||
|
||||
public Integer getCategory() {
|
||||
return category;
|
||||
}
|
||||
|
||||
public void setCategory(Integer category) {
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
public String getTarget_recipients() {
|
||||
return target_recipients;
|
||||
}
|
||||
|
||||
public void setTarget_recipients(String target_recipients) {
|
||||
this.target_recipients = target_recipients;
|
||||
}
|
||||
|
||||
public String getArchetype() {
|
||||
return archetype;
|
||||
}
|
||||
|
||||
public void setArchetype(String archetype) {
|
||||
this.archetype = archetype;
|
||||
}
|
||||
|
||||
public String getCreated_at() {
|
||||
return created_at;
|
||||
}
|
||||
|
||||
public void setCreated_at(String created_at) {
|
||||
this.created_at = created_at;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,130 @@
|
|||
package discourse.common.model.response;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* MyFileResponse for API my file response
|
||||
*
|
||||
* @author YuCheng Hu
|
||||
*/
|
||||
public class MyFileResponse implements Serializable {
|
||||
private static final long serialVersionUID = -5103349220463423614L;
|
||||
|
||||
private Long id;
|
||||
private String azureInputFileUUID;
|
||||
private String azureInputFileETag;
|
||||
private String azureOutputFileUUID;
|
||||
private String azureOutputFileETag;
|
||||
private String customerName;
|
||||
private String inputFileName;
|
||||
private Integer fileCountRow;
|
||||
private Integer fileCountAliasMatch;
|
||||
private Integer fileCountDirectMatch;
|
||||
private Integer fileCountNoMatch;
|
||||
private String dateCreated;
|
||||
private String uuid;
|
||||
|
||||
public String getAzureInputFileUUID() {
|
||||
return azureInputFileUUID;
|
||||
}
|
||||
|
||||
public void setAzureInputFileUUID(String azureInputFileUUID) {
|
||||
this.azureInputFileUUID = azureInputFileUUID;
|
||||
}
|
||||
|
||||
public String getAzureInputFileETag() {
|
||||
return azureInputFileETag;
|
||||
}
|
||||
|
||||
public void setAzureInputFileETag(String azureInputFileETag) {
|
||||
this.azureInputFileETag = azureInputFileETag;
|
||||
}
|
||||
|
||||
public String getAzureOutputFileUUID() {
|
||||
return azureOutputFileUUID;
|
||||
}
|
||||
|
||||
public void setAzureOutputFileUUID(String azureOutputFileUUID) {
|
||||
this.azureOutputFileUUID = azureOutputFileUUID;
|
||||
}
|
||||
|
||||
public String getAzureOutputFileETag() {
|
||||
return azureOutputFileETag;
|
||||
}
|
||||
|
||||
public void setAzureOutputFileETag(String azureOutputFileETag) {
|
||||
this.azureOutputFileETag = azureOutputFileETag;
|
||||
}
|
||||
|
||||
public String getCustomerName() {
|
||||
return customerName;
|
||||
}
|
||||
|
||||
public void setCustomerName(String customerName) {
|
||||
this.customerName = customerName;
|
||||
}
|
||||
|
||||
public String getInputFileName() {
|
||||
return inputFileName;
|
||||
}
|
||||
|
||||
public void setInputFileName(String inputFileName) {
|
||||
this.inputFileName = inputFileName;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Integer getFileCountRow() {
|
||||
return fileCountRow;
|
||||
}
|
||||
|
||||
public void setFileCountRow(Integer fileCountRow) {
|
||||
this.fileCountRow = fileCountRow;
|
||||
}
|
||||
|
||||
public Integer getFileCountAliasMatch() {
|
||||
return fileCountAliasMatch;
|
||||
}
|
||||
|
||||
public void setFileCountAliasMatch(Integer fileCountAliasMatch) {
|
||||
this.fileCountAliasMatch = fileCountAliasMatch;
|
||||
}
|
||||
|
||||
public Integer getFileCountDirectMatch() {
|
||||
return fileCountDirectMatch;
|
||||
}
|
||||
|
||||
public void setFileCountDirectMatch(Integer fileCountDirectMatch) {
|
||||
this.fileCountDirectMatch = fileCountDirectMatch;
|
||||
}
|
||||
|
||||
public Integer getFileCountNoMatch() {
|
||||
return fileCountNoMatch;
|
||||
}
|
||||
|
||||
public void setFileCountNoMatch(Integer fileCountNoMatch) {
|
||||
this.fileCountNoMatch = fileCountNoMatch;
|
||||
}
|
||||
|
||||
public String getDateCreated() {
|
||||
return dateCreated;
|
||||
}
|
||||
|
||||
public void setDateCreated(String dateCreated) {
|
||||
this.dateCreated = dateCreated;
|
||||
}
|
||||
|
||||
public String getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public void setUuid(String uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package discourse.common.model.response;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* SearchResponse from Remote Source
|
||||
*
|
||||
* @author YuCheng Hu
|
||||
*/
|
||||
public class SearchResponse implements Serializable {
|
||||
private static final long serialVersionUID = -2014480627591149391L;
|
||||
|
||||
|
||||
private String uuid;
|
||||
private Date currentDate;
|
||||
|
||||
public static long getSerialVersionUID() {
|
||||
return serialVersionUID;
|
||||
}
|
||||
|
||||
public String getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public void setUuid(String uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public Date getCurrentDate() {
|
||||
return currentDate;
|
||||
}
|
||||
|
||||
public void setCurrentDate(Date currentDate) {
|
||||
this.currentDate = currentDate;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,135 @@
|
|||
package com.ossez.toolkits.discourse;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.ossez.toolkits.discourse.common.model.entity.BBSOssezForumAttach;
|
||||
import com.ossez.toolkits.discourse.common.model.entity.BBSOssezForumPost;
|
||||
import com.ossez.toolkits.discourse.common.model.request.TopicRequest;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
import org.apache.http.HttpHeaders;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
/**
|
||||
* Test Logger and function
|
||||
*
|
||||
* @author YuCheng Hu
|
||||
*/
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class DiscourseTopicsImportTest {
|
||||
private static Logger logger = LoggerFactory.getLogger(DiscourseTopicsImportTest.class);
|
||||
|
||||
|
||||
@BeforeAll
|
||||
protected void setUp() throws Exception {
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
protected void tearDown() throws Exception {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests search functionality for the customer object.
|
||||
*/
|
||||
@Test
|
||||
public void testPost() throws IOException, InterruptedException {
|
||||
List<String> idList = FileUtils.readLines(new File("C:\\Users\\yhu\\Pictures\\Pics\\2021-01\\1.txt"));
|
||||
for (String id : idList) {
|
||||
processPost(NumberUtils.toLong(id));
|
||||
Thread.sleep(6000);
|
||||
// break;
|
||||
|
||||
}
|
||||
|
||||
|
||||
// make sure the customer was found
|
||||
// assertNotNull(bbsOssezForumPost);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDateTime() throws IOException {
|
||||
DateTime dateTime = new DateTime(1256834117 * 1000L);
|
||||
System.out.println(dateTime.toString());
|
||||
|
||||
}
|
||||
|
||||
private void processPost(Long tid) throws IOException {
|
||||
String postCtx = StringUtils.EMPTY;
|
||||
|
||||
// BBSOssezForumPost bbsOssezForumPost = PostFactory.getBBSOssezForumPostTid(tid);
|
||||
// if (bbsOssezForumPost == null)
|
||||
// return;
|
||||
//
|
||||
// logger.debug("Questions Content - {}", bbsOssezForumPost.getSubject());
|
||||
//
|
||||
// String postCtx = bbsOssezForumPost.getMessage();
|
||||
//// logger.debug(">>>>{}", postCtx);
|
||||
//
|
||||
//
|
||||
// String pattern = "\\[attach\\]((\\d)*?)\\[\\/attach\\]";
|
||||
//
|
||||
// // Create a Pattern object
|
||||
// Pattern r = Pattern.compile(pattern);
|
||||
//
|
||||
// // Now create matcher object.
|
||||
// Matcher m = r.matcher(postCtx);
|
||||
//
|
||||
// while (m.find()) {
|
||||
// String attachId = StringUtils.substringBetween(m.group(0), "[attach]", "[/attach]");
|
||||
// logger.debug("{}", attachId);
|
||||
// BBSOssezForumAttach bbsOssezForumAttach = PostFactory.getBBSOssezForumAttach(NumberUtils.toLong(attachId));
|
||||
// if (bbsOssezForumAttach!= null) {
|
||||
// String fullURL = "![](https://cdn.ossez.com/com-ossez-www/data/attachment/forum/" + bbsOssezForumAttach.getAttachment() + ")";
|
||||
// postCtx = StringUtils.replace(postCtx, m.group(0), fullURL);
|
||||
// }
|
||||
// }
|
||||
|
||||
logger.debug("{}", postCtx);
|
||||
|
||||
|
||||
CloseableHttpClient client = HttpClients.createDefault();
|
||||
|
||||
HttpPost httpPost = new HttpPost("https://www.ossez.com/posts.json");
|
||||
httpPost.setHeader(HttpHeaders.CONTENT_TYPE, "application/json; charset=UTF-8");
|
||||
httpPost.setHeader("Api-Key", "8d789c529c4c22bf1dac3de7dbe7b29af10f2429aeb9a1914eff6da70c2265a9");
|
||||
httpPost.setHeader("Api-Username", "honeymoose");
|
||||
|
||||
TopicRequest topicRequest = new TopicRequest();
|
||||
topicRequest.setTitle(bbsOssezForumPost.getSubject());
|
||||
topicRequest.setRaw(postCtx);
|
||||
topicRequest.setCreated_at(new DateTime(bbsOssezForumPost.getDateline() * 1000L).toString() );
|
||||
topicRequest.setCategory(30);
|
||||
|
||||
StringEntity postingString = new StringEntity(new Gson().toJson(topicRequest), StandardCharsets.UTF_8);
|
||||
|
||||
httpPost.setEntity(postingString);
|
||||
|
||||
|
||||
CloseableHttpResponse response = client.execute(httpPost);
|
||||
|
||||
logger.info("{}", EntityUtils.toString(response.getEntity()), StandardCharsets.UTF_8);
|
||||
client.close();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"id": 16,
|
||||
"uuid": "35057495-bec8-4288-beec-568c552c88e4",
|
||||
"dateModified": "2020-10-29T11:56:06.630+00:00",
|
||||
"userId": "24548d05-5274-4ea0-82aa-f1693cb82045",
|
||||
"userName": "Hu, Yucheng",
|
||||
"userEmail": "Yucheng.Hu@insight.com",
|
||||
"customerName": "license (1).txt",
|
||||
"inputFileName": "license (1).txt",
|
||||
"fileRowCount": null,
|
||||
"fileMatchCount": null,
|
||||
"fileStatus": null,
|
||||
"fileSHA3": "069f7222e83cecec5663c47b0e2736709c425448b47962d1827ca958",
|
||||
"createDate": "2020-10-29T11:56:06.630+00:00"
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<Configuration status="WARN">
|
||||
<Appenders>
|
||||
<Console name="Console" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
|
||||
</Console>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Logger name="com.insight.sco" level="trace">
|
||||
<AppenderRef ref="Console"/>
|
||||
</Logger>
|
||||
<Root level="error">
|
||||
<AppenderRef ref="Console"/>
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>toolkits</artifactId>
|
||||
<name>toolkits</name>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.ossez</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<modules>
|
||||
<module>discourse</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
Loading…
Reference in New Issue