|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.starhope.util.LibMisc
public class LibMisc
Miscellaneous utility methods that might be useful elsewhere
Field Summary | |
---|---|
private static HashMap<Class<?>,Class<?>> |
extensionClasses
An extension class can be registered to supplement or replace methods in the basic built-in command interpreters. |
(package private) static int |
MAX_SHUTDOWN_TRIES
Maximum number of times to clear the socket input buffer. |
private static Properties |
messages
TODO: document this field (brpocock, Nov 19, 2009) messages (LibMisc) |
Constructor Summary | |
---|---|
LibMisc()
|
Method Summary | |
---|---|
static boolean |
areWeThereYet(AbstractUser thing,
long when)
TODO: document this method (brpocock, Nov 24, 2009) |
static void |
commandJSON(String cmd,
org.json.JSONObject jso,
org.starhope.util.types.CanProcessCommands commandThread,
AbstractUser user,
Class<?> klass)
Execute a command with a certain method signature from klass, passing it the JSON parameters as well as the environment (thread, zone, and user) to run with. |
static double |
distance(AbstractUser from,
AbstractUser to,
long when)
TODO: document this method (brpocock, Nov 24, 2009) |
private static double |
distance(double x1,
double y1,
double x2,
double y2)
TODO: document this method (brpocock, Nov 24, 2009) |
private static String |
formatFutureDate_English(Date targetDate)
|
static String |
formatFutureDate(Date targetDate)
TODO: document this method (brpocock, Jan 18, 2010) |
static String |
formatFutureDate(Date targetDate,
String language,
String dialect)
TODO: document this method (brpocock, Jan 18, 2010) |
static String |
formatMemory(long numBytes)
Create an user-visible string using metric figures accurate to 1 decimal place, expressing an amount of memory in KiB, MiB, &c. |
static String |
genFakeIP(Object o)
Generate something that resembles an IP address, but is clearly not a valid host address. |
static String |
getText(String string)
|
static String |
getText(String string,
String language,
String dialect)
|
static String |
getTextOrDefault(String key,
String fallback)
Look for a string key in the message catalogue. |
static boolean |
hasText(String string)
TODO: document this method (brpocock, Jan 5, 2010) |
static boolean |
hasText(String string,
String language,
String dialect)
TODO: document this method (brpocock, Jan 5, 2010) |
static String |
hexify(byte[] input)
Convert an array of bytes into a string of ASCII hexadecimal nybbles. |
private static void |
initMessages()
Initialize the configured message catalog. |
private static String |
listToDisplay_English(List<String> words)
Internal helper method for listToDisplay(List, String, String) for English. |
private static String |
listToDisplay_Español(List<String> words)
Internal helper method for listToDisplay(List, String, String) for Spanish. |
private static String |
listToDisplay_فرسئ(List<String> words)
Internal helper method for listToDisplay(List, String, String) for Persian. |
static String |
listToDisplay(Collection<? extends Object> words,
String language,
String dialect)
TODO: document this method (brpocock, Jan 12, 2010) |
static String |
listToDisplay(List<String> words,
String language,
String dialect)
Given a list of strings, combine then into a string for display purposes. |
static String |
listToDisplay(Object[] set,
String language,
String dialect)
|
static Class<?> |
loadExtension(Class<?> klass)
Find a substitute class for a command interpreter class with local extensions. |
static int |
makeHashCode(String string)
TODO: document this method (brpocock, Dec 1, 2009) |
static String |
rot13(String msg)
Perform rot-13 on basic alphabetic characters in the font |
static void |
setMaxShutdownTries(int mst)
Set the maximum number of times to clear the socket input buffer. |
static void |
shutdownInput(Socket socket)
This method taken from Apache Tomcat: |
static LinkedHashMap<Integer,Integer> |
sortHashMapByValues(Map<Integer,Integer> stuffToSort)
Sort the contents of a hash map based upon comparing the values of its keys. |
static String |
stringify(Map<Object,Object> map)
Convert a map into a string, mostly for debugging purposes. |
static long |
timeToTarget(AbstractUser thing,
long when)
TODO: document this method (brpocock, Nov 24, 2009) |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final HashMap<Class<?>,Class<?>> extensionClasses
static int MAX_SHUTDOWN_TRIES
private static Properties messages
Constructor Detail |
---|
public LibMisc()
Method Detail |
---|
public static boolean areWeThereYet(AbstractUser thing, long when)
thing
- Who are we?when
- When are we?
public static void commandJSON(String cmd, org.json.JSONObject jso, org.starhope.util.types.CanProcessCommands commandThread, AbstractUser user, Class<?> klass)
Execute a command with a certain method signature from klass, passing it the JSON parameters as well as the environment (thread, zone, and user) to run with.
The class klass is searched for a method with the name
"do_COMMAND", which must take a Zone, JSONObject, User, and
Integer (as a room number in which the user is standing) as input
parameters. If no such method is found, the extension class (if
any) defined for klass using loadExtension(Class)
will
also be searched, before reporting an error back to the command
thread.
cmd
- The command's string namejso
- JSON parameters to that commandcommandThread
- The command processor threaduser
- The user initiating the commandklass
- The command-processor class in which to search for
the commandpublic static double distance(AbstractUser from, AbstractUser to, long when)
from
- one thingto
- another thingwhen
- when is it
private static double distance(double x1, double y1, double x2, double y2)
x1
- start x abcessay1
- start y ordinatex2
- end x abcessay2
- end y ordinate
public static String formatFutureDate(Date targetDate)
targetDate
- a date in the future
public static String formatFutureDate(Date targetDate, String language, String dialect)
targetDate
- a date in the futurelanguage
- the user's languagedialect
- the user's dialect
private static String formatFutureDate_English(Date targetDate)
targetDate
- a date in the future
public static String formatMemory(long numBytes)
numBytes
- a number of bytes (size_t)
public static String genFakeIP(Object o)
o
- The object for which to generate a fake IP address
public static String getText(String string)
string
- WRITEME
public static String getText(String string, String language, String dialect)
string
- WRITEMElanguage
- WRITEMEdialect
- WRITEME
public static String getTextOrDefault(String key, String fallback)
key
- The key name which should exist in the message catalogue.fallback
- The fallback text to be used if that message does not exist.
public static boolean hasText(String string)
string
- WRITEME
public static boolean hasText(String string, String language, String dialect)
string
- WRITEMElanguage
- WRITEMEdialect
- WRITEME
public static String hexify(byte[] input)
input
- The bytes to be converted to hex
private static void initMessages()
public static String listToDisplay(Collection<? extends Object> words, String language, String dialect)
words
- WRITEMElanguage
- WRITEMEdialect
- WRITEME
public static String listToDisplay(List<String> words, String language, String dialect)
Given a list of strings, combine then into a string for display purposes.
For English, the list will obey the traditional grammatical usage of commas: List elements are joined with commas, except that the conjunction (in our case, always “and”) occurs penultimate, and two or three element lists do not use commas.
For Spanish, works essentially the same way.
For other languages, we just join the words with commas and omit the conjunction
words
- A list of words.language
- The user's display languagedialect
- The user's sublanguage dialect
public static String listToDisplay(Object[] set, String language, String dialect)
set
- WRITEMElanguage
- WRITEMEdialect
- WRITEME
private static String listToDisplay_English(List<String> words)
listToDisplay(List, String, String)
for English.
words
- word list
private static String listToDisplay_Español(List<String> words)
listToDisplay(List, String, String)
for Spanish.
words
- word list
private static String listToDisplay_فرسئ(List<String> words)
listToDisplay(List, String, String)
for Persian.
words
- word list
public static Class<?> loadExtension(Class<?> klass)
klass
- The class for which an extension might exist
public static int makeHashCode(String string)
string
- WRITEME
public static String rot13(String msg)
msg
- The string to be rot-13:ed
public static void setMaxShutdownTries(int mst)
mst
- maximum number of tries to shut down a socket input
bufferpublic static void shutdownInput(Socket socket) throws IOException
This method taken from Apache Tomcat:
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Shut down the input stream of a connection
socket
- The socket whose input stream is to be shut down
IOException
- If the input stream cannot be shut down
despite best effortspublic static LinkedHashMap<Integer,Integer> sortHashMapByValues(Map<Integer,Integer> stuffToSort)
stuffToSort
- The hash table to be sorted
public static String stringify(Map<Object,Object> map)
map
- a map object to be stringified
public static long timeToTarget(AbstractUser thing, long when)
thing
- what is movingwhen
- what time is it now
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |