Leandro Coutinho

Ranch Hand
+ Follow
since Mar 04, 2009
Merit badge: grant badges
Biography
In most cases, programmer time is much more valuable than computer time. Joshua Bloch
For More
Brazil
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
3
Received in last 30 days
0
Total given
20
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Leandro Coutinho

Paul Clapham wrote: And if I understand it correctly, the tutorial which you linked to does include that interface implementation:



Thanks Paul.

I tried something similar but got the same error: "not a subtype":



I will later investigate it further but I already did a small test and SPI works for concrete classes too, eg:


3 years ago
static method provider works.
There is a nice example here:
https://www.logicbig.com/tutorials/core-java-tutorial/modules/service-provider-method.html

Also from the java docs:

If the service provider declares a provider method, then the service loader invokes that method to obtain an instance of the service provider. A provider method is a public static method named "provider" with no formal parameters and a return type that is assignable to the service's interface or class.
In this case, the service provider itself need not be assignable to the service's interface or class.



So there's something wrong in my code ...
3 years ago
Hi =)

I converted the repo below to use maven:
https://github.com/java9-modularity/java9-vertx

The project has one provider that does NOT implement or extends anything.
It's like this:



And he uses it like this:

But then I get the error:

Exception in thread "main" java.util.ServiceConfigurationError: javamodularity.easytext.pagefetch.WikipediaFetcher: Provider javamodularity.easytext.pagefetch.impl.WikipediaFetchImpl could not be instantiated
       at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:581)
       at java.base/java.util.ServiceLoader$ProviderImpl.newInstance(ServiceLoader.java:803)
       at java.base/java.util.ServiceLoader$ProviderImpl.get(ServiceLoader.java:721)
       at java.base/java.util.ServiceLoader$3.next(ServiceLoader.java:1394)
       at java.base/java.util.ServiceLoader.findFirst(ServiceLoader.java:1809)
       at javamodularity.easytext.web.Main.main(Main.java:16)
Caused by: java.util.ServiceConfigurationError: io.vertx.reactivex.core.Vertx: javamodularity.easytext.vertx.VertxProvider not a subtype
       at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:588)
       at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNextService(ServiceLoader.java:1236)
       at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNext(ServiceLoader.java:1264)
       at java.base/java.util.ServiceLoader$2.hasNext(ServiceLoader.java:1299)
       at java.base/java.util.ServiceLoader$3.hasNext(ServiceLoader.java:1384)
       at java.base/java.util.ServiceLoader.findFirst(ServiceLoader.java:1808)
       at javamodularity.easytext.pagefetch.impl.WikipediaFetchImpl.<init>(WikipediaFetchImpl.java:16)
       at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
       at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
       at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
       at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
       at java.base/java.util.ServiceLoader$ProviderImpl.newInstance(ServiceLoader.java:779)
       ... 4 more

Does this pattern really work? Or Service Provider Interfaces (SPI) only work if we implement some interface?

I also found a little strange that the author did that, because io.vertx.reactivex.core.Vertx is a concrete class.
But I understand that he wanted to only have one instance of that class in the application.
3 years ago

Ryan McGuire wrote:I know you said you get it now but I'll answer anyhow:

Leandro Coutinho wrote:Thanks a lot Ryan!
1)
Why
if ((A[i] >> bit & 1) != (A[j] >> bit & 1)) {
and not:
if (A[i] >> bit != A[j] >> bit) {
?
I tested and it gave the same result for all examples.



No it doesn't. If A[i] = 3, A[j] = 1, and bit = 0, then A[i]>>bit & 1 == A[j]>>bit & 1, but A[i]>>bit != A[j]>>bit.


Yes, it does. Because bit won't reach 0, it stops when bit = 1.

Ryan McGuire wrote:That guts of that if() figures out the value for that bit in B that would make C[i] < C[j] (with i < j). For instance, in the case above where A[i] = 01111 and A[j] = 01001 (with i < j), when bit=2, we would want to set bit 2 of B to a 1. That way, bit 2 of A[i] would get XORed from a 1 to a 0 and bit 2 of A[j] would get XORed from a 0 to a 1, which would make C[i] < C[j].


Got it.

In the first example:
{3, 2, ...}

i = 0, j = 2

They differ in bit 0, then ++profits[0][]
And to make the changes, the 0 bit of B must be 1, then ++profits[0][1]

Thanks a lot Ryan.
Thanks a lot Ryan!

Ryan McGuire wrote:The value for B is a number numBits bits long with each bit set to whichever value has a higher value in profits[bit][].


Really cool.

So "int bit = numBits - 1", to get the high order bit.
If "int bit = numBits" it would right shift all bits and the number would be zero.

When A[i] < A[j], then A[i] >> bit & 1 equals 0. So:
++profits[bit][A[i] >> bit & 1]; => ++profits[bit][0];
Interesting.

1)
Why
if ((A[i] >> bit & 1) != (A[j] >> bit & 1)) {
and not:
if (A[i] >> bit != A[j] >> bit) {
?
I tested and it gave the same result for all examples.

2)
In the example "0)", it says that only B=3 returns 8, but debugging it shows that B could also be =2:
profits[0][0] = 1
profits[0][1] = 4
profits[1][0] = 4
profits[1][1] = 4

right?


3)
It's still not clear to me where the xor happens (if it happens).
And I don't understand how he came up with this idea of finding B and the number of pairs and why it works. I'll think more hard here and work through the examples to find out.

Thanks again.
Hi,

I read the problem's solution but couldn't understand it. So could someone here explain for me how the code works, please?

Problem: http://community.topcoder.com/stat?c=problem_statement&pm=13657&rd=16313
Solution:
http://apps.topcoder.com/wiki/display/tc/SRM+649



I understand the syntax, but not the logic behind this.

Thanks a lot!!
Hi,

The place on our profile that shows the likes that we gave and that we received could have a link for those posts.

Thank you.

[cowpoll]
9 years ago

George Mournos wrote:
So, in your example of the "order by" columns, if one does an IDOR attack and substitutes one "order by column" with another, he could order results in ways for which his has no access. This is not an attack (no impact)!!!



I think this can be used as an attack. For example if someone can only see a list of the last 10 suppliers, then order by some other thing like supplier owner or contract value. Probably a poor example, but I think there are some cases that this can be bad.
9 years ago
I got surprised with the result. I thought instances of the super classes were always created before the child classes, but, based on the result, it seems that it is not what happen.
It's more like the not private members of the super class are included inside the child class, and you can use "super" and "this" more like a namespace ...
Hi,

What are the main benefits that Java 7 brings for concurrence, threads, parallel programming?
What would be very hard or not possible to do with Java 6?

Thank you!


ps: Congratulations for the book. I seems to be pretty good. I'm reading the sample chapter, and I like it because there are real examples, real code and doing is a very good way to learn.
Problem SOLVED!!! YEAH! hehe

I had the AffableBeanPool in the JDBC Connections Pools, but didn't have jdbc/affablebean in JDBC Resources.
Glassfish Admin Console -> JDBC -> JDBC Resources -> New
12 years ago
JSF

Maurice Rogers wrote:I think the problem I was experiencing was due to a space in one of my configuration files.

Double check your xml config to make sure that the connection source is as it should be....


testDataSource.jsp


web.xml
12 years ago
JSF