|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.ResourceBundle
com.myjavatools.lib.human.HumanInterface
public class HumanInterface
Title: My Java Tools Library
Description: This class, HumanInterface, contains a bunch of funny methods to deal with converting data to human-readable form, and, at times, back.
Copyright: This is public domain; The right of people to use, distribute, copy or improve the contents of the following may not be restricted.
Company: My Java Tools
Field Summary |
---|
Fields inherited from class java.util.ResourceBundle |
---|
parent |
Constructor Summary | |
---|---|
HumanInterface()
|
Method Summary | |
---|---|
java.util.Enumeration<java.lang.String> |
getKeys()
|
protected java.lang.Object |
handleGetObject(java.lang.String key)
|
static java.lang.String |
humanTime(long time)
turns time into an approximate humanized value |
static java.lang.String |
humanTime(long time,
java.lang.String smallestUnitName)
turns time into an approximate humanized value |
static java.lang.String |
humanWhen(long timestamp)
turns timestamp into an approximate form used by humans |
static java.lang.String |
humanWhen(long timestamp,
java.lang.String unitName)
turns timestamp into an approximate form used by humans |
static Logical.LogicalConstant |
isTrue(java.lang.String string)
Extracts logical value from a string |
static boolean |
isVowel(char c)
Checks whether a character is a latin vowel. |
java.lang.String |
localizedCantTellTime(long time)
localized version of stringifier for an unknown time period |
java.lang.String |
localizedHumanWhen(long timestamp,
java.lang.String unitName)
localized version of humanWhen |
protected Logical.LogicalConstant |
localizedIsTrue(java.lang.String string)
localized version of isTrue() |
protected boolean |
localizedIsVowel(char c)
localized vowel test |
java.lang.String |
localizedVeryLittleTime(long time,
com.myjavatools.lib.human.HumanInterface.TimeUnit unit)
localized version of stringifier for a very small time period |
static java.lang.String |
plurality(java.lang.String number,
java.lang.String what)
returns plurality representation of a number and its unit |
static java.lang.String |
plurality(java.lang.String number,
java.lang.String item,
java.lang.String ps)
returns plurality representation of a number and its unit |
static java.lang.String |
timestampToDatetime(long timestamp)
turns a timestamp into a readable timestamp string (see example) |
static boolean |
toBoolean(java.lang.String string,
boolean defaultValue)
Extracts Boolean value from a string |
static java.lang.String |
toPlural(java.lang.String word)
returns plural of an English word (too simplistic so far) |
Methods inherited from class java.util.ResourceBundle |
---|
getBundle, getBundle, getBundle, getLocale, getObject, getString, getStringArray, setParent |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public HumanInterface()
Method Detail |
---|
public java.util.Enumeration<java.lang.String> getKeys()
getKeys
in class java.util.ResourceBundle
protected java.lang.Object handleGetObject(java.lang.String key)
handleGetObject
in class java.util.ResourceBundle
public static final boolean isVowel(char c)
c
- the char to tests
protected boolean localizedIsVowel(char c)
c
- char
public static final Logical.LogicalConstant isTrue(java.lang.String string)
string
-
isTrue("YeS")
returns LogicalConstant.TRUE;isTrue("false")
returns LogicalConstant.TRUE;isTrue(null)
returns LogicalConstant.TRUE.protected Logical.LogicalConstant localizedIsTrue(java.lang.String string)
string
- String
public static boolean toBoolean(java.lang.String string, boolean defaultValue)
string
- defaultValue
-
toBoolean("YeS", false)
returns true;toBoolean("false", false)
returns false;toBoolean(null, true)
returns true.public static java.lang.String timestampToDatetime(long timestamp)
timestamp
- long
timestampToDatetime(1000000000)
returns "010908_1846_40"
which means September 08, 2001 18:46:40
public static final java.lang.String humanTime(long time)
time
- long time in milliseconds
humanTime(4321)
returns "4 seconds"humanTime(518520)
returns "8 minutes"public static final java.lang.String humanTime(long time, java.lang.String smallestUnitName)
time
- long time in millisecondssmallestUnitName
- String the name of the smallest unit to use
humanTime(4321, "minute")
returns "0 minutes"humanTime(518520, "minute")
returns "8 minutes"public java.lang.String localizedCantTellTime(long time)
time
- long
public java.lang.String localizedVeryLittleTime(long time, com.myjavatools.lib.human.HumanInterface.TimeUnit unit)
time
- longunit
- TimeUnit
public static final java.lang.String humanWhen(long timestamp)
timestamp
- long the moment to stringify
humanTime(System.currentTimeMillis() + 4321)
returns "in 4 seconds"humanTime(System.currentTimeMillis() - 518520)
returns "8 minutes ago"public static final java.lang.String humanWhen(long timestamp, java.lang.String unitName)
timestamp
- long the moment to stringifyunitName
- String the name of the smallest unit to use
humanTime(System.currentTimeMillis() + 4321)
returns "in 4 seconds"humanTime(System.currentTimeMillis() - 518520)
returns "8 minutes ago"public java.lang.String localizedHumanWhen(long timestamp, java.lang.String unitName)
timestamp
- longunitName
- String
public static java.lang.String toPlural(java.lang.String word)
word
- String the word
toPlural("cat")
returns "cats"toPlural("plurality")
returns "pluralities"toPlural("catfish")
returns "catfishes"toPlural("itch")
returns "itches"public static java.lang.String plurality(java.lang.String number, java.lang.String what)
number
- String number of unitswhat
- String unit name
plurality(0, "minute")
returns "0 minutes"plurality(8, "inch")
returns "8 inches"plurality(1, "day")
returns "1 day"public static java.lang.String plurality(java.lang.String number, java.lang.String item, java.lang.String ps)
number
- String number of unitsitem
- String unit nameps
- String post scriptum - what to add if there is something to add to, see examples
plurality(0, "minute", "long")
returns ""plurality(8, "inch", "wide")
returns "8 inches wide"plurality(1, "day", "ago")
returns "1 day ago"
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |