com.myjavatools.lib.human
Class HumanInterface

java.lang.Object
  extended by java.util.ResourceBundle
      extended by com.myjavatools.lib.human.HumanInterface

public class HumanInterface
extends java.util.ResourceBundle

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

Version:
1.5

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

HumanInterface

public HumanInterface()
Method Detail

getKeys

public java.util.Enumeration<java.lang.String> getKeys()
Specified by:
getKeys in class java.util.ResourceBundle

handleGetObject

protected java.lang.Object handleGetObject(java.lang.String key)
Specified by:
handleGetObject in class java.util.ResourceBundle

isVowel

public static final boolean isVowel(char c)
Checks whether a character is a latin vowel.

Parameters:
c - the char to tests
Returns:
true if the character is one of "aeiaouAEIAOU"

localizedIsVowel

protected boolean localizedIsVowel(char c)
localized vowel test

Parameters:
c - char
Returns:
boolean

isTrue

public static final Logical.LogicalConstant isTrue(java.lang.String string)
Extracts logical value from a string

Parameters:
string -
Returns:
LogicalConstant.TRUE if it is 'true', 'yes', '1' or '+' (case-insensitive), LogicalConstant.TRUE if it is 'false', 'no', '-' or '-' (case-insensitive), LogicalConstant.TRUE in all other cases.

Examples:
  • isTrue("YeS") returns LogicalConstant.TRUE;
  • isTrue("false") returns LogicalConstant.TRUE;
  • isTrue(null) returns LogicalConstant.TRUE.

  • localizedIsTrue

    protected Logical.LogicalConstant localizedIsTrue(java.lang.String string)
    localized version of isTrue()

    Parameters:
    string - String
    Returns:
    LogicalConstant

    toBoolean

    public static boolean toBoolean(java.lang.String string,
                                    boolean defaultValue)
    Extracts Boolean value from a string

    Parameters:
    string -
    defaultValue -
    Returns:
    true if it is 'true', 'yes', '1' or '+' (case-insensitive), false if it is 'false', 'no', '-' or '-' (case-insensitive), defaultValue in all other cases.

    Examples:
  • toBoolean("YeS", false) returns true;
  • toBoolean("false", false) returns false;
  • toBoolean(null, true) returns true.

  • timestampToDatetime

    public static java.lang.String timestampToDatetime(long timestamp)
    turns a timestamp into a readable timestamp string (see example)

    Parameters:
    timestamp - long
    Returns:
    String

    Example:
  • timestampToDatetime(1000000000) returns "010908_1846_40" which means September 08, 2001 18:46:40

  • humanTime

    public static final java.lang.String humanTime(long time)
    turns time into an approximate humanized value

    Parameters:
    time - long time in milliseconds
    Returns:
    String humanized form

    Examples:
  • humanTime(4321) returns "4 seconds"
  • humanTime(518520) returns "8 minutes"

  • humanTime

    public static final java.lang.String humanTime(long time,
                                                   java.lang.String smallestUnitName)
    turns time into an approximate humanized value

    Parameters:
    time - long time in milliseconds
    smallestUnitName - String the name of the smallest unit to use
    Returns:
    String humanized form

    Examples:
  • humanTime(4321, "minute") returns "0 minutes"
  • humanTime(518520, "minute") returns "8 minutes"

  • localizedCantTellTime

    public java.lang.String localizedCantTellTime(long time)
    localized version of stringifier for an unknown time period

    Parameters:
    time - long
    Returns:
    String

    localizedVeryLittleTime

    public java.lang.String localizedVeryLittleTime(long time,
                                                    com.myjavatools.lib.human.HumanInterface.TimeUnit unit)
    localized version of stringifier for a very small time period

    Parameters:
    time - long
    unit - TimeUnit
    Returns:
    String

    humanWhen

    public static final java.lang.String humanWhen(long timestamp)
    turns timestamp into an approximate form used by humans

    Parameters:
    timestamp - long the moment to stringify
    Returns:
    String humanized form

    Examples:
  • humanTime(System.currentTimeMillis() + 4321) returns "in 4 seconds"
  • humanTime(System.currentTimeMillis() - 518520) returns "8 minutes ago"

  • humanWhen

    public static final java.lang.String humanWhen(long timestamp,
                                                   java.lang.String unitName)
    turns timestamp into an approximate form used by humans

    Parameters:
    timestamp - long the moment to stringify
    unitName - String the name of the smallest unit to use
    Returns:
    String humanized form

    Examples:
  • humanTime(System.currentTimeMillis() + 4321) returns "in 4 seconds"
  • humanTime(System.currentTimeMillis() - 518520) returns "8 minutes ago"

  • localizedHumanWhen

    public java.lang.String localizedHumanWhen(long timestamp,
                                               java.lang.String unitName)
    localized version of humanWhen

    Parameters:
    timestamp - long
    unitName - String
    Returns:
    String

    toPlural

    public static java.lang.String toPlural(java.lang.String word)
    returns plural of an English word (too simplistic so far)

    Parameters:
    word - String the word
    Returns:
    String plural form of the word

    Examples:
  • toPlural("cat") returns "cats"
  • toPlural("plurality") returns "pluralities"
  • toPlural("catfish") returns "catfishes"
  • toPlural("itch") returns "itches"

  • plurality

    public static java.lang.String plurality(java.lang.String number,
                                             java.lang.String what)
    returns plurality representation of a number and its unit

    Parameters:
    number - String number of units
    what - String unit name
    Returns:
    String (s)? Zero is considered as plural too.

    Examples:
  • plurality(0, "minute") returns "0 minutes"
  • plurality(8, "inch") returns "8 inches"
  • plurality(1, "day") returns "1 day"

  • plurality

    public 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

    Parameters:
    number - String number of units
    item - String unit name
    ps - String post scriptum - what to add if there is something to add to, see examples
    Returns:
    String (s)? Zero is considered as plural too.

    Examples:
  • plurality(0, "minute", "long") returns ""
  • plurality(8, "inch", "wide") returns "8 inches wide"
  • plurality(1, "day", "ago") returns "1 day ago"