@Override public boolean writeObject(Object obj, JsonGenerator jgen, boolean expand) throws JsonProcessingException, IOException { logger.debug("list of maps"); // convert this 'on the fly' to a datatable Collection<?> col = scala.collection.JavaConversions.asJavaCollection((Iterable<?>) obj); List<Map<String, Object>> tab = new ArrayList<Map<String, Object>>(); for (Object o : col) { Map<String, Object> row = scala.collection.JavaConversions.mapAsJavaMap((scala.collection.Map<String, Object>) o); tab.add(row); } TableDisplay t = new TableDisplay(tab, parent); jgen.writeObject(t); return true; } }
@Override public boolean writeObject(Object obj, JsonGenerator jgen, boolean expand) throws JsonProcessingException, IOException { logger.debug("primitive type map"); List<String> columns = new ArrayList<String>(); columns.add("Key"); columns.add("Value"); List<List<?>> values = new ArrayList<List<?>>(); Map<?, ?> m = scala.collection.JavaConversions.mapAsJavaMap((scala.collection.Map<?, ?>) obj); Set<?> keys = m.keySet(); for (Object key : keys) { Object val = m.get(key); List<Object> l = new ArrayList<Object>(); l.add(key.toString()); l.add(val); values.add(l); } jgen.writeStartObject(); jgen.writeObjectField("type", "TableDisplay"); jgen.writeObjectField("columnNames", columns); jgen.writeObjectField("values", values); jgen.writeObjectField("subtype", TableDisplay.DICTIONARY_SUBTYPE); jgen.writeEndObject(); return true; } }
@Override public boolean canBeUsed(Object obj, boolean expand) { if (!expand) return false; if (!(obj instanceof scala.collection.immutable.Map)) return false; Map<?, ?> m = scala.collection.JavaConversions.mapAsJavaMap((scala.collection.Map<?, ?>) obj); Set<?> keys = m.keySet(); for (Object key : keys) { if (key != null && !parent.isPrimitiveType(key.getClass().getName())) return false; Object val = m.get(key); if (val != null && !parent.isPrimitiveType(val.getClass().getName())) return false; } return true; }
@Override public boolean writeObject(Object obj, JsonGenerator jgen, boolean expand) throws JsonProcessingException, IOException { logger.debug("generic map"); // convert this 'on the fly' to a map of objects Map<?, ?> m = scala.collection.JavaConversions.mapAsJavaMap((scala.collection.Map<?, ?>) obj); Set<?> keys = m.keySet(); for (Object key : keys) { if (key == null || !(key instanceof String)) { jgen.writeObject(obj.toString()); return true; } } jgen.writeStartObject(); for (Object key : keys) { Object val = m.get(key); jgen.writeFieldName(key.toString()); if (!parent.writeObject(val, jgen, false)) jgen.writeObject(val != null ? (val.toString()) : "null"); } jgen.writeEndObject(); return true; } }
@Override public boolean canBeUsed(Object obj, boolean expand) { if (!expand) return false; if (!(obj instanceof scala.collection.immutable.Seq<?>)) return false; Collection<?> col = scala.collection.JavaConversions.asJavaCollection((Iterable<?>) obj); if (col.isEmpty()) return false; for (Object o : col) { if (!(o instanceof scala.collection.Map<?, ?>)) return false; Map<?, ?> m = scala.collection.JavaConversions.mapAsJavaMap((scala.collection.Map<?, ?>) o); Set<?> keys = m.keySet(); for (Object key : keys) { if (key != null && !parent.isPrimitiveType(key.getClass().getName())) return false; Object val = m.get(key); if (val != null && !parent.isPrimitiveType(val.getClass().getName())) return false; } } return true; }
/** * A Java transliteration of what the scala implementation does, which unfortunately is declared as private */ protected void flushDirtyLogs() { LOG.debug("Checking for dirty logs to flush..."); final Set<Map.Entry<TopicAndPartition, Log>> entries = JavaConversions.mapAsJavaMap(logManager.logsByTopicPartition()).entrySet(); for (final Map.Entry<TopicAndPartition, Log> topicAndPartitionLogEntry : entries) { final TopicAndPartition topicAndPartition = topicAndPartitionLogEntry.getKey(); final Log kafkaLog = topicAndPartitionLogEntry.getValue(); final long timeSinceLastFlush = JODA_TIME.milliseconds() - kafkaLog.lastFlushTime(); try { LOG.debug( "Checking if flush is needed on {} flush interval {} last flushed {} time since last flush: {}", topicAndPartition.topic(), kafkaLog.config().flushInterval(), kafkaLog.lastFlushTime(), timeSinceLastFlush); if (timeSinceLastFlush >= kafkaLog.config().flushMs()) { kafkaLog.flush(); } } catch (Exception e) { LOG.error("Error flushing topic " + topicAndPartition.topic(), e); } } }
/** * Creates a new HTTP context. * * @param request the HTTP request */ public Context(Request request) { this.request = request; this.header = request._underlyingHeader(); this.id = header.id(); this.response = new Response(); this.session = new Session(JavaConversions.mapAsJavaMap(header.session().data())); this.flash = new Flash(JavaConversions.mapAsJavaMap(header.flash().data())); this.args = new HashMap<String,Object>(); this.args.putAll(JavaConversions.mapAsJavaMap(header.tags())); }
/** * @return the sessions in the request */ public Map<String,String> session() { play.api.mvc.Cookies scalaCookies = scalaCookies(); scala.Option<play.api.mvc.Cookie> cookie = scalaCookies.get(play.api.mvc.Session$.MODULE$.COOKIE_NAME()); scala.collection.Map<String,String> data = play.api.mvc.Session$.MODULE$.decodeCookieToMap(cookie); return JavaConversions.mapAsJavaMap(data); }
/** * @return the cookies in a Java map */ public Map<String,String> flash() { play.api.mvc.Cookies scalaCookies = scalaCookies(); scala.Option<play.api.mvc.Cookie> cookie = scalaCookies.get(play.api.mvc.Flash$.MODULE$.COOKIE_NAME()); scala.collection.Map<String,String> data = play.api.mvc.Flash$.MODULE$.decodeCookieToMap(cookie); return JavaConversions.mapAsJavaMap(data); }
/** Called by the default implementation of {@link #writeMap} to enumerate * map elements. The default implementation is for {@link Map}.*/ @SuppressWarnings("unchecked") protected Iterable<Map.Entry<Object,Object>> getMapEntries(Object map) { if (map instanceof scala.collection.Map) { return JavaConversions.mapAsJavaMap((scala.collection.Map) map).entrySet(); } return super.getMapEntries(map); } }
public static Map<String, String> urlDecode(String body,String encode) throws IOException{ Map<String, String> postData = Maps.newHashMap(); scala.collection.immutable.Map<String, Seq<String>> formData = FormUrlEncodedParser.parse(body,encode); Map<String, Seq<String>> map = JavaConversions.mapAsJavaMap(formData); for(Map.Entry<String, Seq<String>> entry : map.entrySet()){ postData.put(entry.getKey(), entry.getValue().apply(0)); } return postData; } }
JavaConversions.mapAsJavaMap(topicMap); for (Map.Entry<String, scala.collection.Map<Object, scala.collection.Seq<Object>>> topicMapEntry : convertedTopicMap.entrySet()) { String topic = topicMapEntry.getKey(); Map<Object, scala.collection.Seq<Object>> convertedPartitionMap = JavaConversions.mapAsJavaMap(topicMapEntry.getValue()); Map<Integer, List<Integer>> resultPartitionMap = Maps.newHashMap(); for (Map.Entry<Object, scala.collection.Seq<Object>> partitionMapEntry :
@Override public UserInfo apply(play.api.libs.openid.UserInfo scalaUserInfo) { return new UserInfo(scalaUserInfo.id(), JavaConversions.mapAsJavaMap(scalaUserInfo.attributes())); } },Invoker.executionContext());
@Override public UserInfo apply(play.api.libs.openid.UserInfo scalaUserInfo) { return new UserInfo(scalaUserInfo.id(), JavaConversions.mapAsJavaMap(scalaUserInfo.attributes())); } }, Execution.internalContext());
objectsList.add(((WrappedArray) nestedRow).array()); } else if (nestedRow instanceof scala.collection.Map) { objectsList.add(scala.collection.JavaConversions.mapAsJavaMap((scala.collection.Map) nestedRow)); } else if (nestedRow instanceof Object[]) { objectsList.add(nestedRow);
private Sort nthArgSort(KLabel klabel, int n) { java.util.Set<Tuple2<Seq<Sort>,Sort>> sigs = mutable(JavaConversions.mapAsJavaMap(module.signatureFor()).get(klabel)); if (sigs == null) { throw new IllegalArgumentException("Not found signature for label: " + klabel); } Sort sort = null; for (Tuple2<Seq<Sort>,Sort> sig : sigs) { List<Sort> sorts = JavaConversions.seqAsJavaList(sig._1()); if (n >= sorts.size()) continue; sort = sorts.get(n); if (!sort.equals(Sorts.K())) { return sort; } } return sort; } }
JavaConversions.mapAsJavaMap(moduleWithPolyProds.signatureFor()).entrySet().stream().forEach(e -> { JavaConversions.setAsJavaSet(e.getValue()).stream().forEach(p -> { ImmutableList.Builder<Sort> sortsBuilder = ImmutableList.builder(); JavaConversions.mapAsJavaMap(module.attributesFor()).entrySet().stream().forEach(e -> { attributesBuilder.put(e.getKey().name(), e.getValue()); });
/** * A Java transliteration of what the scala implementation does, which unfortunately is declared as private */ protected void flushDirtyLogs() { LOG.debug("Checking for dirty logs to flush..."); final Set<Map.Entry<TopicAndPartition, Log>> entries = JavaConversions.mapAsJavaMap(logManager.logsByTopicPartition()).entrySet(); for (final Map.Entry<TopicAndPartition, Log> topicAndPartitionLogEntry : entries) { final TopicAndPartition topicAndPartition = topicAndPartitionLogEntry.getKey(); final Log kafkaLog = topicAndPartitionLogEntry.getValue(); final long timeSinceLastFlush = JODA_TIME.milliseconds() - kafkaLog.lastFlushTime(); try { LOG.debug( "Checking if flush is needed on {} flush interval {} last flushed {} time since last flush: {}", topicAndPartition.topic(), kafkaLog.config().flushInterval(), kafkaLog.lastFlushTime(), timeSinceLastFlush); if (timeSinceLastFlush >= kafkaLog.config().flushMs()) { kafkaLog.flush(); } } catch (Exception e) { LOG.error("Error flushing topic " + topicAndPartition.topic(), e); } } }
/** * A Java transliteration of what the scala implementation does, which unfortunately is declared as private */ protected void flushDirtyLogs() { LOG.debug("Checking for dirty logs to flush..."); final Set<Map.Entry<TopicAndPartition, Log>> entries = JavaConversions.mapAsJavaMap(logManager.logsByTopicPartition()).entrySet(); for (final Map.Entry<TopicAndPartition, Log> topicAndPartitionLogEntry : entries) { final TopicAndPartition topicAndPartition = topicAndPartitionLogEntry.getKey(); final Log kafkaLog = topicAndPartitionLogEntry.getValue(); final long timeSinceLastFlush = JODA_TIME.milliseconds() - kafkaLog.lastFlushTime(); try { LOG.debug( "Checking if flush is needed on {} flush interval {} last flushed {} time since last flush: {}", topicAndPartition.topic(), kafkaLog.config().flushInterval(), kafkaLog.lastFlushTime(), timeSinceLastFlush); if (timeSinceLastFlush >= kafkaLog.config().flushMs()) { kafkaLog.flush(); } } catch (Exception e) { LOG.error("Error flushing topic " + topicAndPartition.topic(), e); } } }
@Test public void testGetIntermediateStreamProperties() { Map<String, String> config = new HashMap<>(); KafkaSystemFactory factory = new KafkaSystemFactory(); Map<String, Properties> properties = JavaConversions.mapAsJavaMap( factory.getIntermediateStreamProperties(new MapConfig(config))); assertTrue(properties.isEmpty()); // no properties for stream config.put("streams.test.samza.intermediate", "true"); config.put("streams.test.compression.type", "lz4"); //some random config properties = JavaConversions.mapAsJavaMap( factory.getIntermediateStreamProperties(new MapConfig(config))); assertTrue(properties.isEmpty()); config.put(ApplicationConfig.APP_MODE, ApplicationConfig.ApplicationMode.BATCH.name()); properties = JavaConversions.mapAsJavaMap( factory.getIntermediateStreamProperties(new MapConfig(config))); assertTrue(!properties.isEmpty()); Properties prop = properties.get("test"); assertEquals(prop.getProperty("retention.ms"), String.valueOf(KafkaConfig.DEFAULT_RETENTION_MS_FOR_BATCH())); assertEquals(prop.getProperty("compression.type"), "lz4"); } }