Sangel Kapoor

Ranch Hand
+ Follow
since Jan 12, 2013
Sangel likes ...
Android Java
Cows and Likes
Cows
Total received
1
In last 30 days
0
Total given
0
Likes
Total received
8
Received in last 30 days
0
Total given
21
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Sangel Kapoor

Junilu Lacar wrote:So, if you only care about certain fields that you want to explicitly list out, why use reflection?  That's the smell. Using reflection to exclude specific fields makes sense because you won't have to change the code if that exclusion list doesn't change but the objects are modified to include more fields that should be checked. In your case, it doesn't make sense to use reflection because you want to list fields to include.  If that list changes, you'll still have to change the code. You gain nothing by using reflection. Since reflection is costly, you're paying for a service that is of no practical use to you in the context of the problem you're trying to solve. That's like paying for premium cable channels that you don't ever watch.  So what's the point?



Got your Point, thanks a bunch ! and I think for the same reason they don't have include fields in api but exclude fields only.
4 years ago
So intent is to check whether transformation of one Pojo to another pojo is done correctly. Essentially I am testing static transformer method which converts one pojo to another.
4 years ago
Task : I am  converting external request to Service to Internal Command.  So essentially I need to test the quality of two POJOs  and I need to test the quality for few fields only.

I agree I can write getters but they are many.

There is another option to use Matchers SamePropertyValueAs , but it does not provide any fields to include or exclude. This was the motivation to switch to ReflectionEquals.
4 years ago
I am testing two Pojos as follows



but what I am trying to find is not to mention fields that I want to exclude but fields which I want to include. Is there any way ??

4 years ago
I was asked question in Interview as follows

How would you avoid/prevent when DB(say ORACLE) is down?

I don't know how to answer this question and what precisely she wanted to listen to an Answer.


I just said using multiple nodes/ distributed database will ensure availability. He seems not so happy with the answer. I cannot think beyond Replication of DB and Redundancy as Solution.

Suggestions.
We have thew following requirement.

Use Case : Given one request say R that can be answered by one of the various classes of same type say S. We need to stop and reply back once we got answer from any of the S.

Query :  How should we model this ?





5 years ago
GIVEN :  I am working on Story and I  have already made some local commits. and I cannot push since CRs take long time to review.

NOW : My Manager want me to work on different small story and push it asap.

What I need :  I want to save these local commits somewhere and work for new story to fix issue and push it.
                      After pushing I want my local commits to come back so that I continue my work on original story .

       I want to know your preferred way of doing this ?

Jesper de Jong wrote:What Tushar posted probably works, but it looks more complicated than necessary. The Spring ApplicationContext has a method to do exactly what you want: getBeansWithAnnotation.

It returns a Map in which the keys are bean names and the values are bean instances.

For example:



Thanks a bunch, I have a follow up question , We also have CommandHandlers which handles particular Command.
I would like to annotate method in class as follows



There is another class Router which will route Command to its handler and invoke handle method.

Class Router is as follows


}


I want Spring to populate above map automatically when Spring Context is loaded. How to achieve this , given now I know how to find classes with @Command Annotations.

5 years ago

Stephan van Hulst wrote:If your external type follows the JavaBeans conventions, you can use an existing Hamcrest matcher. Sadly, the matcher is type-safe, so it's easiest to wrap it in a method call that takes all kinds of objects:

You then call it like this:



This is not working for me , error :  incompatible type. I think Matcher<Object> and type of internal are different thats why it is coming. Any suggestions ?
5 years ago
I stumble upon @Immutable annotation in javax package. I would like to know what it is actually doing to the class ??
5 years ago
How to Scan Beans with particular Annotation. For instance I would like to know all the beans  with @Command Annotation on them.
5 years ago
Use Case :  I am converting external model for service to internal domain model.  Let say External model name is E and Internal Domain model name is I.

Query  : Now I am want to test the I model is successfully build from E in Unit test.  For that I need to assert for all the fields in I and E respectively as follows




Is there any Library or built in api that can solve this to one line ?
5 years ago

