Win a copy of Programmers Guide to Apache Thrift this week in the Open Source forum!

Marimuthu Madasamy

Ranch Hand
+ Follow
since Jun 07, 2007
Marimuthu likes ...
Java Monad Scala
Software Developer. Programming Languages Enthusiast. Scala/Haskell fanatic.
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Marimuthu Madasamy

Though Mathematical skills would help in programming, the above code is straightforward, taking the brute force approach. Further I also have been learning Haskell for one month and really love the language. Learning Haskell would definitely improve your programming skills and your way of thinking in programming.
Taking the brute force approach and to have some fun with Haskell:

which returned [(8,12,16),(8,16,12),(12,16,8)]
To add, With 'def' you are creating a method which means you cannot pass it around as first class value whereas 'val's containing functions are first class values so you can pass it around.

Thats why you are getting the following error since the method is not passed enough arguments hence it is not a method call and also it cannot be assigned to the REPL generated variable since it is not a first class value:

If we follow this method with '_', a function is created which can be passed around/assigned to a variable.
8 years ago
If you are using Scala swing's 'TextField', you can use 'text' method on the TextField to get the text.
8 years ago
A supertype reference can reference subclass objects. Through that reference, you can call all the public methods of supertype and you will be invoking the implementations of subclass if the methods are overridden by subclass.
With the above facts, if you are allowed to restrict the access of overridden methods, the compiler in no way can make sure that the overridden method will be invoked using supertype reference.

For example:

Here how can the compiler differentiate between case 1 that is broken and case 2 that is not? what if the process() method is in a library jar and you are not sure what are all the methods that will be invoked on the passed instance? In essence, it would break polymorphism.
8 years ago
Using Regex, you need a pattern with three constructs,
1) A matching opening parenthesis
2) Match any character until it matches a closing parenthesis
3) A matching closing parenthesis

To get you start with:
1) To match a character, you just need to have that character in the pattern string. Watch out for meta characters which need to be escaped.
2) To match any character, the meta character '.' (dot) is used.
3) To match a character zero or more times, the meta character '*' (asterisk) is used
4) To extract a subset of data from the regex, you can use something called 'groups'. In your case, the parenthesis' are used to just match and you are interested in the data in between them; so you can capture the data as a group.

8 years ago
You can use wildcard with bound:

8 years ago
The solution which I posted above would just fit. If you have five classes to process an object of class A, lets say, MyClass1, MyClass2, MyClass3, MyClass4, MyClass5. With reference to my above solution, when you create 'Function's, inside apply() method you need to create an instance of one of those classes and forward to a method on those class.

When you read rules from your properties file, you need to put appropriate 'Function's to a map as in the above solution. Since we have composed appropriate instances of one of the above classes inside 'Function1' instances, the function instances will forward to the method on the required class.

If all your classes share a common interface to process Class A objects, you don't need to wrap it in another interface like 'Function1'; you can just create a map on that interface to define rules.
8 years ago
If you parse a date(with time) string with format "yyyy-MM-dd", you will get the date object without time details. So in your code, you might be trying the format "yyyy-MM-dd" before "yyyy-MM-dd hh:mm:ss" so the date gets parsed with the first format without time details and the time gets defaulted to 00:00:00.
8 years ago
Right Rob Prime. The pseudo code should do. Just provided the code for reference.
8 years ago
One solution would be to represent those processes as functions/commands and composing them in a collection and pass it around.

8 years ago
You can generate combinations selecting one from each list with a recursive approach (Excluding your first condition; I don't know how you can get a list of 5 elements from 4 lists without duplicates).

create a method that accepts a list of lists and returns the combinations as list of lists.
For example, {{1, 2}, {3, 4, 5}} to {{1, 3}, {1, 4}, {1, 5}, {2, 3}, {2,4}, {2,5}}

Algorithm with pseudo code

Turning this into Java statements is straightforward.
Here is the code (Hope you would try your own and would require this only to compare with your solution )

8 years ago
@swapnil nawale: Just for your information: within REPL, you can load and interpret a scala file with ':load' option:

8 years ago
In your main() method, you have just created an object of your class. The behavior you want is in a method which is not called. So you need to call your method.
8 years ago
You can avoid paranthesis using this calling notation:

This is also quiet not looking natural. We can improve this further:

Adding another method in class Temperature:

with this method in 'Temperature' class, we can call like this:

- Marimuthu Madasamy
8 years ago