« first day (3547 days earlier)      last day (1395 days later) » 

4:50 AM
picks nose
 
 
2 hours later…
6:50 AM
Hi. I am trying to solve a problem in which given a sorted ArrayList, I am supposed to remove duplicates. For some reason (maybe some internal working in java) my code works for smaller numbers but not the bigger ones. Can someone please point out what am I doing wrong?
incase you are wondering why did I actually remove the elements from the arraylist instead of just returning the number of unique values, the problem statement stated that I am supposed to remove the elements as well.
 
Zoe
7:42 AM
Why not just use a set?
/javadoc Set
 
@Zoe it needs to be solved in place
 
Zoe
Ah, so another unrealistic school assignment :')
 
8:42 AM
morn
 
morn
 
8:55 AM
@jatin a) you are only checking consecutive values, so you would find a duplicate if your list looks like this: [1, 2, 1] and b) don't use "==" to compare for equality. Use ".equals ()"
 
Zoe
@PhilipHelger It's a sorted list
It would be 1, 1, 2 or 2, 1, 1 depending on the sort, so it does work
== doesn't work on strings, but it works on ints and other primitives
ints being primitives also means there isn't an .equals method, because it's one of the very few things in Java that isn't an object
 
9:24 AM
@Zoe haha indeed
 
Zoe
it's actually weird though
oh, wait xd
Philip is actually right xd
 
@jatin an easy approch though you might not be allowed to use it. noduplicates = mylist.stream().collect(Collectors.toSet())
 
Zoe
It's a list of Integers, not a list of ints
 
yes he is righ
 
@Zoe of course it is... I have never seen a List of ints :P
well not in standard jdk
 
Zoe
9:27 AM
@motaa I've been doing a lot of C++ lately :')
 
hehe
you are excused
 
Zoe
std::vector<int> is perfectly valid there ^^"
 
Thanks @PhilipHelger @Zoe
It's amazing how sometimes some harmless-looking problems can bring you down to earth. lol
 
@jatin this is a classic problem that lots of people have when getting into the Java world :D
 
That's why I don't like auto boxing, because it doesn't really solve problems. You always need to know whether you are on the primitive or on the object
 
9:35 AM
@motaa Ironically I have been a part of java family for the last 4 yrs. lol. I think I need some more coffee.
 
@jatin bring me some along will you? :)
 
sure!! :D
 
 
3 hours later…
12:09 PM
@Wietlol lol
 
Zoe
@wiet lol
 
@Wiet nam
 
/wietloldamnit
 
its not weitlol, wietbol, weitol, wetlal, wietnam, wietlawl, wietrofl, wietroll, wietlmao, waldoil, walido, wiedol or wheat-lol, its Wietlol damnit
 
Zoe
/wietloldamnit
 
12:12 PM
its weitlol, wietbol, weitol, wetlal, wietnam, wietlawl, wietrofl, wietroll, wietlmao, waldoil, walido, wiedol or wheat-lol, its ABSOLUTELY NOT UNDER ANY CIRCUMSTANCE Wietlol damnit
 
-_-
there is a new one actually...
Wietlot
 
Zoe
okay, wietlol damnit
 
 
2 hours later…
2:41 PM
o.o
did anyone have experienced this kind of oddity in code;
    return Optional.ofNullable(DataAccessUtils.singleResult(
            jdbcTemplate.query(sql, sqlParameterSource, rowMapper)
    ));
this gives an empty optional. But when I place a breakpoint there, at the return and debug it by going step by step, I get a list with one item once jdbcTemplate.query(sql, sqlParameterSource, rowMapper) got executed. The Optional returns with an item in it.
WHY IS IT GIVIN AN EMPTY OPTIONAL WHEN I DO NOT USE BREAKPOINT???
(note: arguments are same, identical, as 1 =1 )
 
what does singleResult return?
 
from Spring, here's the source
	@Nullable
	public static <T> T singleResult(@Nullable Collection<T> results) throws IncorrectResultSizeDataAccessException {
		if (CollectionUtils.isEmpty(results)) {
			return null;
		}
		if (results.size() > 1) {
			throw new IncorrectResultSizeDataAccessException(1, results.size());
		}
		return results.iterator().next();
	}
