Quantcast
Channel: User M. Prokhorov - Stack Overflow
Browsing latest articles
Browse All 43 View Live

Comment by M. Prokhorov on Mocking object in set

It seems like you don't mock the new B() and instead you create an actual instance of it. Would I be correct in this observation? If I am correct, then it's no surprising it doesn't behave exactly...

View Article



Comment by M. Prokhorov on Removing a hard Enter from a String

\r\n is not the only possible variant. It could be just one \n char in there. But also - if you aren't getting the correct output - what DO you get?

View Article

Comment by M. Prokhorov on Change xjc generated Java field name from 'value'...

Does this answer your question? XSD: Specifying a name for a text node property

View Article

Comment by M. Prokhorov on How to generalize a comparison in Java code

I would argue that naming things may still be helpful in reading the code later. Perhaps, defining interface Filter extends Predicate<Earthquake> is the best of both worlds.

View Article

Comment by M. Prokhorov on Flux.zip with repeated empty Mono leads to endless...

From my understanding or the doc, Repeat operation wraps the original Mono to do onSubscribe as soon as the original Mono does its onComplete. The Empty mono only ever calls onComplete. So what you get...

View Article


Comment by M. Prokhorov on Which of the several sessions waiting to acquire...

@Baalback, so in other words, there is a linked list of waiters to notify. Because my two new sessions start concurrently, it's undefined which one of them will get the lock next, but any other session...

View Article

Comment by M. Prokhorov on Unzip specific file from inputstream into another...

You can't put files into an Outputstream, that's a misnomer. InputStream represents the contents of the file, not the file itself. If you want to have a particular output file in the end, that is not...

View Article

Comment by M. Prokhorov on Which of the several sessions waiting to acquire...

By "queue", do we mean a list of strict ordering, where there can only be one "next", which is chosen at the time of adding to the queue? I'm asking because some programming platforms have unordered...

View Article


Comment by M. Prokhorov on How to close HttpClient? Why there is no .close()...

HttpResponse.BodySubscriber talks about closing underlying connections, but there doesn't seem to be any way of explicitly doing so for now, as stated with the Holger's answer.

View Article


Comment by M. Prokhorov on Hibernate Constraint Primary Key

The main property of any primary table key is its uniqueness within the owning table. Your expressed intent with "having two rows with the same primary key" contradicts this property, so you can't do...

View Article

Comment by M. Prokhorov on Can i put not null constraint to FK?

We can't really design your system for you, because we don't know full spec of it. What is the specific perceived problem you are trying to solve? Why not indeed simply make it a non-null FK?

View Article

Comment by M. Prokhorov on Java stream an array list and compare with...

You are not avoiding loops by using streams - you just move the loop into the streams library. It's still going to be there, just not as visible and harder to debug.

View Article

Comment by M. Prokhorov on intellij-internal error-buil error in java

Did you read what the error says? Did you do what is suggested by the error message?

View Article


Comment by M. Prokhorov on How can I interpret this error? Required type:...

The error message you got refers to java's type system. As stated in the answer below, the compiler expects you to pass a Supplier<R> into the method. You passed Collector<T, A, List>, and...

View Article

Answer by M. Prokhorov for How can I change the stream my event uses via the...

Live broadcast is associated with a stream using a liveBroadcasts/bind method.In terms of Java API it would look something like this:YouTube yt = ... // your reference to YouTubeString broadcastId =...

View Article


Answer by M. Prokhorov for Thymeleaf - Unquoting a part of inline JavaScript...

[[...]] notation is used for escaped inlining: it converts everything inside into a well-formed Javascript string.Since you also want to call something, you need un-inlined version, using [(...)]...

View Article

Answer by M. Prokhorov for What's the point of @Before and @BeforeClass?

@BeforeClass method runs whenever a static initializer block runsThe important caveat here is that this statement is wrong. Static initializer block runs when the class is loaded, which is not...

View Article


Answer by M. Prokhorov for java.lang.IllegalArgumentException: fromIndex(x) >...

This exception happens because when computing start of your slice you don't take into consideration how many objects are there in full list of candidates.If I request from your method a page 1 of size...

View Article

Answer by M. Prokhorov for Chain optionals with void return type

I'm just going to start by saying: cleanest solution would require a better abstraction than Optional provides, because it's main purpose is to represent a missing value, not validation output.However,...

View Article

Answer by M. Prokhorov for Can't find the right screen dimension

You are querying an application area size, which might not take up the entire screen size. From Display class docs:The application display area specifies the part of the display that may contain an...

View Article

Answer by M. Prokhorov for java.time: Compare two Instants - get the number...

Something like this should work:ZoneId zone = ZoneId.systemDefault();ZonedDateTime ago = ZonedDateTime.ofInstant(Instant.ofEpochSeconds(unixSeconds), zone);ZonedDateTime now =...

View Article


Answer by M. Prokhorov for How to bring generics into a java stream

The legacy shouldn't really affect your other code that much. So I think there's no need for an extra step in stream pipeline or anything like that - just cast the list:long containA =...

View Article


