This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of Transfer Learning for Natural Language Processing (MEAP) and have Paul Azunre on-line!
See this thread for details.
Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!

Mohamed Farouk

Ranch Hand
+ Follow
since Jun 08, 2005
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
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Mohamed Farouk

Jeanne Boyarsky wrote:Try creating a method called printNumberLegs(). Implement in Animal, Dog and Special Animal. Then you can call that one method.



Hi Jeanne
Thanks for your reply
I think you misunderstood the issue, the problem is not with printing Legs I can very well do call noOfLegs() dont have to create printNumberLegs(),
the problem is with Special Animal, calling noOfHands, Without instance of I would not be able to print the following Systemout

if (animal instanceof SpecialAnimal) {
System.out.println("SpecialAnimal" + animal.noOfLegs() + " No of Hands" + ((SpecialAnimal) animal).noOfHands());
}


Regards
Mohamed




What will be the best design pattern to remove instanceof check and use polymorphism to the best ?
Hi thanks for trying

Perfect Answer: select * from order o where amount = (select max(amount) from order where date=o.date);

Thanks Sresh Rangi your spot on.!

Looks like a simple order by date,customer_id would work to me.


it will bring all the records we want only 4 out of 5 (4/1/2013 3 1 700 should not appear as it has 700 for 4/1/2013 which is less than 1000 for 4/1/2013

Thanks for trying
OK Sorry I apologize English is not my first language!

Let me put it like this in numbers

Order Table
date customer_id order_id amount
1/1/2013 1 1 1500
1/1/2013 2 2 1500
3/1/2013 1 1 1000
4/1/2013 3 1 700
4/1/2013 1 1 1000


What will be the SQL to to get the below answer
date customer_id order_id amount
1/1/2013 1 1 1500
1/1/2013 2 2 1500
3/1/2013 1 1 1000
4/1/2013 1 1 1000

Let me be clear i tried and I failed cant get it, lets see what you guys come up with!
Required SQL Group the orders according to date for with max amount for each date

Order Table
date customer_id order_id amount
1/1/2013 1 1 1500
1/1/2013 2 2 1500
3/1/2013 1 1 1000
4/1/2013 3 1 700 -- Will not be in the output of sql as the amount is less than 1000 which is from another record on the same date
4/1/2013 1 1 1000


Required result
date customer_id order_id amount
1/1/2013 1 1 1500
1/1/2013 2 2 1500
3/1/2013 1 1 1000
4/1/2013 1 1 1000

I tried: select date, customer_id, order_id, max(amount) group by date
returns:
date customer_id order_id amount
1/1/2013 1 1 1500
3/1/2013 1 1 1000
4/1/2013 1 1 1000

Missing for below order record for customer 2 with same amount 1500
1/1/2013 2 2 1500
Hello Friends
A bit of puzzle , taught it is a easy one, but struggling, SQL required for getting the max amount customer order grouped on date

Order Table
date customer_id order_id amount
1/1/2013 1 1 1500
1/1/2013 2 2 1500
3/1/2013 1 1 1000
4/1/2013 3 1 700 -- Will not be in the output of sql as the amount is less than 1000 which is from another record on the same date
4/1/2013 1 1 1000


Answer should be

date customer_id order_id amount
1/1/2013 1 1 1500
1/1/2013 2 2 1500
3/1/2013 1 1 1000
4/1/2013 1 1 1000




Author Implements Call back to avoid blocking when we use future to get a result.



So question is so if we use the Call back way of implementation without using future is there no way of getting the result?

Thanks

Then you have to have your findHighValue method keep a reference to the Future, and call get() on it to get the results:



Thanks very much for your reply

Call back has the result, Ok we have a reference to the Future and and how does future.get know the result from call back method ?

Thanks
parallel-processing-and-multi-core-utilization-with-java/ -

Parallel Processing

I am writing a low latency request to get the greates number of primitive array and trying to parallelize the serial operation as it will be called million times.

The author has explained using a loop load the following types:
1. Serial Service( Slowest(
2. ExecutorServiceTest - Parallel Attempt 1
3. CompletionExecutorServiceTest - Parallel Attempt 2
4. CallableExecutorServiceTest - Parallel Attempt 3
5. ForkJoinExecutorServiceTest - Parallel Attempt 4 (JDK7)


He has used a simple test where he creates the service and then performs a load on the task.
TEST --> TASK

My requirement is I need to create service which should manage a task
TEST --> Interface --> Implementation --> Task

For Type 4: Callable the result does not use futures but calls back the caller's callback to return the result from the task call method (has it has a reference to the caller)





My Implementation - Test , Interface , Implementaiton , Task(FindHighValueTask)
Now Question is:

In a case when my interface/implementaiton is calling the CallableTask instead of the test. how can I get the result in my implementation method as the results go the callback method



I assume the array to be sorted / selected from is actually passed into your method from some other method?
If so, what is to stop some other thread from modifying that array while you are working with it?



Thanks for your reply, So basically do i need to perform syncrhonization based on the passed parameter Is this good enough?

So if my interface is i:


Hello friends

MY interface is sorting of an int array and returning the first highest 5 values as array

If the method just does the arrays.sort and all sorting is done local to the method and there is no instance variable in the implementation(current) class?,

Do I need to worry about synchronization at all.

This method will be used by a computational engine so kindly let me your thoughts method please?

Thanks
Thanks both for your help

What I inferred and learnt here is
1. What is stable sort
2. According to my requirement stable sort will not make any difference
3. Arrays sort is faster than Collections.sort

Thanks for all your help
I will post my synchronization related question next
7 years ago

How much data do you have to sort? Is it mostly sorted already? Does it have to be a stable sort?



How much data do you have to sort? - 50 elements max,
Is it mostly sorted already? - no
Does it have to be a stable sort? Not sure what you mean by that.


All i want to find out is which is better (relative) way to sort given that a interface has int[]. Will it be less powerful to use some form of sorted list or set ?
7 years ago
Hello Friends

I have to design a interface method which accepts an primitive [] array and perform a sort and return back an primitive [] array for a LOW LATENCY(high performance) requirement and will be called by many threads at the same time. The interface can be modified If i can justify that a different option (Se instead of int[])is better for performance.

Question:

1. I am not sure whether it is better to use (for sorting) [b]primitive array or some kind of LinkedList or TreeSet?[/b] If primitive array if so What is the reason to use primitive array instead of tree set?

2. If the method is read only (all sorting is done local to the method) and there is no instance variable in the class?, Do I need to worry about synchronisation?

3. What is the best method to sort ? Arrays.sort?, Collections.sort or anything else (Quick Sort?) which will render efficient sorting in Java 6 or Java 7 given this low latency requirement and maximum efficiency
Any response is greatly appreciated
Regards

Mohamed
7 years ago