@Benchmark public Map<String, String> scalaAnyRef() { int localSize = this.size; String[] localElements = this.elements; Map<String, String> scalaAnyRefMap = this.isPresized ? new AnyRefMap<>(localSize) : new AnyRefMap<>(); for (int i = 0; i < localSize; i++) { scalaAnyRefMap.put(localElements[i], "dummy"); } return scalaAnyRefMap; } }
static String reverseString(String input) { return new StringBuilder(input).reverse().toString(); }
private static Seq<String> gaugeName(String name) { return scala.collection.JavaConversions.asScalaBuffer(Arrays.asList(name)).toList(); }
@SuppressWarnings("unchecked") @Override public Object deserialize(JsonNode n, ObjectMapper mapper) { org.apache.commons.lang3.tuple.Pair<String, Object> deserializeObject = TableDisplayDeSerializer.getDeserializeObject(parent, n, mapper); String subtype = deserializeObject.getLeft(); if (subtype != null && subtype.equals(TableDisplay.DICTIONARY_SUBTYPE)) { return JavaConverters.mapAsScalaMapConverter((Map<String, Object>) deserializeObject.getRight()).asScala().toMap(Predef.<Tuple2<String, Object>>conforms()); } else if (subtype != null && subtype.equals(TableDisplay.LIST_OF_MAPS_SUBTYPE)) { List<Map<String, Object>> rows = (List<Map<String, Object>>) deserializeObject.getRight(); List<Object> oo = new ArrayList<Object>(); for (Map<String, Object> row : rows) { oo.add(JavaConverters.mapAsScalaMapConverter(row).asScala().toMap(Predef.<Tuple2<String, Object>>conforms())); } return scala.collection.JavaConversions.collectionAsScalaIterable(oo); } else if (subtype != null && subtype.equals(TableDisplay.MATRIX_SUBTYPE)) { List<List<?>> matrix = (List<List<?>>) deserializeObject.getRight(); ArrayList<Object> ll = new ArrayList<Object>(); for (List<?> ob : matrix) { ll.add(scala.collection.JavaConversions.asScalaBuffer(ob).toList()); } return scala.collection.JavaConversions.asScalaBuffer(ll).toList(); } return deserializeObject.getRight(); }
private long flushMessages(List<Message> messages, long payloadSize) { if (messages.isEmpty()) { LOG.debug("No messages to flush, not trying to write an empty message set."); return -1L; } final ByteBufferMessageSet messageSet = new ByteBufferMessageSet(JavaConversions.asScalaBuffer(messages).toSeq()); if (LOG.isDebugEnabled()) { LOG.debug("Trying to write ByteBufferMessageSet with size of {} bytes to journal", messageSet.sizeInBytes()); } final LogAppendInfo appendInfo = kafkaLog.append(messageSet, true); long lastWriteOffset = appendInfo.lastOffset(); if (LOG.isDebugEnabled()) { LOG.debug("Wrote {} messages to journal: {} bytes (payload {} bytes), log position {} to {}", messages.size(), messageSet.sizeInBytes(), payloadSize, appendInfo.firstOffset(), lastWriteOffset); } writtenMessages.mark(messages.size()); return lastWriteOffset; }
public RRMultiWriter(String[] streams, DistributedLogClient client) { this.streams = streams; this.client = client; scala.collection.immutable.Set<ServiceFactory<VALUE, DLSN>> scalaSet = JavaConversions.asScalaSet(initializeServices(streams, client)).toSet(); this.service = Balancers.heap(new scala.util.Random(System.currentTimeMillis())) .newBalancer( Activity.value(scalaSet), NullStatsReceiver.get(), new NoBrokersAvailableException("No partitions available") ).toService(); }
@Benchmark public void get() { int localSize = this.size; String[] localElements = this.elements; Map<String, String> localScalaMap = this.scalaMap; for (int i = 0; i < localSize; i++) { if (!localScalaMap.get(localElements[i]).isDefined()) { throw new AssertionError(i); } } } }
@Benchmark public scala.collection.mutable.HashMap<String, String> mutableScalaPut() { int localSize = this.size; String[] localElements = this.elements; scala.collection.mutable.HashMap<String, String> map = new PresizableHashMap<>(localSize); for (int i = 0; i < localSize; i++) { map.put(localElements[i], "dummy"); } return map; }
@Override public Object deserialize(JsonNode n, ObjectMapper mapper) { HashMap<String, Object> o = new HashMap<String, Object>(); try { logger.debug("using custom map deserializer"); Iterator<Map.Entry<String, JsonNode>> e = n.fields(); while (e.hasNext()) { Map.Entry<String, JsonNode> ee = e.next(); o.put(ee.getKey(), parent.deserialize(ee.getValue(), mapper)); } } catch (Exception e) { logger.error("exception deserializing Map {}", e.getMessage()); o = null; } if (o != null) return JavaConverters.mapAsScalaMapConverter(o).asScala().toMap(Predef.<Tuple2<String, Object>>conforms()); return null; }
private JPanel createArtifactRow(final String ext, final String serv, final String mainClass, final String args) { final JLabel extLabel = new JLabel(EXT_LABEL); final JTextField extField = new JTextField(); extField.setToolTipText(EXT_TOOLTIP); extField.setText(ext); final JLabel packgeLabel = new JLabel("Artifact"); final JTextField packgeField = new JTextField(); packgeField.setToolTipText("e.g. ch.epfl.lamp:dotty-language-server_0.3:0.3.0-RC2"); packgeField.setText(serv); final JLabel mainClassLabel = new JLabel("Main class"); final JTextField mainClassField = new JTextField(); mainClassField.setToolTipText("e.g. dotty.tools.languageserver.Main"); mainClassField.setText(mainClass); final JLabel argsLabel = new JLabel("Args"); final JTextField argsField = new JTextField(); argsField.setToolTipText("e.g. -stdio"); argsField.setText(args); final List<JComponent> components = Arrays.asList(extLabel, extField, packgeLabel, packgeField, mainClassLabel, mainClassField, argsLabel, argsField); final JPanel panel = createRow(components, ArtifactLanguageServerDefinition$.MODULE$.getPresentableTyp()); final scala.collection.mutable.LinkedHashMap<String, JComponent> map = new scala.collection.mutable.LinkedHashMap<>(); map.put(EXT, extField); map.put(PACKGE, packgeField); map.put(MAINCLASS, mainClassField); map.put(ARGS, argsField); rows.add(new ServersGUIRow(panel, ArtifactLanguageServerDefinition$.MODULE$.typ(), map)); return panel; }
@Setup public void setUp() { Random random = new Random(123456789012345L); this.elements = new String[this.size]; this.scalaMap = new PresizableHashMap<>(this.size); for (int i = 0; i < this.size; i++) { String element = RandomStringUtils.random(RANDOM_COUNT, 0, 0, false, true, null, random); this.elements[i] = element; this.scalaMap.put(element, "dummy"); } }
private static void triggerPreferredLeaderElection(KafkaZkClient zkClient, List<PartitionInfo> partitionInfoList) { scala.collection.mutable.HashSet<TopicPartition> scalaPartitionInfoSet = new scala.collection.mutable.HashSet<>(); for (PartitionInfo javaPartitionInfo : partitionInfoList) { scalaPartitionInfoSet.add(new TopicPartition(javaPartitionInfo.topic(), javaPartitionInfo.partition())); } PreferredReplicaLeaderElectionCommand.writePreferredReplicaElectionData(zkClient, scalaPartitionInfoSet); }
/** * Read number of partitions for the given topic on the specified zookeeper * @param zkUrl zookeeper connection url * @param topic topic name * * @return the number of partitions of the given topic */ public static int getPartitionNumForTopic(String zkUrl, String topic) { ZkUtils zkUtils = ZkUtils.apply(zkUrl, ZK_SESSION_TIMEOUT_MS, ZK_CONNECTION_TIMEOUT_MS, JaasUtils.isZkSecurityEnabled()); try { Seq<String> topics = scala.collection.JavaConversions.asScalaBuffer(Arrays.asList(topic)); return zkUtils.getPartitionsForTopics(topics).apply(topic).size(); } catch (NoSuchElementException e) { return 0; } finally { zkUtils.close(); } }
public static SparkConf getSparkConfBasedOn(SparkSession.Builder sparkSessionBuilder) { try { SparkConf sparkConf = new SparkConf(); Field options = sparkSessionBuilder.getClass().getDeclaredField("org$apache$spark$sql$SparkSession$Builder$$options"); options.setAccessible(true); Iterator iterator = ((scala.collection.mutable.HashMap) options.get(sparkSessionBuilder)).iterator(); while (iterator.hasNext()) { Tuple2 x = (Tuple2) iterator.next(); sparkConf.set((String) (x)._1, (String) (x)._2); } return sparkConf; } catch (Exception e) { throw new RuntimeException(e); } }
@Override public Object deserialize(JsonNode n, ObjectMapper mapper) { List<Object> o = new ArrayList<Object>(); try { logger.debug("using custom array deserializer"); for (int i = 0; i < n.size(); i++) { o.add(parent.deserialize(n.get(i), mapper)); } } catch (Exception e) { logger.error("exception deserializing Collection {}", e.getMessage()); o = null; } if (o != null) return scala.collection.JavaConversions.asScalaBuffer(o).toList(); return null; } }
@Test public void testExpressionWithColumn() throws Exception { Method method = MyFunc.class.getDeclaredMethod("reverseString", String.class); FunctionRegistry.registerStaticFunction(method); FunctionInfo functionInfo = FunctionRegistry.resolve("reverseString", new Class<?>[]{Object.class}); System.out.println(functionInfo); String expression = "reverseString(testColumn)"; FunctionExpressionEvaluator evaluator = new FunctionExpressionEvaluator(expression); GenericRow row = new GenericRow(); for (int i = 0; i < 5; i++) { String value = "testValue" + i; row.putField("testColumn", value); Object result = evaluator.evaluate(row); Assert.assertEquals(result, new StringBuilder(value).reverse().toString()); } }
@Benchmark public void get() { int localSize = this.size; String[] localElements = this.elements; Map<String, String> localScalaAnyRefMap = this.scalaAnyRefMap; for (int i = 0; i < localSize; i++) { if (!localScalaAnyRefMap.get(localElements[i]).isDefined()) { throw new AssertionError(i); } } } }
@Setup public void setUp() { Random random = new Random(123456789012345L); this.elements = new String[this.size]; this.scalaAnyRefMap = new AnyRefMap<>(this.size); for (int i = 0; i < this.size; i++) { String element = RandomStringUtils.random(RANDOM_COUNT, 0, 0, false, true, null, random); this.elements[i] = element; this.scalaAnyRefMap.put(element, "dummy"); } }
@Benchmark public scala.collection.mutable.HashMap<String, String> scala() { int localSize = this.size; if (Float.compare(this.loadFactor, 0.75f) != 0) { throw new IllegalArgumentException(); } String[] localElements = this.elements; /** * @see HashTable#initialSize() */ int defaultInitialSize = 16; scala.collection.mutable.HashMap<String, String> scala = this.isPresized ? new PresizableHashMap<>(localSize) : new PresizableHashMap<>(defaultInitialSize); for (int i = 0; i < localSize; i++) { scala.put(localElements[i], "dummy"); } return scala; } }
private JPanel createCommandRow(final String ext, final String command) { final JLabel extLabel = new JLabel(EXT_LABEL); final JTextField extField = new JTextField(); extField.setToolTipText(EXT_TOOLTIP); extField.setText(ext); final JLabel commandLabel = new JLabel("Command"); final TextFieldWithBrowseButton commandField = new TextFieldWithBrowseButton(); commandField.setText(command); commandField.setToolTipText("e.g. python.exe -m C:\\python-ls\\pyls"); commandField.addBrowseFolderListener(new TextBrowseFolderListener(new FileChooserDescriptor(true, false, true, true, true, false).withShowHiddenFiles(true))); final List<JComponent> components = Arrays.asList(extLabel, extField, commandLabel, commandField); final JPanel panel = createRow(components, RawCommandServerDefinition$.MODULE$.getPresentableTyp()); final scala.collection.mutable.LinkedHashMap<String, JComponent> map = new scala.collection.mutable.LinkedHashMap<>(); map.put(EXT, extField); map.put(COMMAND, commandField); rows.add(new ServersGUIRow(panel, RawCommandServerDefinition$.MODULE$.typ(), map)); return panel; }