« first day (2890 days earlier)      last day (2034 days later) » 

12:00 AM
"People rise to the occasion without hesitation when they feel inspired and challenged." -Lorii Myers (source)
 
is this our resident bot? neat
so now we know that Streams have all those operators we need, but we have a problem
 
Just FYI, I know about lists but haven't used. I just know their better versions of arrays with more methods you can call.
(Sorry)
 
that's pretty much all you need to know about them, they're just more OO versions of arrays
so if we convert our list to a Stream and we want to run two operations on it -- say, a filter and a map -- but our filter gives us back a List, then what will we do?
we'll need to convert the List back to a Stream before we can run our map
 
And what exactly are "Collections"? I have seen before. But just want to make sure.
 
a Collection is literally just a collection of objects. It's just an interface that everything like Lists, Sets, etc. all inherit from
 
12:03 AM
ah
 
basically just means that it's Iterable
not technically but that doesn't matter
 
@forresthopkinsa wdym by this? Don't you just do x -> Math.sqrt(x*2)?
@forresthopkinsa ok...
 
well inside of the lambda scope, sure
the lambda just knows, number in, number out
 
yepo
 
but our map function needs to return some kind of Object
 
12:04 AM
buuuuuuutttt.....
:)
 
hahahaha. if we need to run another Stream operation after our map then we want it to return a Stream
our Streams, being streams, like method chaining: list.filter(...).map(...).skip(2)...
 
@forresthopkinsa wdym return an object, why not just an int or string, etc.?
 
well the map() function operates on the scale of the entire list, rather than each element
so e.g. if map() returned an int, then where would the list go?
a series of numbers goes into the map and a series of numbers goes out. The question is, what container is holding that series of numbers
 
well I figured its the equivlant of a for loop so it would just replace the original value that x originally was but as I am typing that I am realizing that that makes no sense....
 
haha yeah a map doesn't modify its input
 
12:08 AM
just passes it
 
@forresthopkinsa Idk.
 
and since the map operates on itself (i.e., it doesn't take the list of numbers as one of its parameters; it acts on the instance it belongs to), the input will always be the Type that map is a part of
i.e. a Stream
sorry if that's kind of a difficult explanation
 
So basically.....
List doesn't have the map option, but stream does, so we have to convert it a .stream(). But map will return what we give it (a stream) so we have to convert it back to a list
 
right
check this out
this is the method definition of Map:
 
12:11 AM
vs. JS where the Array directly has the map()
 
it's inside the Stream interface
right
 
@forresthopkinsa IntelliJ! XD
 
of course! hahaha
 
@forresthopkinsa you say that yet everyone else in my class uses eclipses, including the teacher
/facepalm
 
12:13 AM
IME students use Eclipse and professionals use IDEA
not 100% true but that's very often what I see
 
@forresthopkinsa ok so what exactly is that telling us
 
I used Eclipse for a long time but shortly after I started working, I grabbed IDEA and I was amazed at how much more powerful it is
what it's telling us is the method contract for .map()
we have two inputs for it
 
@forresthopkinsa I'm in High School so their def not pro's XD
 
hahaha yeah I was using Eclipse at that point as well
the first input is the instance that map is being called on, i.e. the Stream coming from before the period
myStream.map()
the second is our parameter, the lambda
...map(myFunction)
 
@forresthopkinsa Never used eclipse. I am self taught + stack overflow and I was told to use a Intellij so I went with it and it was great!! I was originally using terminal javac and java (yeah, I know)
 
12:16 AM
you definitely have to start there so that you know what's going on under the covers
 
@forresthopkinsa Got that.
 
ok so
we'll talk about the output in a sec
hey sorry talking to coworker
 
@forresthopkinsa I demand that you quit your job and prioritize some random person on the internet over your job.
;)
 
absolutely sir
so here's the chain I presented earlier:
15 mins ago, by forresthopkinsa
our Streams, being streams, like method chaining: list.filter(...).map(...).skip(2)...
.filter and .map and .skip are all Stream operations
we have to make them all return Streams so that we can chain them like that
 
wait
 
12:22 AM
or else we'd have to do something like list.toStream().map(...).toStream().filter(...).toStream.skip(2)...
 
I thought they were returning streams, thats the problem
 
they are yes, I'm explaining why
 
ah
got it
 
soo
at the end of our chain
we have a Stream that has all the filtered, mapped elements in it
and we need to turn it back into a List
 
.toList? XD
 
12:25 AM
we use .collect(...) to collect stream elements
nearly! but Java is way more wordy than that hahaha
.collect(Collectors.toList())
 
