Skip to content

Commit 219b352

Browse files
committed
Merge branch 'develop'
2 parents bf5f7f9 + e0147b4 commit 219b352

File tree

18 files changed

+869
-223
lines changed

18 files changed

+869
-223
lines changed

.idea/artifacts/Support_jar.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/META-INF/MANIFEST.MF

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Manifest-Version: 1.0
2+
Implementation-Title: jimmyhowe.support
3+
Implementation-Version: Build 1 Beta
4+
Specification-Vendor: JimmyHowe.com 2016
5+
Name: jimmyhowe/support/
6+
Specification-Title: JimmyHowe.com Java Support Package
7+
Specification-Version: 1.0b
8+
Implementation-Vendor: JimmyHowe.com
9+
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
package com.jimmyhowe.support;
2+
3+
import java.util.Scanner;
4+
5+
/**
6+
* Created by Jimmy on 03/12/2016.
7+
*/
8+
public class ConsoleHelper
9+
{
10+
/**
11+
* The Scanner Object for reading input from console
12+
*/
13+
private static Scanner console = new Scanner(System.in);
14+
15+
/**
16+
* @return Console
17+
*/
18+
public static Scanner Console()
19+
{
20+
return console;
21+
}
22+
23+
/**
24+
* UTILITY: Print Header
25+
* <p>
26+
* Prints a fancy header surrounded by stars
27+
*
28+
* @param headerText
29+
*/
30+
public static void printHeader(String headerText)
31+
{
32+
String[] headerRows = { "", "" }; // The top and bottom row of stars
33+
34+
String headerChar = "*";
35+
36+
String formattedText = "%s %s %s\n"; // the middle row formatted text
37+
38+
int padding = 4;
39+
40+
/*
41+
Build the top and bottom rows by adding the length of the header text to the padding,
42+
and on each iteration, concatenating the header row with itself, adding the header
43+
character
44+
*/
45+
46+
for ( int i = 0; i < headerText.length() + padding; i++ )
47+
{
48+
49+
headerRows[0] += headerChar;
50+
headerRows[1] += headerChar;
51+
}
52+
53+
// Print out the header rows in order
54+
55+
System.out.println(headerRows[0]);
56+
System.out.printf(formattedText, headerChar, headerText, headerChar);
57+
System.out.println(headerRows[1]);
58+
}
59+
60+
/**
61+
* UTILITY: Print Menu Option
62+
* <p>
63+
* Prints a formatted Menu Option
64+
*
65+
* @param number
66+
* @param text
67+
*/
68+
public static void printMenuOption(int number, String text)
69+
{
70+
System.out.printf("\t%s\t%s\n", number, text);
71+
}
72+
73+
/**
74+
* UTILITY: Print Blank Line
75+
* <p>
76+
* Prints a blank line to the console
77+
*/
78+
private static void printBlankLine()
79+
{
80+
System.out.print('\n');
81+
82+
}
83+
84+
/**
85+
* UTILITY: Show Error
86+
* <p>
87+
* Prints a formatted error to the console
88+
*
89+
* @param text
90+
*/
91+
private static void showError(String text)
92+
{
93+
String formattedErrorText = "\t!!! %s !!!\n";
94+
95+
printBlankLine();
96+
System.out.printf(formattedErrorText, text);
97+
printBlankLine();
98+
System.out.print("\tPress ENTER to return!");
99+
console.nextLine();
100+
printBlankLine();
101+
}
102+
103+
/**
104+
* UTILITY: Ask Yes/No
105+
* <p>
106+
* Print a yes/no message to the screen and return the response
107+
*
108+
* @param question
109+
* @return
110+
*/
111+
public static String askYesNo(String question)
112+
{
113+
String formattedText = "\n\t%s (y/n): ";
114+
115+
System.out.printf(formattedText, question);
116+
117+
return console.nextLine();
118+
}
119+
120+
/**
121+
* UTILITY: Ask For
122+
* <p>
123+
* Print a message to the screen using the passed context string
124+
* and return a string reply
125+
*
126+
* @param context
127+
* @return
128+
*/
129+
public static String askFor(String context)
130+
{
131+
String formattedText = "\n\tPlease enter your %s: ";
132+
133+
System.out.printf(formattedText, context);
134+
135+
return console.nextLine();
136+
}
137+
138+
/**
139+
* UTILITY: Is Yes
140+
* <p>
141+
* This will take a string, and check if it matches y, yes, or true
142+
* and if it does it will return true and if not return false.
143+
*
144+
* @param answer
145+
* @return
146+
*/
147+
public static boolean isYes(String answer)
148+
{
149+
String[] possibleYesAnswers = { "y", "yes", "true" };
150+
151+
for ( String possibleYesAnswer : possibleYesAnswers )
152+
{
153+
if ( answer.toLowerCase().equals(possibleYesAnswer) )
154+
{
155+
return true;
156+
}
157+
}
158+
159+
return false;
160+
}
161+
162+
/**
163+
* Say Goodbye
164+
* <p>
165+
* Exits the Program
166+
*/
167+
private static void sayGoodbye()
168+
{
169+
printBlankLine();
170+
printHeader("Bye Bye");
171+
172+
System.exit(0);
173+
}
174+
}

