# 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:
YuCheng Hu
2021-04-12 22:20:09 -04:00
parent 76c7f1b984
commit fb82d4b70f
47 changed files with 2883 additions and 127 deletions
@@ -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;
}
}
+97
View File
@@ -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>