@forresthopkinsa ofc. Why would Java make it easy for us?
 
and then we have a List
hahahaha right
 
so why .collect?
"to collect stream elements" wdym?
 
well the idea of a Stream is that every operation done on it just acts on each element
none of them are really "aware" of the bigger picture, i.e. the list
so the terminal operator, collect, is just taking the elements being passed down from above and adding each one to a list
in some really weird situation where you're trying to return a stream I guess
you're pretty much always going to end up finishing your stream with a .collect or something similar
 
oh
Can you have a stream variable type?
 
12:28 AM
in your situation, you don't have a list. You have an array. So it's a little different.
sure
everything in Java is typed of course
 
just making sure :)
 
you can hold the result of any operation in a variable
except void I guess
so
your array
based on this answer, looks like your "collector" is going to look like .toArray(Integer[]::new)
 
hold up
 
so .collector.toArray(Integer[]::new)? If so, can you also explain ":" see them all the time but never use them. I am guessing they are the shorting of something longer?
 
12:32 AM
sure
:: is a method reference
let me explain
say you have a method public int foo(int x)
and say you have a higher-order function public void bar((int) -> int)
of course in Java that would actually look like public void bar(Function<Integer, Integer> func)
 
ok
sorta got that
 
ok so now we have two things: a function that takes an int and produces a new int, and a function that takes a function that takes an int and produces an int
so how can we give the first function to the second one
well, if we use a lambda, it'll look like
bar(x -> foo(x))
 
@forresthopkinsa so one returns an int and the other makes a new one
 
the second one actually takes a function as a parameter
so we give it foo, which fits its required parameter type (int) -> int
 
Don't exactly get functions as arguments
 
12:39 AM
yeah it's definitely a little more difficult to grasp
anyway
point of a method reference is the ability to pass around functions as objects
so instead of saying bar(x -> foo(x))
we can say bar(this::foo)
 
bar::foo?
close
 
yeah close!
the left side of the :: just says where you can find the function
the right side is the function identifier itself
 
isnt that passing bar into foo?
 
it's actually passing foo into bar
when we call it from somewhere saying bar(this::foo)
 
so "this" refers to what?
 
12:41 AM
we're giving this::foo as the argument
oh you know, the class that you're in
I'm just assuming this is all happening in the same class
So: method reference just means, passing around a function as an object
 
@forresthopkinsa oh, I was overthinking that one
 
hahaha yeah
so .toArray(Integer[]::new)
 
@forresthopkinsa what about x? foo(x)?
 
x was just a lambda parameter
 
but its required by foo
 
12:42 AM
it was just made up for our lambda
 
foo(int x)
 
well see, when we reference the function, it intelligently understands that bar is going to give foo a number
because bar needs something that will take a number and produce a number
and foo does that
.toArray() is kinda like bar
 
how is bar giving foo an int if foo is required to call bar?
deadlock
 
foo doesn't call bar
we're giving foo to bar
 
foo returns and int and gives that int to bar
 
12:44 AM
and bar will use it however it wants
the inside of bar will contain something like: int myNewNumber = func.apply(2);
and so when we pass foo to bar, foo gets called when bar runs func.apply
10 mins ago, by forresthopkinsa
of course in Java that would actually look like public void bar(Function<Integer, Integer> func)
 
Oooooooooohhhhh
Its not passing the return value of foo its passing foo itself?
 
exactly
so toArray() is doing the same thing
 
toArray(Integer[]::new)
 
the method signature is basically toArray(Function<Integer, Object> func)
toArray wants a function that will consume an integer and produce an object
 
@forresthopkinsa "Integer" = Integer[]; "Object" = new
 
12:48 AM
sorta
when we call it like I did above, toArray(String[]::new)
what we're really doing is toArray(x -> new String[x])
we're giving it back a starting array of the correct size and type
 
x is an int?
 
yeah
remember, the function that toArray takes must consume an int and produce an object
uhhh
what do you mean
here, the object that needs to be produced is an array
 
So we are creating an array with a bunch of string arrays? because each iteration of the x stream is creating a new String[]
 
but see, toArray is a terminal operation
 
@forresthopkinsa oh, what makes more sense
 
12:52 AM
which means it doesn't return a Stream
yeah
 
yes
 
so it's just making one array, and putting everything it receives into it
we just need to tell it how to make the array
'cause it doesn't know what type of array we need or anything
 
