Correct code format for file DescParseTickFormat

This commit is contained in:
snowleo 2011-08-08 17:46:12 +02:00
parent b07ba21659
commit f75390bd3f

View file

@ -6,6 +6,7 @@ import java.util.*;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
/** /**
* This utility class is used for converting between the ingame * This utility class is used for converting between the ingame
* time in ticks to ingame time as a friendly string. * time in ticks to ingame time as a friendly string.
@ -15,25 +16,23 @@ import java.util.logging.Logger;
* *
* @author Olof Larsson * @author Olof Larsson
*/ */
public class DescParseTickFormat { public class DescParseTickFormat
{
// ============================================ // ============================================
// First some information vars. TODO: Should this be in a config file? // First some information vars. TODO: Should this be in a config file?
// -------------------------------------------- // --------------------------------------------
public static final Map<String, Integer> nameToTicks = new LinkedHashMap<String, Integer>(); public static final Map<String, Integer> nameToTicks = new LinkedHashMap<String, Integer>();
public static final Set<String> resetAliases = new HashSet<String>(); public static final Set<String> resetAliases = new HashSet<String>();
public static final int ticksAtMidnight = 18000; public static final int ticksAtMidnight = 18000;
public static final int ticksPerDay = 24000; public static final int ticksPerDay = 24000;
public static final int ticksPerHour = 1000; public static final int ticksPerHour = 1000;
public static final double ticksPerMinute = 1000d / 60d; public static final double ticksPerMinute = 1000d / 60d;
public static final double ticksPerSecond = 1000d / 60d / 60d; public static final double ticksPerSecond = 1000d / 60d / 60d;
private static final SimpleDateFormat SDFTwentyFour = new SimpleDateFormat("HH:mm", Locale.ENGLISH); private static final SimpleDateFormat SDFTwentyFour = new SimpleDateFormat("HH:mm", Locale.ENGLISH);
private static final SimpleDateFormat SDFTwelve = new SimpleDateFormat("h:mmaa", Locale.ENGLISH); private static final SimpleDateFormat SDFTwelve = new SimpleDateFormat("h:mmaa", Locale.ENGLISH);
static { static
{
nameToTicks.put("sunrise", 22000); nameToTicks.put("sunrise", 22000);
nameToTicks.put("rise", 22000); nameToTicks.put("rise", 22000);
@ -68,7 +67,6 @@ public class DescParseTickFormat {
// ============================================ // ============================================
// PARSE. From describing String to int // PARSE. From describing String to int
// -------------------------------------------- // --------------------------------------------
public static long parse(String desc) throws NumberFormatException public static long parse(String desc) throws NumberFormatException
{ {
Long ret; Long ret;
@ -77,16 +75,40 @@ public class DescParseTickFormat {
desc = desc.toLowerCase().replaceAll("[^A-Za-z0-9]", ""); desc = desc.toLowerCase().replaceAll("[^A-Za-z0-9]", "");
// Detect ticks format // Detect ticks format
try { return parseTicks(desc); } catch (Exception e) {} try
{
return parseTicks(desc);
}
catch (Exception e)
{
}
// Detect 24-hour format // Detect 24-hour format
try { return parse24(desc); } catch (Exception e) {} try
{
return parse24(desc);
}
catch (Exception e)
{
}
// Detect 12-hour format // Detect 12-hour format
try { return parse12(desc); } catch (Exception e) {} try
{
return parse12(desc);
}
catch (Exception e)
{
}
// Detect aliases // Detect aliases
try { return parseAlias(desc); } catch (Exception e) {} try
{
return parseAlias(desc);
}
catch (Exception e)
{
}
// Well we failed to understand... // Well we failed to understand...
throw new NumberFormatException(); throw new NumberFormatException();
@ -201,7 +223,6 @@ public class DescParseTickFormat {
// ============================================ // ============================================
// FORMAT. From int to describing String // FORMAT. From int to describing String
// -------------------------------------------- // --------------------------------------------
public static String format(long ticks) public static String format(long ticks)
{ {
StringBuilder msg = new StringBuilder(); StringBuilder msg = new StringBuilder();