Answer by M. Prokhorov for Passing argument to enum abstract method

Since Java 8, java.util.Comparator<T> has a default method reversed() that you can use.You can make your enum implement Comparator, then you get reverse sort "for free", but that means changing...

View Article

Answer by M. Prokhorov for Is it possible to access instance of exception...

There is a less specialized version of expect method in that rule, that accepts a Hamcrest's matcher:expect(Matcher)This method would allow you to assert almost anything about the thrown exception,...

View Article

Answer by M. Prokhorov for Java beginner exercise with methods

The reason compiler gives you "no return statement" error is because you didn't cover all possible cases with your ifs: there is Double.NaN, which is not equal to 0 (or any other value, for that...

View Article


Answer by M. Prokhorov for JUnit FindById returns null pointer (Mockito)

Your init() method is tagged with org.junit.Before annotation, but the test overall is run using JUnit 5, which does not recognize the method to be invoked as part of setup procedure. Meaning...

View Article

Rollback for doubly nested transaction bypasses savepoint

It's not exactly as the title says, but close to. Consider these Spring beans:@Beanclass BeanA { @Transactional(propagation = Propagation.REQUIRED, rollbackFor = EvilException.class) public void...

View Article

Answer by M. Prokhorov for Get today midnight as milliseconds for given...

Formatting to string and then parsing from it is a horrible solution, especially since you also have to also construct all these parsers every time, and your format effectively has hacks in it.There...

View Article

Answer by M. Prokhorov for Enhanced 'switch' blocks are not supported at...

The part that isn't supported is this:case "first option", "second option", "third option":They are multivalue labels, and are indeed not supported prior to Java 14, where they became standard.What you...

View Article



Answer by M. Prokhorov for JOOQ SUM in Kotlin with custom types

I assume that problems you're experiencing is just due to Java's type system.If so, you can simply coerce the field to a different type for a query, like so (admittedly, muddying the query defining...

View Article

Answer by M. Prokhorov for Escape character in LIKE through Criteria api

In JPA, CriteriaBuilder's like method has several overloads which have a third parameter, that is the escape character. It can be either of types char or Expression<Character>.So, for your case,...

View Article

Answer by M. Prokhorov for how to remove from a list from a combo box

You can't have several else blocks for the same if. Each else block has to be attached to its own if:if(a) { ...} else { if (b) { ... } else { if (c) { ... } else { ... } }}Or, with a shorthand for all...

View Article

Answer by M. Prokhorov for the Cell.add(" Cell Content ") does not work in...

In iText, not all elements can accept just "simple" text - some elements are containers for other "Block" elements, whereas the Text is a Leaf element. Actual text is represented by objects of Text or...

View Article


Answer by M. Prokhorov for Why is null appearing in my output? - Java

This is the code right here:public void Histogram(int[] f) { String[] asterisk = new String[6]; System.out.println("Histogram: "); System.out.println(" "); for (int i = 0; i <= f.length - 1; i++) {...

View Article

Answer by M. Prokhorov for How to find all Instants which correspond to the...

For any given pair of LocalDateTime and ZoneId, there is only one Instant - because Instant is a moment in UTC offset, the +0:0.You're probably looking for conversion from LocalDateTime to...

View Article

Answer by M. Prokhorov for Limit the number of rows in a room database

Assuming:Your table is create table example_table ( ts timestamp, uid number(19), some_other_field varchar(64) );And you don't want to care about running some query manually.Use database triggers:...

View Article


Check what type of Temporal a given format string can be used to parse

I'm given some datetime format string that user entered, and need to check into what java.time temporals I can parse data in that format (within reason, I indend to support only the simpler cases for...

View Article


Answer by M. Prokhorov for Builder pattern with Reactor mono

As I said, in the comment, trying to convert Mono into something that is is not a reactive type kind of flies in the face of using reactive programming to begin with.According to reactive paradigm, you...

View Article

Answer by M. Prokhorov for Java Stream.map() on Subclasses with Wildcards Not...

Since Java 12, you can use a teeing collector and collect into a pair by using standard collector chains rather than your own function-based custom collector:import static...

View Article

Answer by M. Prokhorov for Java8 - Object Type - Dynamically add more property

If I understand it right, this is a case of constructed type having additional properties that should be populated from header. Then, there are several approaches here. First, the one I would prefer,...

View Article

Answer by M. Prokhorov for How do i import SerialBlob?

Blobs are representation of binary arrays (which may be files) that your database engine know about.This, typically, means that blobs are created by the driver, or added to the database's datafile...

View Article


Answer by M. Prokhorov for How to access parameter of Callable Future after...

According to Javadoc, every conforming ExecutorService will:@return a list of Futures representing the tasks, in the samesequential order as produced by the iterator for thegiven task list, each of...

View Article

Answer by M. Prokhorov for How to generalize a comparison in Java code

Seems to me, that the general part of your code is whether the comparison is INCLUSIVE or EXCLUSIVE, while the wrapper Filter is mostly for the property extraction.If I'm correct, then what about doing...

View Article

Browsing latest articles
Browse All 43 View Live




Latest Images