Mercurial Hosting > luan
diff 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 |
line wrap: on
line diff
--- a/src/luan/modules/Utils.java Thu Sep 05 01:29:57 2019 -0600 +++ b/src/luan/modules/Utils.java Fri Sep 06 00:19:47 2019 -0600 @@ -104,6 +104,13 @@ return (String)val; } + public static String removeRequiredString(Map map,String key) throws LuanException { + String s = removeString(map,key); + if( s==null ) + throw new LuanException( "parameter '"+key+"' is required" ); + return s; + } + public static Number removeNumber(Map map,String key) throws LuanException { Object val = map.remove(key); if( val!=null && !(val instanceof Number) ) @@ -111,7 +118,7 @@ return (Number)val; } - public static Integer removeInt(Map map,String key) throws LuanException { + public static Integer removeInteger(Map map,String key) throws LuanException { Object val = map.remove(key); if( val==null ) return null; @@ -137,6 +144,20 @@ return (Boolean)val; } + public static LuanFunction removeFunction(Map map,String key) throws LuanException { + Object val = map.remove(key); + if( val!=null && !(val instanceof LuanFunction) ) + throw new LuanException( "parameter '"+key+"' must be a function but is a "+Luan.type(val) ); + return (LuanFunction)val; + } + + public static LuanFunction removeRequiredFunction(Map map,String key) throws LuanException { + LuanFunction fn = removeFunction(map,key); + if( fn==null ) + throw new LuanException( "parameter '"+key+"' is required" ); + return fn; + } + public static void checkEmpty(Map map) throws LuanException { if( !map.isEmpty() ) throw new LuanException( "unrecognized options: "+map );