Skip to content

Latest commit

 

History

History
119 lines (82 loc) · 3.41 KB

File metadata and controls

119 lines (82 loc) · 3.41 KB

JavaUtil


JavaUtil

Overview, core utilities, simple examples

📖   Documentation / Examples

Package README Javadoc Overview
🛠️    General util org.jutil.util Javadoc
🖥️    GUI (Swing) org.jutil.gui Javadoc
💾    I/O org.jutil.io Javadoc
📱    Application specific org.jutil.app Javadoc

⚡️ Quick overview (more examples are in the READMEs of the package)

Using org.jutil.util.Strings (selected examples)

import org.jutil.util.*;

	... 
	// create a simple headline (e.g. for logging)
	System.out.println(Strings.repeat(30, "*"));
	System.out.println(Strings.center("***", "headline", "***", 30));
	System.out.println(Strings.repeat(30, "*"));	
	
Output:
******************************
***        headline        ***
******************************

	...
	// create line numbers
	int i = 42;
	System.out.println(
		Strings.fillLeft("" + i + ": ", 7, " ") + "some text");
	i += 1000;
	System.out.println(
		Strings.fillLeft("" + i + ": ", 7, " ") + "some other text");
	
Output:
   42: some text
 1042: some other text
   
	...
	Strings.stripIfEndsWith("myFile.json", ".json");             // returns "myFile"

	...
	Strings.listToString(List.of(1, 2, 3), null, ","", false);   // returns "1,2,3"

	...
	Strings.listToString(List.of(1, 2, 3), "   ", ",\n", false);	
	
Output (indented by "   "):
   1,
   2,
   3

	...
	System.out.println(
		Strings.listToString(List.of("This", "is", "a", "text."), "   <a>, "</a>\n", true)); 

Output:
   <a>This</a>
   <a>is</a>
   <a>a</a>
   <a>text.</a>
   
	...
	indent("  ", 3, "text line");          // returns "      text line" (indented by 6 spaces)
	
More detailed examples can be found in the package README or the Javadoc API.

Back to top

Using org.jutil.Util (selected examples)

import org.jutil.Util;

	... 
	Util.notImplementedException();		
	// throws a subclass of RuntimeException and text to identify unimplemented
	// code parts 
	
	...
	Util.sleep(100, false); 	
	// convenience method: sleeps 100ms or until interruption, see 
	// implementation or Javadoc for details
	
	...
	String prompt = Util.prompt("go further: ");		// console IO
	System.out.println("Prompted input: '" + prompt + "'");
	
More detailed examples can be found in the package README or the Javadoc API.

Overview                 Back to top