1 28 29 package multiple; 30 31 import java.util.Date ; 32 import java.util.List ; 33 34 40 41 public abstract class Utils 42 { 43 public static boolean equalStrings(String a, String b) { 44 return (a == null && b == null) || a.equals(b); 45 } 46 47 public static boolean equalLists(List a, List b) { 48 return (a == null && b == null) || a.equals(b); 49 } 50 51 public static boolean equalAirports(AirportBean a, AirportBean b) { 52 return (a == null && b == null) || (a != null && a.equals(b)); 53 } 54 55 public static boolean equalCarriers(CarrierBean a, CarrierBean b) { 56 return (a == null && b == null) || (a != null && a.equals(b)); 57 } 58 59 public static boolean equalDates(Date a, Date b) { 60 return (a == null && b == null) || (a != null && a.equals(b)); 61 } 62 63 public static int timeToMinute(String time) { 64 65 int mark = time.indexOf(':'); 67 if (mark > 0) { 68 69 int hour = Integer.parseInt(time.substring(0, mark)); 71 if (hour == 12) { 72 hour = 0; 73 } 74 75 String mins = time.substring(mark+1, time.length()-1); 77 int minute = Integer.parseInt(mins); 78 79 char last = time.charAt(time.length()-1); 81 boolean pm = Character.toLowerCase(last) == 'p'; 82 83 return ((pm ? 12 : 0) + hour)*60 + minute; 85 86 } else { 87 throw new IllegalArgumentException ("Not a valid time: " + time); 88 } 89 } 90 91 public static String minuteToTime(int minute) { 92 93 int hour = minute / 60; 95 boolean pm = false; 96 if (hour >= 12) { 97 hour -= 12; 98 pm = true; 99 } 100 if (hour == 0) { 101 hour = 12; 102 } 103 104 minute %= 60; 106 String mtext = Integer.toString(minute); 107 if (mtext.length() == 1) { 108 mtext = '0' + mtext; 109 } 110 111 return Integer.toString(hour) + ':' + mtext + (pm ? 'p' : 'a'); 113 } 114 } 115 | Popular Tags |