Mercurial Hosting > luan
comparison src/luan/modules/Utils.java @ 1392:002152af497a
hosted postgres
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Fri, 06 Sep 2019 00:19:47 -0600 |
parents | eb8b35dccd99 |
children | 225808b90cee |
comparison
equal
deleted
inserted
replaced
1391:94f48cc76de8 | 1392:002152af497a |
---|---|
102 if( val!=null && !(val instanceof String) ) | 102 if( val!=null && !(val instanceof String) ) |
103 throw new LuanException( "parameter '"+key+"' must be a string but is a "+Luan.type(val) ); | 103 throw new LuanException( "parameter '"+key+"' must be a string but is a "+Luan.type(val) ); |
104 return (String)val; | 104 return (String)val; |
105 } | 105 } |
106 | 106 |
107 public static String removeRequiredString(Map map,String key) throws LuanException { | |
108 String s = removeString(map,key); | |
109 if( s==null ) | |
110 throw new LuanException( "parameter '"+key+"' is required" ); | |
111 return s; | |
112 } | |
113 | |
107 public static Number removeNumber(Map map,String key) throws LuanException { | 114 public static Number removeNumber(Map map,String key) throws LuanException { |
108 Object val = map.remove(key); | 115 Object val = map.remove(key); |
109 if( val!=null && !(val instanceof Number) ) | 116 if( val!=null && !(val instanceof Number) ) |
110 throw new LuanException( "parameter '"+key+"' must be a string but is a "+Luan.type(val) ); | 117 throw new LuanException( "parameter '"+key+"' must be a string but is a "+Luan.type(val) ); |
111 return (Number)val; | 118 return (Number)val; |
112 } | 119 } |
113 | 120 |
114 public static Integer removeInt(Map map,String key) throws LuanException { | 121 public static Integer removeInteger(Map map,String key) throws LuanException { |
115 Object val = map.remove(key); | 122 Object val = map.remove(key); |
116 if( val==null ) | 123 if( val==null ) |
117 return null; | 124 return null; |
118 Integer i = Luan.asInteger(val); | 125 Integer i = Luan.asInteger(val); |
119 if( i==null ) { | 126 if( i==null ) { |
135 if( val!=null && !(val instanceof Boolean) ) | 142 if( val!=null && !(val instanceof Boolean) ) |
136 throw new LuanException( "parameter '"+key+"' must be a string but is a "+Luan.type(val) ); | 143 throw new LuanException( "parameter '"+key+"' must be a string but is a "+Luan.type(val) ); |
137 return (Boolean)val; | 144 return (Boolean)val; |
138 } | 145 } |
139 | 146 |
147 public static LuanFunction removeFunction(Map map,String key) throws LuanException { | |
148 Object val = map.remove(key); | |
149 if( val!=null && !(val instanceof LuanFunction) ) | |
150 throw new LuanException( "parameter '"+key+"' must be a function but is a "+Luan.type(val) ); | |
151 return (LuanFunction)val; | |
152 } | |
153 | |
154 public static LuanFunction removeRequiredFunction(Map map,String key) throws LuanException { | |
155 LuanFunction fn = removeFunction(map,key); | |
156 if( fn==null ) | |
157 throw new LuanException( "parameter '"+key+"' is required" ); | |
158 return fn; | |
159 } | |
160 | |
140 public static void checkEmpty(Map map) throws LuanException { | 161 public static void checkEmpty(Map map) throws LuanException { |
141 if( !map.isEmpty() ) | 162 if( !map.isEmpty() ) |
142 throw new LuanException( "unrecognized options: "+map ); | 163 throw new LuanException( "unrecognized options: "+map ); |
143 } | 164 } |
144 | 165 |