src/com/jimmyhowe/support/Main.java

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/com/jimmyhowe/support/Str.java

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
package com.jimmyhowe.support;
2+
3+
import java.util.List;
4+
import java.util.StringJoiner;
5+
6+
/**
7+
* String Utility Helper
8+
*/
9+
public class Str
10+
{
11+
/**
12+
* Converts CamelCase to Camel Case
13+
*
14+
* @param camelCase
15+
*/
16+
public static String CamelCaseToWords(String camelCase)
17+
{
18+
String result = "";
19+
20+
for ( int i = 0; i < camelCase.length(); i++ )
21+
{
22+
Character ch = camelCase.charAt(i);
23+
if ( Character.isUpperCase(ch) )
24+
result += " " + ch;
25+
else
26+
result += ch;
27+
}
28+
29+
return result.trim();
30+
}
31+
32+
/**
33+
* Converts CamelCase to camel case
34+
*
35+
* @param camelCase
36+
*/
37+
public static String CamelCaseToLowerCaseWords(String camelCase)
38+
{
39+
String result = "";
40+
41+
for ( int i = 0; i < camelCase.length(); i++ )
42+
{
43+
Character ch = camelCase.charAt(i);
44+
if ( Character.isUpperCase(ch) )
45+
result += " " + Character.toLowerCase(ch);
46+
else
47+
result += ch;
48+
}
49+
50+
return result.trim();
51+
}
52+
53+
/**
54+
* Converts CamelCase to snake_case
55+
*
56+
* @param camelCase
57+
*/
58+
public static String CamelCaseToSnakeCase(String camelCase)
59+
{
60+
return Str.CamelCaseToLowerCaseWords(camelCase).replace(' ', '_');
61+
}
62+
63+
/**
64+
* Convert String Array to CSV Format
65+
*/
66+
public static String toCsv(List<String> list)
67+
{
68+
return listSeparator(list, ", ");
69+
}
70+
71+
public static String toSpaceSeparated(List<String> list)
72+
{
73+
return listSeparator(list, " ");
74+
}
75+
76+
/**
77+
* Convert String Array to CSV Format
78+
*/
79+
private static String listSeparator(List<String> data, String separator)
80+
{
81+
StringJoiner stringJoiner = new StringJoiner(separator);
82+
83+
data.forEach(stringJoiner::add);
84+
85+
return stringJoiner.toString();
86+
}
87+
88+
/**
89+
* @param delimiter Delimiter
90+
* @param string String
91+
*
92+
* @return Array of Strings
93+
*/
94+
public static String[] explode(String delimiter, String string)
95+
{
96+
String[] split = string.split(delimiter);
97+
98+
return (split.length > 0) ? split : new String[]{ string };
99+
}
100+
101+
/**
102+
* @param strings Array of Strings
103+
*
104+
* @return Imploded Array
105+
*/
106+
public static String implode(String[] strings)
107+
{
108+
return implode(" ", strings);
109+
}
110+
111+
/**
112+
* @param delimiter Delimiter
113+
* @param strings Array of Strings
114+
*
115+
* @return Imploded Array
116+
*/
117+
public static String implode(String delimiter, String[] strings)
118+
{
119+
StringBuilder builder = new StringBuilder();
120+
121+
for ( int i = 0; i < strings.length; i++ )
122+
{
123+
builder.append(strings[i]);
124+
if ( i != strings.length - 1 )
125+
{
126+
builder.append(delimiter);
127+
}
128+
}
129+
130+
return builder.toString();
131+
}
132+
133+
/**
134+
* @param delimiter Delimiter
135+
* @param strings Array of Strings
136+
*
137+
* @return Imploded Array
138+
*/
139+
public static String implode(String delimiter, List<String> strings)
140+
{
141+
StringBuilder builder = new StringBuilder();
142+
143+
for ( int i = 0; i < strings.size(); i++ )
144+
{
145+
builder.append(strings.get(i));
146+
if ( i != strings.size() - 1 )
147+
{
148+
builder.append(delimiter);
149+
}
150+
}
151+
152+
return builder.toString();
153+
}
154+
}

0 commit comments

Comments
 (0)