so if I interrupt toArray(x -> new String[x]) at toArray(x -> what is x? The number of things from the stream?
 
yeah, the total number of elements when the stream is done
and it needs to be the size we initialize the array at
 
ah
ok
new String[] new = Arrays.stream(old).map(x -> x*2).collector.toArray(String[]::new)
 
12:57 AM
I need to head home but
check this out
I think it's doing what you need
ttyl
 
Great!
 
Thanks so much for help!
 
no problem
see ya
 
Sorry for all the questions, just want to make sure I really get it.
@forresthopkinsa Will look at
@forresthopkinsa Cya later THANKS!!
 
 
4 hours later…
Zoe
4:35 AM
Mornin
 
5:12 AM
Mornin!
 
 
1 hour later…
USM
6:13 AM
I am writing one dummy project on spring boot, how excatly should i call my class , as default main method is in @SpringBootApplication class.
 
6:28 AM
If I have an API endpoint to upload multiple files at once it should ideally just fail if one file could not be written to the target location, right?
 
Morning
 
Morning.
 
user8622974
Morning
 
/fire :p
 
7:16 AM
hi
 
@user3510366 Welcome to the Java Chat, the room for Java enthusiasts! Please use a code snippet tool when posting code snippets. If you have an Android question, you're in the wrong place! And remember: this is not tech support! Thanks for visiting and have fun! :D
 
am working on grouping by in elastic search
TermsBuilder ipGroupAgg = AggregationBuilders.terms("by_ipGroup").field("IP Group")
.subAggregation(AggregationBuilders.terms("by_Priority").field("Priority"));
// create the bool filter for the condition above
String[] priority= { "2", "3" };
BoolQueryBuilder aggFilter = QueryBuilders.boolQuery().must(QueryBuilders.termsQuery("Priority", priority));

// create the filter aggregation and add the year sub-aggregation
FilterAggregationBuilder aggregation = AggregationBuilders.filter("agg").filter(aggFilter).subAggregation(ipGroupAgg );
gives compile error in the last line at .filter(aggFilter)
The method filter(FilterBuilder) in the type FilterAggregationBuilder is not applicable for the arguments (BoolQueryBuilder) is the error description
 
7:37 AM
Please format your code by using Ctrl+K prior to sending your message or use a paste site.
 
7:57 AM
Hi guys good morning
 
Morning dude
 
I need to understand which is the best handle error behaviour in my program for example suppose to have a form and I do CRUD operation. I want undestand what I must see to the user.
For example if I receive an 500 error I need to redirect users in my 500_error_page?
and if I receive 400 and 404?
 
//lmgtfy java custom error page
 
user8622974
 
@Doflamingo19 5XX series is for server side issues, here is list restapitutorial.com/httpstatuscodes.html
 
8:05 AM
This does not answer the question.
 
@geisterfurz007 dude that is not answer XD, that is just suggestion.
 
@Simmant I know code error :)
 
well, now for your answer.. if you want to show error to user, then make generic page with some message like "some thing went wrong" or some thing like that, I guess just show them message code not complete details, and in log you can dump every thing.
 
> I need to redirect
"Just make an error page"
 
also, you can categories error like critical, data_error etc.
 
8:10 AM
@Doflamingo19 I think you can configure error codes in your web.xml
 
@geisterfurz007 generic error page :)
 
I'm reading thanks!
 
He asks how to redirect and your answer is to create an error page. See the issue? ;)
 
<web-app ...>
<error-page>
<location>/general-error.html</location>
</error-page>
</web-app>
@geisterfurz007 I like to explain with flow B-)
 
ok I undesrtand for 404 or 500
but for 400 that is "parameters wrong"
it's better show a message on the form and not a "PARAMETTER ERROR" string with all text?
 
8:15 AM
I guess you can have error message, along with some details of error.
Message + String passes to end-point.
 
@geisterfurz007 Saved.
 
Thanks you.
 
xD
 
morn
 
user8622974
morn
 
8:45 AM
morn
 
morn known the unknown
6 star on that java countdown message wow we have 7 users here now :D
 
Henlo unknown
announ
 
me, Zoe, Nick, motaa, Cold, rabbit?, wonder, Jenna, Tavo, Rob?, Tim?, Mibael, Itachi... I am missing a few stars
 
You... You... You just ignored me? ;-;
cries in corner
 
@geisterfurz007 you are the one who wrote the message
you cant star it
I only included members that can star your message
 
8:52 AM
You... You... You are right.
cries in corner
 
You... You... You just ignored me? ;-;
cries in corner
 
yes, yes I did
I dont know you
 
wow
 

« first day (2890 days earlier)      last day (2034 days later) »