« first day (1592 days earlier)      last day (3344 days later) » 

fge
12:15 AM
1
Q: How do I deal with Function<T, R> and ellipsis in this case?

fgeOne of my project is throwing-lambdas; in it I aim to ease the use of potential @FunctionalInterfaces in Streams, whose only "defect" for being used in streams is that they throw checked exceptions (on my part I'd rather call defective the fact that you can't throw checked exceptions from streams...

 
fge
1:06 AM
OK, so I have stumbled upon a compiler bug it seems
 
 
5 hours later…
6:34 AM
@gem @Xryaznov heya
 
HI @ItachiUchiha
 
heya
 
i am getting error Application blocked by security settings
i thought it applet error
 
@ItachiUchiha Morning ^^
 
6:44 AM
@ItachiUchiha
i got email from client
Also, we have a big issue with a java applet. I believe you guys may have worked on this before.

As you are probably aware, Oracle has REALLY tightened the security on java run-time library functionality.

Currently, I believe our applet is unsigned, or has an expired signature. We need someone to make the necessary changes, signing, etc. that will make our .jar file run with the newest version of java on both Windows and Mac platforms and with the default (High) level of security setting in those operating systems.
 
Good morning, Java
 
Morning Oleg
 
6:59 AM
anyone look my above message
 
7:21 AM
@AniketDeshmukh You need to sign your jar. There is no other way.
 
it require to change in code files or only jar
 
thank you @ItachiUchiha
 
7:59 AM
Proof that a dog will look guilty even when he's innocent:
the cat flipped the treats over, and now the dog thinks he's gonna get blamed.
 
8:35 AM
@Gemtastic Yours? :D
 
@SecondRikudo Sadly not. I really want a dog :/
 
Here's mine ^
 
D'aaw :3
 
When you have a java8 stream, can you read one element without closing the stream (as does findFirst) ?
 
8:50 AM
You can, but the action wouldn't be called for until you are about to close the stream
 
@dystroy what do you want to do?
 
@ItachiUchiha do something different with the first line of a stream (which is made of lines of a csv file)
I know I could test a boolean (areHeadersInitialized) for each line but that would be ugly
 
@dystroy you can always use filter() on streams
but I guess that is not you want
 
someone told me that lambda can replace if else, who can show me a example. thanks
 
9:05 AM
@ming Be more selective on who to trust. That theory is nuts.
 
@Unihedro lol
 
@dystroy You can use a capture variable and a peek statement, I think.
 
@Unihedro Woudln't this also involve a boolean or counter ?
 
boolean foo = false;
stream.peek(x -> if (!foo) {
  // do something to x
  foo = true;
}) // chain on
@dystroy You can always hope for the compiler to spin up the variable into a stack counter for the consumer, since it's effectively never used anywhere else.
 
Yeah, but then I could directly do that in the following read, I find this ugly
I'd just want to have a function to read one element, like findFirst, but not closing the stream
 
9:12 AM
You can use a copy constructor to create a copy of the stream and then use findFirst.
=javadoc Stream#Stream
 
@Unihedro Sorry, I can't find that method. :(
 
Stream.Builder builder = Stream.builder();
stream.forEach(builder::accept);

builder.build().findFirst() // do something with it
That's not a copy constructor, but it does approximately the same.
 
don't you read the whole stream just to do something with the first line there?
 
Yes.
 
not very efficient...
 
9:19 AM
Streams are lazy; they only do what you tell them to and only when they absolutely have to.
It may sound inefficient, but it isn't
 
@Gemtastic yeah, but how should that prevent from reading one element without closing ?
 
It's not designed for that as far as I know. The Stream is a one use only, and you better know what you wanna do with the stream when you create it.
You can do many things in that one use, but it will still only work once
 
@dystroy maybe you should use a bufferedreader, read the first line, then use br.lines() (that returns a stream) to do the rest
 
I might as well totally skip the stream then...
 
why? you can keep doing the nifty stuff once you've read the first line
 
9:23 AM
I use a few mapping steps before I must do something different with the first line
 
@FlorianMargaine Ugh, I wanted to make a joke about looking for efficiency in Java code, but I can't do it. You're right.
 
try (Stream<String[]> lines = Files.lines(path).map(s -> s.split(";"))) {
    ... now do something different with the first line and then process the rest
 
private static void readStreamOfLinesUsingFiles() throws IOException
{
    Stream<String> lines = Files.lines(Paths.get("c:/temp", "data.txt"));
    Optional<String> hasPassword = lines.filter(s -> s.contains("password")).findFirst();
    if(hasPassword.isPresent()){
        System.out.println(hasPassword.get());
    }
    //Close the stream and it's underlying file as well
    lines.close();
}
this examples seems to imply that you have to explicitly close the stream
although it goes through all the lines...
 
@FlorianMargaine Streams are best used in try-with-resource blocks.
They're AutoCloseable, so.
 
@Unihedro is "open source" its own language?
 
9:25 AM
@Unihedro well, if he wants to close it himself...
 
@Gemtastic idk
 
@FlorianMargaine all examples I find involve many re-readings of the same files... They're retarded...
 
@Unihedro Hmm
 
I'll ask a question on main
 
I won't go further... I don't want to soil this computer by installing a java IDE...
 
9:27 AM
16 mins ago, by Unihedro
boolean foo = false;
stream.peek(x -> if (!foo) {
  // do something to x
  foo = true;
}) // chain on
 
Yeah, that's what I want to avoid of course
 
36 mins ago, by dystroy
I know I could test a boolean (areHeadersInitialized) for each line but that would be ugly
 
why?
 
47 secs ago, by Florian Margaine
36 mins ago, by dystroy
I know I could test a boolean (areHeadersInitialized) for each line but that would be ugly
 
So you want pretty code? Write a utility method that takes a stream and a consumer and nest everything in that method and you won't have to see it.
 
9:29 AM
pretty and efficient
I mean, pretty and not retarded
(because reading the whole file just to get the first line is retarded)
 
=javadoc Files
 
Which one do you mean? (type the number)
1. com.google.common.io.Files
2. java.nio.file.Files
 
2
 
@Unihedro java.nio.file.Files: This class consists exclusively of static methods that operate on files, directories, or other types of files. (1/2)
 
how is that pretty? :P
 
9:31 AM
Nah, I couldn't find Files' javadocs on ddg, so I used the bot.
I think Files.newBufferedReader will do better than using a stream from .lines.
 
@FlorianMargaine you want pretty code? Don't write it in Java? :P
 
@SecondRikudo java 8 allows pretty code...
note that I didn't say beautiful, or I'd just write lisp...
 
@FlorianMargaine Prettier than Java 6, certainly.
 
Yeah, that's a big improvement compared to java 6, but Java 8 is disappointing nonetheless... Everybody looks... half-made and clumsy...
 
9:35 AM
try (
    BufferedReader input = Files.newBufferedReader(
        Paths.get("c:/temp", "data.txt"),
        StandardCharsets.UTF_8
    );
) {
    String firstLine = input.readLine();
    // 1
    Stream<String> lines = input.lines();
    // 2
}
@dystroy s, 8,,
 
15 mins ago, by Florian Margaine
@dystroy maybe you should use a bufferedreader, read the first line, then use br.lines() (that returns a stream) to do the rest
 
@FlorianMargaine :O
I totally didn't see that, whoops
 
@Unihedro illegal start of expression
 
Yes you have to use proper lambda form.
 
boolean foo = false;
list.stream().peek(x -> if (!foo) {
// do something to x
foo = true;
}); // chain on
 
9:41 AM
=javadoc Stream#of
 
Which one do you mean? (type the number)
1. java.util.stream.Stream#of(Object)
2. java.util.stream.Stream#of(Object[])
 
2
 
@Unihedro Stream of(Object[] values): Returns a sequential ordered stream whose elements are the specified values.
 
@Michael Will we have proper varargs?
 
:21876829 Stream.of(list).peek(x -> if (!foo) {
            // do something to x
            foo = true;
        });// is this?
@Unihedro same error occurs
 
9:46 AM
peek(x -> {...})
 
if use peek(x -> {...}), can't find first element and break...
 
No, put the if then clause inside braces. It has to be in scope for it to be a lambda expression body.
 
0
Q: Handle one element in a stream without closing it

dystroyI'm looking for a clean and efficient way to apply a consumer to one element of a stream without closing the stream. I mean I want to replace boolean firstOneDone = false; lines.forEach(line -> { if (!firstOneDone) { // handle first line firstOneDone = true; } else { ...

 
@dystroy may use "try-with-resource"
 
What testing framework do you guys use?
 
9:58 AM
Doesn't fge use mokito?
 
fge
TestNG
 
@Gemtastic I thought mokito was just a mocking framework?
 
fge
@Gemtastic mockito is a mocking library, not a testing library
 
Well, shows what I know >_>
I should just be quiet today and focus on my thing...
 
fge
@SecondRikudo my recommendations are: TestNG, mockito and assertj
 
10:01 AM
But if we make the project like we talked about yesterday... Could we throw in some TDD into it since it's a part of the course?
(Obviously I need to learn more about testing)
 
fge
Sure thing
 
PowerMockito rules
 
Yaay
 
sigh Spring, why must you torment me so?
 
10:06 AM
@fge
30 mins ago, by Florian Margaine
15 mins ago, by Florian Margaine
@dystroy maybe you should use a bufferedreader, read the first line, then use br.lines() (that returns a stream) to do the rest
 
Spring's magic is dark magic
 
fge
@Unihedro PowerMockito sucks
 
That's it? That sums all of Spring Boot's CLI capabilities? XD
 
fge
The day when you have to use it, the code has a problem
 
Or am I missing something?
 
10:08 AM
private SubTest getSubTestByTime(int time) {
for (SubTest t : subTests) {
if (t.getTime() == time) {
return t;
}
}
// java8
// subTests.forEach(st -> {
// if (st.getTime() == time) {
// TODO i need break at here
// }
// });
return null;
}
in this method, i want to translate to java8
but in the forEach can i break?
 
fge
@ming use .findFirst()
 
@fge yeah, i will try thank you
 
fge
return subTests.stream().filter(st -> st.getTime() == time).findFirst().orElse(null);
 
@fge if use filter, the loop is run from first to last
if use for, i can find the element then breank
 
Wow I just had a huge epiphany. I can't believe I never realized it before
 
10:15 AM
Is it related to grammar?
 
No it's related to the commandline
 
@ming that's not really how it works
 
sorry my en is week
 
Streams are lazy and the operation is performed only on the terminal call (findFirst)
 
@Unihedro Wow I just had a huge epiphany.
 
10:17 AM
but you can only do one operation on the streams...
 
thank you
 
@FlorianMargaine You can perform many things on one stream, you can only use the stream once though.
 
@FlorianMargaine that's essentially what streams are
 
fge
@ming no; streams are lazily populated
 
in java, yeah...
 
fge
10:20 AM
@FlorianMargaine what do you mean?
 
@fge yep, you are right
thank you
 
@fge what Gemstatic said
 
fge
Ah, yeah
@ming but your original code just works, so why not just keep it as is?
 
which is stupid imho
 
fge
10:22 AM
@FlorianMargaine that's just the way they are designed; and you can always recreate a stream anyway if you need to
 
or use peek for intermediate operations abusively :p
 
@fge yeah, I'm talking about the fact that the design is stupid
 
@fge +1
The design isn't stupid; it's lazy ;D
 
fge
@FlorianMargaine that's your opinion
That's not mine
I do wish that .forEach() was less surprising on parallel streams though :(
 
the use case on @dystroy's question shows it... it's not a corner case
 
10:23 AM
@fge this is my test code, i'm learning lambda
 
Fact still remains that when you use streams as intended, you'll have a much faster tool that doesn't eat unnecessary memory.
 
fge
Oh, come on, that's easily solvable
 
recreating a stream is a good solution for you?
 
@Unihedro in which case we require pay for a certificate while Signing JAR Files and how
 
fge
No need to recreate a stream at all
 
10:24 AM
dinner time byebye ereryone
 
fge
Just grab the iterator from it, grab the first value and then .forEachRemaining()
Problem solved
 
@Gemtastic you can have streams that don't eat unnecessary memory without having a one-time-only stream...
@fge sounds interesting, could you add an answer on the thread?
 
The design is a part of the concept of immutability. If you think it's dumb don't use it, but chances are, you code won't be as efficient.
 
@FlorianMargaine You can't have that without going into the native level.
 
@Gemtastic you mean in case the stream is used in 2 threads in parallel?
 
10:28 AM
If I remember it correctly, stream will autothread on its own. It's designed for multi-core use.
 
fge
A stream may, or may not, be parallel; in fact you can't tell
This is why Collectors have characteristics for instance
I had asked the question in fact:
12
Q: Can a Java 8 `Stream` be parallel without you even asking for it?

fgeAs I see it, the obvious code, when using Java 8 Streams, whether they be "object" streams or primitive streams (that is, IntStream and friends) would be to just use: someStreamableResource.stream().whatever() But then, quite a few "streamable resources" also have .parallelStream(). What isn'...

 
> If they're polite, they'll specify their behavior.
duh
 
11:00 AM
hello @Unihedro
 
@AniketDeshmukh hi
 
i want to Signing JAR Files
 
@Gemtastic This is true on so many levels.
 
11:19 AM
If I pass a String[] to a function that accepts a String... will it works as expected?
 
Hi All, i need some help on Elasticsearch, so can one one spare some time to help me?
 
@SecondRikudo I think you'll get a compile time error
 
Nope, it should work. ... is syntactic sugar for arrays
 
Oh, it's a vararg? Sorry, I thought it was ellipses as part of the sentence
 
For some reason I always write main(String[] args), but use ellipses everywhere else I want varargs
at least I understood it as being about varargs
yeah, a typo
 
11:25 AM
@kiheru Ok.
 
With Java 8, is it possible to transform a list of objects into a list of strings (i.e. .map())?
I have a List<MyObject> and one of the fields on MyObject is the string I want.
 
Would you like a stream method?
list.stream().map(Object::toString).collect(Collectors.toList());
 
fge
@SecondRikudo .map(MyObject::theGetterMethod)
 
Cheers
 
fge
And then collect as @Unihedro says
 
11:32 AM
I need to collect to a string anyway
So Collectors.joining("\n") it is
Thanks :)
 
Collectors.joining is the best collector IMHO.
It's not like there's an easy way to collect an array as A B C D instead of [A, B, C, D] otherwise.
 
arrayOfObjects.map(obj => obj.getter()).join("\n")
is how that would be done with JS ^
 
Even with a StringBuffer, it's hard to avoid The Inevitable Space In The Endâ„¢
Lambda in JS!
 
11:46 AM
@Unihedro although in JS, you can do crazy things with those methods
You can map an array of objects to an array of functions, then map those function to the results of those functions, for instance
 
12:41 PM
hiya @all
 
Heya @Vog
 
wow... this uh...
ouch...
 
?..
 
you know what's extremely pissing??
 
12:45 PM
?...
 
@SecondRikudo arrayOfObjects.reduce((str, obj) => str + '\n' + obj.getter(), '');
 
@ECHO OFF
echo ---------------------------------------------------------------- Build TIME: %TIME%
set _PATH=%PATH%
set ANT_HOME=%DEVELOP_HOME%\applications\ant-1.6.5
set ANT_OPTS= -Xmx256M
set PATH=%PATH%;%ANT_HOME%\bin
ant -listener net.sf.antcontrib.perf.AntPerformanceListener -Ddevelop.home=%DEVELOP_HOME% -Ddevenv.home=%DEVENV_HOME% %1 %2 %3 %4 %5 %6 %7 %8 %9
set PATH=%_PATH%
^ buildscripts like this
in a company with "free choice of OS"
 
@FlorianMargaine Mine is shorter, and I like it better conceptually too.
 
@SecondRikudo conceptually you're looping twice :/
 
@FlorianMargaine That's an implementation detail, not a conceptual one.
 
12:47 PM
also, conceptually, you're reducing an array of something to a single string
 
Although you do have a point.
 
@Vogel612 what the actual?
set _PATH=%PATH%
set PATH=%_PATH%
xD
 
which is usually a hint that you should use reduce (this)
 
@Unihedro that's the buildscript to use in combination with a 1.5k Lo"C" build.xml ant-file
which has stuff like this:
 
Gotta love 2k LoC methods
 
12:49 PM
<property name="agency.version.home" location="../../../"/>
aka: "IMPLYING directory structure XY"
and the "best" is: it's using SVN as VCS... over three branches and with manual dependency management
oh cool I found a table with the name assmntblxassmnt
 

« first day (1592 days earlier)      last day (3344 days later) »