I am working on program that should make rectangle moves from top to bottom and then left to right once the rectangle crosses the borders of the frame it should reverse its motion from right to left and bottom to top. I managed to do the first part with a simple if statement but I didn’t know how to rev…
Tag: java
How I can turn on and off BlockHound check
I have some App with WebFlux and i want to use BlockHound, but i need to have a possible turn on and off it through parameter in application.properties or through spring profiling or somthing else. Also I want to override action, when the lock operation is caught so that not throw error but log warning. And f…
How to match equals() and hashCode in streams?
I have a stream where I am aggregating some data like this: The problem is that by adding this comparator I am braking the contract between hashCode() and equals() and at the end I have duplicate keys: Has anyone some ideas how can I fix this? Or is there a way to sort the final object ( Map<String, Map<…
Mapstruct how to initialize fields
I have a DTO like this and an entity I want to create a mapper to map DTO to entity. How can I make the field private Instant timestamp; has value like Instant.now()? My mapper so far It got compile error Answer The issue is due to the source being empty. Remove the source and use expression instead of defaul…
Why is Java Sound API frame position getting stuck?
I’m trying to create a sound recorder using Java Sound API on Kotlin Desktop. I want to automatically stop the recording after 3 seconds. The frame position does initially advance but then gets stuck. This is output of the print statement: What is causing this and is there a way to fix it? Answer The pr…
Create Trigger to update the record that was newly inserted on PostgreSQL
I want the trigger to fire when a new record is inserted, and update that newly inserted record to add a current date and time, need help please be kind still new here 🙁 here’s my code: FUNCTION: TRIGGER: Answer Your WHERE condition is needlessly complicated (and slow) as you could replace it with where…
How to display hashed MD5 value as text displayed in H2?
The H2 HASH function returns bytes, and SELECT HASH(‘MD5’, ‘test’) AS new_id FROM my_table; displays a text value: 098f6bcd4621d373cade4e832627b4f6 How to retrieve that same text value in Java? Using ResultSet.getBytes(“new_id”) gives the object’s address, something l…
Java ProxySelector undefined behaviour
I am experimenting with Proxies in java networking. I have read the documentation regarding them and am currently testing ProxySelector. I notice 2 types of behaviour of this ProxySelector when using with HttpURLConnection & when using with Socket class When using with HttpUrlConnection with this code I g…
create a custom log4j2 rolling file appender
I want to create a custom log4j2 rolling file appender. I need to create this custom appender because I want to wrap the file name with current thread name. We are trying to migrate log4j 1.x to recent log4j2 version and previously we had used DailyRollingFileAppender to log all activities of our application.…
Passing generic types inner class
Here is following example: Is there a way just to pass the generic <String> one time? Actually the inner class should already know its type. Answer That is a limitation of the Java compiler. Although it looks obvious in this case that the type parameter must be String, inferring that is not as easy as i…