Util

final class Util

The Util class contains various utility methods and constants.

Fields

FPPattern

public static final Pattern FPPattern

NEWLINE

public static final String NEWLINE

The system line separator (“n” on UNIX).

nf

NumberFormat nf

Stores the appropriate NumberFormat for AMPL’s only locale (US) Need to have an instance, as formats are not synchronised

s1

static long s1

t1

static long t1

Constructors

Util

public Util()

Methods

CreateUSFormat

public static NumberFormat CreateUSFormat()

Used by classes which by design don’t have a reference to the ampl object (i.e. Tuple and DataFrame)

IndexFactoryFromObjects

static Object IndexFactoryFromObjects(Object... elements)

Get the internal indexing representation of the elements. If null or zero length, return null; If length = 1 returns getDoubleOrStringFromSingleObject of the object If length > 1 returns a tuple

Parameters:
  • elements

format

public String format(double d)

Formats a number with the proper number format for being understood by AMPL (US)

formatObjectWithBrackets

String formatObjectWithBrackets(Object key)

Returns a string representation of the object: double -> format(double) String -> quoted string Tuple -> Tuple.toString (which has the brackets) (like (1, 2, ‘a’))

Parameters:
  • key

formatObjectWithoutBrackets

String formatObjectWithoutBrackets(Object key)

Returns a string representation of the object: double -> format(double) String -> quoted string Tuple -> Tuple.toString (which does not have brackets) like: 1, 2, ‘a’

Parameters:
  • key

formatObjectWithoutBracketsNoCommas

String formatObjectWithoutBracketsNoCommas(Object key)

Returns a string representation of the object: double -> format(double) String -> quoted string Tuple -> Tuple.toString (which does not have brackets) like: 1 2 ‘a’

Parameters:
  • key

getClassLocation

public static java.net.URL getClassLocation(Class<?> c)

getDoubleOrString

static Object getDoubleOrString(String value)

getDoubleOrStringFromSingleObject

static Object getDoubleOrStringFromSingleObject(Object o)

parseDouble

public static double parseDouble(String s)

Parses numbers, AMPL Style

Parameters:
  • s – string representation
Returns:

Double , or positive/negative infinity, or NaN

print

static void print()

printObjectInfo

static void printObjectInfo(Object key)

quote

public static String quote(String str)

Converts str into an AMPL/SAMPL string by surrounding it with single quotes and escaping quotes and newlines.

splitOnCommas

static Object[] splitOnCommas(String s, int indexarity)

Split the input string on commas, considering that we can have input strings, surrounded by quotes, containing a comma

Parameters:
  • s – string
Returns:

Splitted string

staticFormat

public static String staticFormat(double d)

Formats a number with the proper number format for being understood by AMPL (US)

tic

static void tic()

tic2

static void tic2()

tic3

static void tic3()

toIntWithFlooring

public static int toIntWithFlooring(Object o)

toc

static void toc()

toc2

static void toc2()

toc3

static void toc3()

unquote

public static String unquote(String str)

Unquotes an AMPL string. Returns the same string if it is not a valid AMPL string