Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/libraries/Maven__joda_time_joda_time_2_9_7.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/libraries/Maven__org_apiguardian_apiguardian_api_1_0_0.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/libraries/Maven__org_opentest4j_opentest4j_1_1_1.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions java-interview.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?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/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-api:5.4.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.apiguardian:apiguardian-api:1.0.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.opentest4j:opentest4j:1.1.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-commons:1.4.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-engine:5.4.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-engine:1.4.2" level="project" />
<orderEntry type="library" name="Maven: joda-time:joda-time:2.9.7" level="project" />
</component>
</module>
43 changes: 37 additions & 6 deletions src/main/java/com/github/archarithms/App.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,46 @@
package com.github.archarithms;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class App
{
public static String convertToTitleCase(final String inpStr)
{
return inpStr;
public static String convertToTitleCase(final String inpStr) throws Exception {
if (inpStr == null) {
throw new Exception();
}
StringBuilder sb = new StringBuilder();
// Split up the string and remove all of the garbage characters
String[] splitInput = inpStr.split("]|-|_|\\[|/");
for (int i = 0; i < splitInput.length; i++) {
// Set the entire string to lowercase
String s = splitInput[i].toLowerCase();
// check to see if the string contains anything
if (s.length() > 0) {
// Set the first letter to Uppercase if possible
String first = s.substring(0, 1).toUpperCase();
String temp = s.substring(1);
// Concat the 2 strings and append it to the StringBuilder
sb.append(first.concat(temp));
}
// Append a space to the StringBuilder this isn't the last string
if (i < splitInput.length - 1) {
sb.append(" ");
}
}
return sb.toString();
}

public static String convertUnixToDateString(final Long inpUnixSeconds)
{
return String.valueOf(inpUnixSeconds);
public static String convertUnixToDateString(final Long inpUnixSeconds) throws Exception {
if (inpUnixSeconds == null) {
throw new Exception();
}
// Convert to milliseconds
Long millis = inpUnixSeconds * 1000;
// Using DateFormat with a Date to make get the correct format
Date date = new Date(millis);
DateFormat format = new SimpleDateFormat("MMMMMMMMM d, y");
return format.format(date);
}
}
11 changes: 10 additions & 1 deletion src/test/java/com/github/archarithms/test/DateStringTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class DateStringTests
* Test the testConvertUnixToDateString method
*/
@Test
public void testConvertUnixToDateString() {
public void testConvertUnixToDateString() throws Exception {
String testStr = "July 4, 2017";
assertTrue(testStr.equals(App.convertUnixToDateString(1499144400L)));
}
Expand All @@ -33,4 +33,13 @@ public void testConvertUnixToDateString() {
public void testNullCase() {
assertThrows(Exception.class, () -> App.convertUnixToDateString(null));
}

/**
* Test the testMyBirthday method
*/
@Test
public void testMyBirthday() throws Exception {
String testStr = "August 14, 1998";
assertTrue(testStr.equals(App.convertUnixToDateString(903114000L)));
}
}
29 changes: 24 additions & 5 deletions src/test/java/com/github/archarithms/test/TitleCaseTests.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.github.archarithms.test;

import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Test;

import com.github.archarithms.App;

import java.text.ParseException;

import static org.junit.jupiter.api.Assertions.*;

/**
* TitleCaseTests unit tests for simple App.
*/
Expand All @@ -20,7 +22,7 @@ public class TitleCaseTests
* Test the testConvertToTitleCase method
*/
@Test
public void testConvertToTitleCase() {
public void testConvertToTitleCase() throws Exception {
String testStr = "Title Case";
assertTrue(testStr.equals(App.convertToTitleCase("TITLE_CASE")));
}
Expand All @@ -29,7 +31,7 @@ public void testConvertToTitleCase() {
* Test the testNumbers method
*/
@Test
public void testNumbers() {
public void testNumbers() throws Exception {
String testStr = "Number 3";
assertTrue(testStr.equals(App.convertToTitleCase("NUMBER_3")));
}
Expand All @@ -38,8 +40,25 @@ public void testNumbers() {
* Test the testOtherChars method
*/
@Test
public void testOtherChars() {
public void testOtherChars() throws Exception {
String testStr = "Truth Track";
assertTrue(testStr.equals(App.convertToTitleCase("TRUTH-TRACK")));
}

/**
* Test the testMultipleChars method
*/
@Test
public void testMultipleChars() throws Exception {
String testStr = "Case Three Extra Chars";
assertTrue(testStr.equals(App.convertToTitleCase("CASE-THREE_extra[chars]///")));
}

/**
* Test the testNullString method
*/
@Test
public void testNullString() {
assertThrows(Exception.class, () -> App.convertToTitleCase(null));
}
}