[To give a concrete example of that generation gap issue, let's say you call addRelationship(joe, grandson, peter). First of all, it's not very clear how to read this: is Joe the grandfather or grandson? Before you answer that, again that's the point. Somebody needs to tell you or you have to go look at the documentation and if there is none, you have to dig through the source code. This design makes the API ambiguous and unintuitive. This could be read as either "Joe is the grandson of Peter" or "Joe's grandson is Peter."

So, with just that one call you have created a generation gap because no intermediate relationship has been defined. Where is the grandparent's child who is the parent of the grandchild? That is, if Joe is the grandfather, then where is Joe's child who is Peter's parent?



1. addRelationship(joe, grandson, peter). If it is creating confusion then Math.pow(a,b) is also a confusion but it is still there in JAVA API . Of-course you need to read documentation to use any API or you should use microtypes to avoid it as much as possible. What about Account.transfer(Account acc1, Account acc2), same problem.

You can add another parameter called Direction which I thought of but I thought its not required as of now. We can change this to addRelationshipFor() or can use Microtypes as Parameters to resolve this further though. For instance
addRelationship(Source person, Relationship, Target person). I think that is more of clean-coding issue rather than API signature issue.

2. Secondly whatever you said about Relationship classes in my code is not correct , seems like you have not read my long post with code before, where I mentioned that I have just used basic relationships in my Code which are direct and are immediate meaning if you draw out any family tree on paper then all the direct links of any node are represented as Relationship classes in my code. As of now these are , FATHER, MOTHER, SPOUSE , SIBLING.

Grandson and Grandfather were intentionally added as an exception to my code to make things fast but those are removed now as well. We are inferring all the second neighbors and neighbors of neighbors in GRAPH by moving from familyTree of one person to another person family tree and so on....

5 years ago
I doubt how I am different from Winston approach and you are liking his design but not mine :-D


Just posting this to try to articulate the picture I have in my head.

I'm looking at the Tree concept somewhat like an Iterator, as an abstraction and a "lens" to an underlying set of data. It's from the idea that Campbell gave about a Person having two trees, one for parents, another one for offspring. That's where the idea of using two different "lenses" came where I could go to a Person and ask him for a Tree view where that person has a child role or for others where they are have the parent role, or at least are part of a couple that makes up a Parent node. The Tree would then allow me to access the Parent and Child nodes directly and I can recurse from there. That's why the Role enum, if I found that it was really necessary, would have only Parent, Child, and possibly Sibling but probably not, as its values.

From a Parent or Child node, I can traverse the underlying collection by moving between Child and Parent nodes and invoking a relatively small API (getParentTree(), getChildTree(), getChildren(), getParent(), hasMother(), hasFather(), hasChild()) on the Tree/Node interface. Visitor pattern and the Strategy pattern are already vaguely creeping into the design picture at this point.

As I move from one person to another asking for one Tree view or another, I am able to move from person to person, child to parent and vice versa. This can all be done recursively or iteratively if you don't like recursion. The notion of the Akka-esque Root parent node comes in very handy in stopping the recursive or iterative traversal and of course when a Parent node (representing a couple) has no Child nodes, the recursion stops with the childless couple as well.

Now where Dave's Event idea comes in is that once the biological connections have been made, you can layer on the event-related connections. Say Bill and Sue adopted a child named Jim. Jim gets added to a Child of the "Bill & Sue" Parent node with an "adoption event" marker. Bill cheats on Sue and has a child with Mary so now Bill and Mary become a couple in Parent node with a Child node that represents their love child, Connie.

With the combination of Couple/Parent/Child connections and Event markers, I think I can come up with something that reflects what happens when the guy in the song becomes his own grandpa.




Am I not doing exactly the same except , I am keeping SPOUSE as extra relationship . You are talking about keeping it in small trees and I am keeping it in HashMap.
Not a big deal and in fact I feel it is easy and natural to represent SPOUSE in HashMap than keeping one node for couple which is not natural because , some nodes in
your tree are singular and some are plural, no consistency. Also if you put new developer on your code, it will take a while to understand that you are representing one node for couple and that is why I insist on NATURAL design.

I can throw away my design any time, it is not a big deal, its my attempt and not life thesis. But at least I should feel how your design is making a difference.

Only difference I have seen so far is with that "Event design" thing. That model might be helpful if it is easy to find particular event associated with person.

Do you have any concrete case where I wont be able to add easily or extend my design but yours. We differ only inside FamilyTreeADT .


NOTE : I am not defending my design . I am just discussing because I am not yet impressed !

Since this discussion is going in all directions with hypothetical theories , why not you code your concrete classes and show the World !! I would love to see your Person class and FamilyTreeADT .


5 years ago