Deepak Bajoria

Ranch Hand
+ Follow
since Mar 07, 2008
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
1
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Deepak Bajoria

Divyanand Kutagulla wrote:


Hi Deepak,

Thank you for your reply.

In my code I do create a comparator

I wanted to use Collections.sort method to accomplish the sorting And I wanted to be memory efficient
Yes creating a TreeMap would help was it is sorted map. but it would take additional memory, I already have a map - granted it is not sorted, but I can use the Collections.sort to sort it with the right comparator.

Divyanand


If really care about memory, and you do not worry about the possibility of original map being updated after Collection.sort has been performed, then what you have done looks most reasonable to me. Of course, you can use ArrayList instead of LinkedList which might have better performance, although I am not sure about it.
4 years ago

Winston Gutkowski wrote:
Really? You're creating a TreeMap, which is a binary tree structure. Since your Comparator is actually only concerned with what was in the original Map, and is going to order those keys according to their associated values, I could definitely see problems if the original Map is subsequently updated; not to mention the idea of ordering something (your String keys) by something they're not even directly associated with, AND which might be duplicated [Edit: thinking about it; that may actually be the showstopper].

It might work as you've written it (ie, with no "equal" value), and like I say, it's an interesting idea; but I'm not sure I'd want to do any predictive analysis on it.

Winston


Thanks Winston, I see what you mean. What I am trying to do is to figure out how the ArrayList or the ReverseMap approach that you suggested is going to solve the problem of additional element being added to the original map after sort is performed.
4 years ago

Winston Gutkowski wrote:
1. Your compare() method doesn't check when values are equal and return 0. This might be deliberate in order to retain ALL the original key mappings, but I suspect it's flawed.


This is of-course a sample implementation of compare method which can be easily modified as per the exact use case. This was never the concern here.

Winston Gutkowski wrote:
2. What would you expect sortedRepresentation.get("X") to return (assuming "X" is a valid key)? I suspect you'll get null more often than you think; but I have to admit, I'm not absolutely sure.


This comparator is designed to sort only the map which was passed to it while invoking the constructor, in which case sortedRepresentation.get("X") is never going to give null.
4 years ago
What you are doing here is creating a separate LinkedList of EntrySet and sorting it according to Values. While this seems OK, but in case you want to have a map sorted according to values, this is what you can do.

Create a comparator


Now create a TreeMap to use this comparator:


This would be slightly cleaner way of doing the thing.
4 years ago
i m sorry, i wanted to post this in scwcd section, can this be moved please
Hi friends,

I may sound a bit silly, but if you could provide complete details of the SCWCD book in India as i am having a bit difficulty in finding it in the book stores.

Please let me know publisher of Indian version, name of all the writers and appx price in INR.

thanks in advance
Hello ranchers,

I am a final year student of under-graduation degree in computer application stream. About 6 months ago java was almost a new word for me.(I had studied C/C++ for my university exams). It was then I decided to go for some specialization. I picked up K&B and studied it gradually taking time out from my university studies, I took various mocks, and today I am a Sun Certified Java Programmer.

There was one thing which took my by surprise is that the time I got was 210 mins whereas suns website still mentions available time as 175 mins. check out http://www.sun.com/training/catalog/courses/CX-310-055.xml

In any case I completed the exam with revisions with 1 HR left. I just passed the full time by re-revising all the answers.

I thank the community here on javaranch. Various online resources helped me enhance my knowledge, this site in particular.

Regards,
Deepak.
10 years ago
Constructors in abstract classes get executed when their subclasses are instantiated. As you know there is has to be a call to super() in subclass' constructors.
OK, thank you Jamie and Milan for your explanations, got that.
Hello,

Is it true that any protected static member of a class works exactly the same way as a public static.

Thanks,
Hello ranchers,

Here this code:


Outputs:
Mammal eats food

My first question is: Is eat() being overridden or overloaded? Arguments in subclasses are subclasses of those argument defined in superclasses.

I understand that c.eat(h) attaches it to mammal's version at compile time because of reference variable, but at runtime doesn't it know that the object held is of type horse. Since class Cattle doen't have eat(horse), it should have invoked eat(cattle).

Thanks in advance

Deepak
Yes the only thing i am getting is:

Gettin' yer Horse ready... hang on
just wondering, why john meyers changed his name....or perhaps this is his real name