Mercurial Hosting > luan
comparison src/luan/modules/Utils.java @ 1389:eb8b35dccd99
cleanup and stringify change
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 03 Sep 2019 22:54:31 -0600 |
parents | 836e00bf7ce2 |
children | 002152af497a |
comparison
equal
deleted
inserted
replaced
1388:2024d23ddd64 | 1389:eb8b35dccd99 |
---|---|
7 import java.io.OutputStream; | 7 import java.io.OutputStream; |
8 import java.io.File; | 8 import java.io.File; |
9 import java.io.InputStreamReader; | 9 import java.io.InputStreamReader; |
10 import java.net.URL; | 10 import java.net.URL; |
11 import java.net.MalformedURLException; | 11 import java.net.MalformedURLException; |
12 import java.util.Map; | |
13 import luan.Luan; | |
12 import luan.LuanException; | 14 import luan.LuanException; |
13 import luan.LuanTable; | 15 import luan.LuanTable; |
14 import luan.LuanFunction; | 16 import luan.LuanFunction; |
15 | 17 |
16 | 18 |
92 ByteArrayOutputStream out = new ByteArrayOutputStream(); | 94 ByteArrayOutputStream out = new ByteArrayOutputStream(); |
93 copyAll(in,out); | 95 copyAll(in,out); |
94 return out.toByteArray(); | 96 return out.toByteArray(); |
95 } | 97 } |
96 | 98 |
99 | |
100 public static String removeString(Map map,String key) throws LuanException { | |
101 Object val = map.remove(key); | |
102 if( val!=null && !(val instanceof String) ) | |
103 throw new LuanException( "parameter '"+key+"' must be a string but is a "+Luan.type(val) ); | |
104 return (String)val; | |
105 } | |
106 | |
107 public static Number removeNumber(Map map,String key) throws LuanException { | |
108 Object val = map.remove(key); | |
109 if( val!=null && !(val instanceof Number) ) | |
110 throw new LuanException( "parameter '"+key+"' must be a string but is a "+Luan.type(val) ); | |
111 return (Number)val; | |
112 } | |
113 | |
114 public static Integer removeInt(Map map,String key) throws LuanException { | |
115 Object val = map.remove(key); | |
116 if( val==null ) | |
117 return null; | |
118 Integer i = Luan.asInteger(val); | |
119 if( i==null ) { | |
120 String type = val instanceof Number ? val.getClass().getSimpleName().toLowerCase() : Luan.type(val); | |
121 throw new LuanException( "parameter '"+key+"' must be an integer but is a "+type ); | |
122 } | |
123 return i; | |
124 } | |
125 | |
126 public static LuanTable removeTable(Map map,String key) throws LuanException { | |
127 Object val = map.remove(key); | |
128 if( val!=null && !(val instanceof LuanTable) ) | |
129 throw new LuanException( "parameter '"+key+"' must be a table but is a "+Luan.type(val) ); | |
130 return (LuanTable)val; | |
131 } | |
132 | |
133 public static Boolean removeBoolean(Map map,String key) throws LuanException { | |
134 Object val = map.remove(key); | |
135 if( val!=null && !(val instanceof Boolean) ) | |
136 throw new LuanException( "parameter '"+key+"' must be a string but is a "+Luan.type(val) ); | |
137 return (Boolean)val; | |
138 } | |
139 | |
140 public static void checkEmpty(Map map) throws LuanException { | |
141 if( !map.isEmpty() ) | |
142 throw new LuanException( "unrecognized options: "+map ); | |
143 } | |
144 | |
97 } | 145 } |