java Stream how to compare two List then add main object - java-stream

List = [{fileName:'11',idx:1}]....
List = [{fileName:'11',uplod_idx:''}]....
listss.stream()
.forEach(x->{
b.stream().filter(y->y.getFilename().equals(x.getFilename()))
.map(y->{
y.uplod_idx(x.getIdx());
return y;
});
});
how to fix compare anymatch or someting
I mean. How to change smart then me.

Related

How to assign results of futures in Dart depending on which future produced them?

In Dart, I want to run several costly functions, which are independent of each other, and assign the results to my variables, depending on which function produced them. Roughly a parallel version of this:
double x = getX();
double y = getY();
I'm thinking of something like this:
double x, y;
Future.wait([
futureGetX(),
futureGetY()
]).then((List results) {
results.foreach((r) {
// if(r is produced by futureGetX) x = r;
// if(r is produced by futureGetY) y = r;
});
});
and I don't know how to implement this is produced by part. A way would be to wrap the result of each function in a different class and, in the then part, check the class of the result:
if(r is wrapperForX) x = r.getValue();
if(r is wrapperForY) y = r.getValue();
but this seems very inelegant to me. Any suggestions?
Untested, but I think I got this. :)
Use closures:
Future.wait([
() => { x = await futureGetX()},
() => { y = await futureGetY()},
]);
Thanks to Randal I found a solution:
Future.wait([
() async { x = await futureGetX(); } (),
() async { y = await futureGetY(); } ()
]);
To wait for Futures in parallel, you use Future.wait, as you already noticed.
The results in the list returned (asynchronously) by Future.wait are in the same order as the original futures, so instead of using forEach you can just do:
x = results[0];
y = results[1];
Another way would be to use FutureGroup from async package, FIFO behavior for the result list is documented: https://www.dartdocs.org/documentation/async/1.13.3/async/FutureGroup-class.html

Count of the biggest bin in histogram, C#, sharp

