strange.... Is there any way to explain this code then?
@Override
@SuppressWarnings("unchecked")
public final <R, A> R collect(Collector<? super P_OUT, A, R> collector) {
A container;
if (isParallel()
&& (collector.characteristics().contains(Collector.Characteristics.CONCURRENT))
&& (!isOrdered() || collector.characteristics().contains(Collector.Characteristics.UNORDERED))) {
container = collector.supplier().get();
BiConsumer<A, ? super P_OUT> accumulator = collector.accumulator();
forEach(u -> accumulator.accept(container, u));
I'm bad with using a proper debugger, but setting breakpoints could work I guess
public static void main(String[] args) {
final int sz = 1000000;
List<Integer> input = new ArrayList<>(sz);
for (int i = 0; i < sz; i++) {
input.add(i);
}
final AtomicInteger idgen = new AtomicInteger();
System.out.println("Mapping");
Map<Integer,Integer> output = input.parallelStream().collect(Collector.of(
HashMap<Integer,Integer>::new,
(acc, t) -> acc.put(acc.size(), t),
(left, right) -> {
int id = idgen.incrementAndGet();
From the JavaDoc for Collector.Characteristics.CONCURRENT:
> Indicates that this collector is concurrent, meaning that the result container can support the accumulator function being called concurrently with the same result container from multiple threads.
> the accumulator function being called concurrently with the same result container from multiple threads.
@Override
public <P_IN> R evaluateParallel(PipelineHelper<T> helper,
Spliterator<P_IN> spliterator) {
return new ReduceTask<>(this, helper, spliterator).invoke().get();
}
And then suddenly... magic happens.
This declaration...
private static final class ReduceTask<P_IN, P_OUT, R,
S extends AccumulatingSink<P_OUT, R, S>>
extends AbstractTask<P_IN, P_OUT, S, ReduceTask<P_IN, P_OUT, R, S>> {
Netbeans should support matching the < and > type parameters
We should make a Coding Challenge to implement the Java 8 Streams API... ...
Or a coding challenge to implement export into g++. It should take some years and a full team of engineers. And also probably rewriting g++ from scratch.
@skiwi I thought the general idea was supposed to be to increase participation with challenges that were interesting and fun, not to kill the site outright. :-)
For starters, indent your code consistently — the standard in Ruby is two spaces. That includes indenting the contents of your begin-rescue-end blocks.
Normally, I don't like to make such a huge fuss about indentation, but in this case I think it's highly important, because:
Your program has ...
He got rid of some stuff, and I can't figure out why.
I'm trying to implement a magic 8 ball game which produces random answers without any GUI. Since I'm a newbie to VB.NET, I might have not written the program up to the coding standards.
Module Module1
Private recognizer As SpeechRecognizer
Sub Main()
While (True)
re...
Block syntax
This:
loop
{
...
}
Causes a syntax error in MRI 2.1. This would get fix the syntax error:
loop {
...
}
However, the use of {...} is normally reserved for single-line blocks. Prefer:
loop do
..
end
Methods
Use many more methods. It should be possible to figure out ...
I just wrote this gem order_query to find next / previous records relative to the record assuming a (possibly complex) ORDER BY over the records.
Readme: Usage (excerpt)
class Issue < ActiveRecord::Base
include OrderQuery
order_query :order_display, [
[:priority, %w(high medium low)]...
I've written some python code to solve the map coloring problem. In my code, I represent the problem using Territory and MapColor objects:
class Territory:
def __init__(self, name, neighbors, color = None):
self.name = name
self.neighbors = neighbors
self.color...
RebolBot is a chat bot with a natural English dialect interface, specifically targeting the StackOverflow chat rooms. Yet it has a modular design, can post tweets to Twitter, and could be modified with only a little effort to work with other chat systems. An instance of the bot hangs out...
When I teach introductory computer science courses, I like to lighten the mood with some humor. Having a sense of fun about the material makes it less frustrating and more memorable, and it's even motivating if the joke requires some technical understanding to 'get it'!
I'll start off with a cou...
$ ruby bot.rb
logged in with SE openid
logged in to root
logged in to chat
found fkey
Bot initialized.
9997/10000 quota remaining
Answer posted.
9537/10000 quota remaining
9996/10000 quota remaining
9536/10000 quota remaining
9535/10000 quota remaining
9995/10000 quota remaining
> When should I use a key? The No Key limit is meant for light experimentation and simple development work. The instant you need the higher limit, it is acceptable to register for a key. Your application does not need to be in a releasable — even an alpha — state. Remember to update your application registration when you do release your app.
I'm new to Python and want to make sure I'm not developing bad habits. If you could please review this code below and give me any tips, practice ideas or critiques you might have. Any ideas on which aspects of the language I should focus on early would also be appreciated.
Thank you!
#!usr/env/...
If I explicitly specify a function & parameters inside a function it will print out the answer of each iteration of the loop that's inside my function, but when I replace the explicit function & parameters with a variable it will print out the first iteration only.
In my example_function_1 attem...
@syb0rg chat.stackoverflow.com/faq implies you should stay in chat as long as the chat is open in a browser window. Was it your bot that was kicked out? Perhaps the bot needs to do/simulate something Ajax-like as a keep-alive.
A friend of mine dabbles in lua, and he recently sent me a code which applies an equation we were discussing. I personally am very mediocre with lua, but my Python instincts are tingling - I feel as though this code could almost certainly be shortened. Any thoughts?
print("Choose what you want t...
I'm setting up a Django development environment using Vagrant to run an Ubuntu virtual machine on VirtualBox. As this is a student project run mostly be very amateur coders and I want everyone to be able to contribute, I want the environment to be as convenient as possible.
What I'm trying to ac...
This is loosely based on one of W3_School samples:
<!DOCTYPE html>
<html>
<body>
<p>Hello World!</p>
<p>The DOM is very useful!</p>
<p>This example demonstrates forEach() function</p>
<script>
var x=Array.prototype.slice.call(document.getElementsByTagName("p"));
x.forEach(function(value, index...
@SimonAndréForsberg technically, CC-BY-SA requires attribution of the copyright holder, which this question doesn't provide. Also, there is an argument to disallow questions about code not written by OP for reasons that go beyond copyright
You are a two, maybe 3 weeks away from 10K at your current rate
I am not sure if other people have the same competitive streak as me, but, I look at your rate of rep gain and see you in the top 6 with konijn in a month
@SimonAndréForsberg is a slacker at the moment.... and half of the top6 currenly are idle.
Well I was playing Neverwinter (MMORPG) and still have not completely decided whether I should stop or not, but haven't been playing actively in the last 3 weeks
@rolfl Sorry to contradict, but at 4K/month it would take another 3 months to squeeze into the "top 6", assuming Winston remains "idle". But simply exceeding 10k could be a useful milestone (for post-graduation privileges).
I have been so far very selfish only taking input and not contributing anything, but I have my own targets to commit and once done, maybe in a year, I might start returning back to community
Hello, @JavaDeveloper. It's nice to see you here. I look forward to seeing your contributions on this site, whenever time permits. Many of your questions so far have been quite good in terms of scope and interest, and the feedback from them should help you give strong answers someday. As always, continue to vote on useful posts, which is another great way to give back.
The pre-conditions for that code are: - you want to find the primes from integer value X to integer value Y - you already know all the primes from 2 to X - 1
It has been pointed out that using a sieve like that is not the most efficient though ... I should perhaps be using a BitSet .... but that makes the logic even more obscure.
Anyways just curious - there is another question - "given an excel sheet column translate it to numeric value". I have not seen a single good answer, have you happened to solve or review such an answer before
I was recently asked in a job interview to resolve a programming puzzle that I thought it would be interesting to share. It's about translating Excel column letters to actual numbers, if you recall, Excel names its columns with letters from A to Z, and then the sequence goes AA, AB, AC... AZ, BA,...
There are two number series
series 1 : 0 1 2 3 4 5 6 7 8 9 10 11 ...
And the second number series is stripped by zero's
series 2 : 1 2 3 4 5 6 7 8 9 11 12
Thus we can see that 12 of series 2 maps to 10 of series 1
I am looking for a formulae that can do such translations for me.
public static int getExcelColumnNumber(String descriptor) {
char[] chars = descriptor.toLowerCase().toCharArray();
int result = 0;
for (char c : chars) {
result *= 26;
result += c - 'a' + 1;
}
return result;
}
I am still working on A Z80 CPU emulator and I have decided to prototype it in javascript and then translate it into a faster language, It might be ported to C but more likely is Java - this means I cannot use pointers or jump-tables. It both compiles assembly and interprets it however both are g...