1 8 9 package com.sleepycat.je.utilint; 10 11 import java.util.Enumeration ; 12 import java.util.Properties ; 13 import java.util.Set ; 14 15 import com.sleepycat.je.DatabaseException; 16 17 20 public class PropUtil { 21 22 25 public static boolean getBoolean(Properties props, String propName) { 26 String value = props.getProperty(propName); 27 if ((value != null) && (value.equalsIgnoreCase("true"))) { 28 return true; 29 } else { 30 return false; 31 } 32 } 33 34 41 public static Properties validateProps(Properties props, 42 Set allowedProps, 43 String apiMethod) 44 throws DatabaseException { 45 46 if (props == null) { 47 return new Properties (); 48 } else { 49 if (props.size() > 0) { 50 Enumeration e = props.propertyNames(); 51 while (e.hasMoreElements()) { 52 String propName = (String ) e.nextElement(); 53 validateProp(propName, allowedProps, apiMethod); 54 } 55 } 56 return props; 57 } 58 } 59 60 63 public static void validateProp(String propName, 64 Set allowedProps, 65 String apiMethod) 66 throws DatabaseException { 67 68 if (!allowedProps.contains(propName)) { 69 throw new DatabaseException 70 (propName + " is not a valid property for " + apiMethod); 71 } 72 } 73 74 79 public static long microsToMillis(long micros) { 80 return (micros + 999) / 1000; 81 } 82 } 83 84 | Popular Tags |