I want to make histogram of my data so, I use histogram class at c# using MathNet.Numerics.Statistics.
double[] array = { 2, 2, 5,56,78,97,3,3,5,23,34,67,12,45,65 };
Vector<double> data = Vector<double>.Build.DenseOfArray(array);
int binAmount = 3;
Histogram _currentHistogram = new Histogram(data, binAmount);
How can I get the count of the biggest bin? Or just the index of the bigest bin? I try to get it by using GetBucketOf but to do this I need the element in this bucket :(
Is there any other way to do this? I read the documentation and Google and I can't find anything.
(Hi, I would use a comment for this but i just joined so today and don't yet have 50 reputation to comment!) I just had a look at - http://numerics.mathdotnet.com/api/MathNet.Numerics.Statistics/Histogram.htm. That documentation page (footer says it was built using http://docu.jagregory.com/) shows a public property named Item which returns a Bucket. I'm wondering if that is the property you need to use because the automatically generated documentation states that the Item property "Gets' the n'th bucket" but isn't clear how the Item property acts as an indexer. Looking at your code i would try _currentHistogram.Item[n] first (if that doesn't work try _currentHistogram[n]) where you are iterating the Buckets in the histogram using something like -
var countOfBiggest = -1;
var indexOfBiggest = -1;
for (var n = 0; n < _currentHistogram.BucketCount; n++)
{
if (_currentHistogram.Item[n].Count > countOfBiggest)
{
countOfBiggest = _currentHistogram.Item[n].Count;
indexOfBiggest = n;
}
}
The code above assumes that Histogram uses 0-based and not 1-based indexing.

onFullSync action, show updated info - DHTMLX Grid + RoR

I have a Ruby on Rails project where I use a DHTMLX Grid.
Is there a way of showing, using the event handler "onFullSync" provided by the grid API, to show updated data?
Let me explain a little better... I know I can do something like:
dp.attachEvent("onFullSync", function(){
alert("update complete");
})
But what I want is something more complex. I want to, after each completed update, alter a div adding the information like this:
Field 2 was updated to XYZ and field 3 was updated to XER on line X
Field 1 was updated to 123 and field 3 was updated to XSD on line Y
Is this possible?
Thanks
There is a onAfterUpdate event that can be used similar to onFullSync
http://docs.dhtmlx.com/api__dataprocessor_onafterupdate_event.html
It will fire after each data saving operation ( if you are saving 5 rows - it will fire 5 times )
Still, info about updated columns will not be available here.
Also, you can try onEditCell event of grid. It fires after changing data in db, but before real saving in database. Here you can get all necessary info - row, column, old value and new value.
http://docs.dhtmlx.com/api__link__dhtmlxtreegrid_oneditcell_event.html
So, what I end up doing was:
After creating the grid I created an array:
var samples = [];
Then, as per #Aquatic suggestion, I added to "onEditCell" event the following line:
samples[samples.length] = grid.cells(rId, 5).getValue();
This allowed me to add to the array the value present on column 5 of the row changed. Then, on "onFullSync" event I hide or show the div created on the view with the messages (I distinguish if it's on row or more changed on the grid).
//Deals with messages after update
dp.attachEvent("onFullSync", function(){
unique_samples = uniq_fast(samples.sort());
if (unique_samples.length == 1){
$('#updated-samples').text("");
$(".messages").show();
$('#updated-samples').text("A seguinte amostra foi actualizada: " + unique_samples[0]);
//to clear the array
samples = [];
} else if (unique_samples.length > 1){
$('#updated-samples').text("");
$(".messages").show();
$('#updated-samples').text("As seguintes amostras foram actualizadas: " + unique_samples.sort().join(", "));
//to clear the array
samples = [];
} else {
$('#updated-samples').text("");
$(".messages").hide();
//to clear the array
samples = [];
}
})
The problem with using "onEditCell" is that everytime a field is changed on that row I get a repeated value on my "samples" array, I I had to remove duplicate from that array. For that I used one of the suggestions at this answer
// remove duplicates in array
function uniq_fast(a) {
var seen = {};
var out = [];
var len = a.length;
var j = 0;
for(var i = 0; i < len; i++) {
var item = a[i];
if(seen[item] !== 1) {
seen[item] = 1;
out[j++] = item;
}
}
return out;
}
Then I have on the beginning of the view, to show the messages:
<div class="alert alert-success messages" id="updated-samples">
And that's it. I could be not the most efficient way but it works for what I wanted. I will leave the question open a few more days to see if any other option appears.

How to change direction of existing link in zoomcharts

I'm trying to do it like this
function btnChangeDirClick(){
var fromNode = document.getElementById("linkMenuLinkFrom").value;
var toNode = document.getElementById("linkMenuLinkTo").value;
chart.addData({
links:[{id:document.getElementById("linkMenuLinkid").value,
from:toNode,
to:fromNode
}]
});
}
but my console returns
Changing link from,to not supported
Of course it's possible to delete and recreate, but are there any alternatives?
One alternative is to store a direction flag in data and assign from and to decorations depending on it.
I suggest using delete/recreate for now. Link reconnection support will come.
Finally I ended up implementing is as follows, which works fine:
function btnChangeDirClick(){
var fromNode = document.getElementById("linkMenuLinkFrom").value;
var toNode = document.getElementById("linkMenuLinkTo").value;
chart.removeData({links:[{id:document.getElementById("linkMenuLinkid").value}]});
chart.addData({
links:[{
"id":document.getElementById("linkMenuLinkid").value,
from:toNode,
to:fromNode,
"style":{label:document.getElementById("linkMenuLinklabel").value}
}]
});
nextId += 1;
document.getElementById("linkMenuLinkFrom").value = toNode;
document.getElementById("linkMenuLinkTo").value = fromNode;
}

Function with multiple names

In JavaScript you can do this to assign a function to multiple references:
z = function(){
console.log(1)
}
x = y = z
Now when we call x or y, 1 gets printed to the console.
Is this possible in dart?
Yes, just like in JavaScript, functions are first class citizens and can be assigned to variables.
Also see this somewhat older, but still relevant video Functions are Fun, Pt2.
As Example from the video:
loudPrint(String msg) {
print(msg.toUpperCase());
}
var loudify = loudPrint;
loudify('Dart is fun');
// DART IS FUN

Resources