case JRuby: RubyHash oRuby = (RubyHash) engine.eval(defines + "\n" + script, context); Iterator itruby = oRuby.entrySet().iterator(); while (itruby.hasNext()) { Map.Entry pairs = (Map.Entry) itruby.next();
private Map<String, Object> createJavaMap() { Map<String, Object> copy = new HashMap<String, Object>(); Set<Entry<Object, Object>> rubyEntrySet = rubyHash.entrySet(); for (Entry<Object, Object> o: rubyEntrySet) { String key; Object rubyKey = o.getKey(); Object rubyValue = o.getValue(); if (rubyKey instanceof RubyString) { key = ((RubyString) rubyKey).asJavaString(); } else if (rubyKey instanceof String) { key = (String) rubyKey; } else if (rubyKey instanceof Number) { key = String.valueOf(rubyKey); } else { continue; } Object value = convertRubyValue(rubyValue); copy.put(key, value); } return copy; }
/** * A type specific conversion routine. * * @param rbObject object to convert * @return analogous Pig type */ @SuppressWarnings("unchecked") public static Map<String, ?> rubyToPig(RubyHash rbObject) throws ExecException { Map<String, Object> newMap = Maps.newHashMap(); for (Map.Entry<Object, Object> entry : (Set<Map.Entry<Object, Object>>)rbObject.entrySet()) { Object key = entry.getKey(); if (!(key instanceof String || key instanceof RubyString || key instanceof RubySymbol)) throw new ExecException("Hash must have String or Symbol key. Was given: " + key.getClass().getName()); String keyStr = key.toString(); if (entry.getValue() instanceof IRubyObject) { newMap.put(keyStr, rubyToPig((IRubyObject)entry.getValue())); } else { newMap.put(keyStr, entry.getValue()); } } return newMap; }
private Map<String, Object> createJavaMap() { Map<String, Object> copy = new HashMap<String, Object>(); Set<Entry<Object, Object>> rubyEntrySet = rubyHash.entrySet(); for (Entry<Object, Object> o: rubyEntrySet) { String key; Object rubyKey = o.getKey(); Object rubyValue = o.getValue(); if (rubyKey instanceof RubyString) { key = ((RubyString) rubyKey).asJavaString(); } else if (rubyKey instanceof String) { key = (String) rubyKey; } else if (rubyKey instanceof Number) { key = String.valueOf(rubyKey); } else { continue; } Object value = convertRubyValue(rubyValue); copy.put(key, value); } return copy; }
private Map<String, Object> createJavaMap() { Map<String, Object> copy = new HashMap<String, Object>(); Set<Entry<Object, Object>> rubyEntrySet = rubyHash.entrySet(); for (Map.Entry<Object, Object> o: rubyEntrySet) { String key = null; Object value; Object rubyKey = o.getKey(); Object rubyValue = o.getValue(); if (rubyKey instanceof RubySymbol) { key = ((RubySymbol) rubyKey).asJavaString(); } else if (rubyKey instanceof RubyString) { key = ((RubyString) rubyKey).asJavaString(); } else if (rubyKey instanceof String) { key = (String) rubyKey; } else if (rubyKey instanceof Long) { // Skip it silently, it is a positional attribute } else { throw new IllegalStateException("Did not expect key " + rubyKey + " of type " + rubyKey.getClass()); } if (key != null) { value = convertRubyValue(rubyValue); copy.put(key, value); } } return copy; }
private Map<String, Object> createJavaMap() { Map<String, Object> copy = new HashMap<String, Object>(); Set<Entry<Object, Object>> rubyEntrySet = rubyHash.entrySet(); for (Map.Entry<Object, Object> o: rubyEntrySet) { String key = null; Object value; Object rubyKey = o.getKey(); Object rubyValue = o.getValue(); if (rubyKey instanceof RubySymbol) { key = ((RubySymbol) rubyKey).asJavaString(); } else if (rubyKey instanceof RubyString) { key = ((RubyString) rubyKey).asJavaString(); } else if (rubyKey instanceof String) { key = (String) rubyKey; } else if (rubyKey instanceof Long) { // Skip it silently, it is a positional attribute } else { throw new IllegalStateException("Did not expect key " + rubyKey + " of type " + rubyKey.getClass()); } if (key != null) { value = convertRubyValue(rubyValue); copy.put(key, value); } } return copy; }
for (Map.Entry<String, String> e : (Set<Map.Entry<String, String>>)hash.entrySet()) {
for (Map.Entry<String, String> e : (Set<Map.Entry<String, String>>)hash.entrySet()) {