the data is there. Even if I run the query manually in the db, I get one record
 
then I guess it returned null
 
but it is not empty if I put a breakpoint there :/
 
have you tried splitting that return into multiple lines, validating the values?
var queryResult = jdbcTemplate.query(sql, sqlParameterSource, rowMapper);
var singleResult = DataAccessUtils.singleResult(queryResult);
var optionalResult = Optional.ofNullable(singleResult);
return optionalResult;
 
2:47 PM
a minute
 
validate that the optionalResult is indeed not empty
validate that the singleResult is indeed not null
validate that the queryResult is not messed up
I have had a few cases where I was confused
but it never had to do with something like Optional not working correctly
 
gotcha run that without setting a breakpoint and using exact same parameters
 
there has been one case where debugging did something different than running... which iirc was Zoe's fault
or maybe it was geist
 
ok, Optional is empty.
but when I put a debugger there, at queryresult,
I got this
var queryResult = jdbcTemplate.query(sql, sqlParameterSource, rowMapper); // debugger -> using step over
var singleResult = DataAccessUtils.singleResult(queryResult);
var optionalResult = Optional.ofNullable(singleResult);

var queryResult = jdbcTemplate.query(sql, sqlParameterSource, rowMapper); // list blablabla
var singleResult = DataAccessUtils.singleResult(queryResult);
var optionalResult = Optional.ofNullable(singleResult);

var queryResult = jdbcTemplate.query(sql, sqlParameterSource, rowMapper);
so when debugger is used, it has data. But if I remove debugger, it does not have data
😵
I-cannot-fucking-explain-this
semicolon
 
I blame geist
 
2:57 PM
still need to be verified tho. Building atm
 
Jul 29 '19 at 5:44, by geisterfurz007
https://paste.ofcode.org/pm7Lkwk7FqC3JHUbUbnRph @Wietlol as short as I can get it for now. Probably contains a bunch of other stuff that could influence the behaviour. You got two commented peek statements, one in line 28 and one in line 57. You can uncomment and comment them as you like and should get different outputs.
 
nope
grr
 
3:17 PM
@KarelG Is your debugging profile configured to use different environment variables, command-line arguments, or configuration files?
 
no
just checked haha
there was an old java ranch post and someone mentioned that. I thought "why not".
funny: my colleague is able to reproduce this as well
without debug: empty optional. Put a debug: got info
xD
 
Maybe it's some kind of threading issue. By adding a breakpoint, you are giving background threads more time to run.
 
3:33 PM
but it's just the same stuff as I use on other locations
why just here
gotcha stop with this because I am loosing my mind
 
@KarelG This only happens on your computer and not on other computers?
 
 
2 hours later…
5:15 PM
Hi can anyone help me resolve this, Am Missing SELECT keyword
with
    params (client_id) as (select 1 from dual),
    prefs  (min, max) as (select 2, 4 from params)
    select * from prefs;
 
 
2 hours later…
7:23 PM
This should be a fun question,

I have a scheduler that runs jobs. Some of these jobs require the user session to be elevated (some state is set) to run. If so, the session needs to be de-elevated once the job completes.

To avoid having some "remember to unset" magic going on, I am considering taking advantage of the AutoclosableInterface to have it automatically call close, which will de-elevate the session.

I got the idea by thinking of commissioning / decommissioning the session.

That said, is what I am doing wise? There is no real point of throwing an exception with this logic, whic
 
@DustinE. Welcome to the Java Chat, the room for Java enthusiasts! I'm Oak, one of the room's bots. If you want to ask a question, just ask it and someone will respond if they feel like it. But remember that this room is not a help desk or tutoring service! If you want to just hang out, then welcome aboard! Oh, and the room's full list of rules are posted here.
 
@Ghostff What dialect are you using, surely the SQL chat room would be a finer place
 

« first day (3547 days earlier)      last day (1395 days later) »