Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!

trupti nigam

Ranch Hand
+ Follow
since Jun 21, 2001
Cows and Likes
Cows
Total received
1
In last 30 days
0
Total given
0
Likes
Total received
1
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 trupti nigam

I have an array of objects that needs to be filtered. The object structure is like below:


and the array will have 50/60 of such objects in the array like below.

I need to have something like this in order to display it on GUI. Separate out array based on their group name. Since Group names are going to be unique but each group can have multiple choices under it.

So I want to create multiple HashMaps that has key as the Group name and Value as the Name.

how can I achieve this using array functions or I need to have a separate logic to create a hashmap?

thanks,

trupti nigam wrote:The numbers will come as string like "1-2-20-21" or, 1-2-3-4" or "20-13-14-16-19"

For these I came up with:
Pattern onlyNumbers = Pattern.compile("(([1-9]|[1][0-9]|[2][0-1]\\-)++)");

But it does not work.



it worked with below expression.

Pattern onlyNumbers = Pattern.compile("([1-9]|[1][0-9]|[2][0-1])(\\-([1-9]|[1][0-9]|[2][0-1]))+");
3 years ago
The numbers will come as string like "1-2-20-21" or, 1-2-3-4" or "20-13-14-16-19"

For these I came up with:
Pattern onlyNumbers = Pattern.compile("(([1-9]|[1][0-9]|[2][0-1]\\-)++)");

But it does not work.
3 years ago

Carey Brown wrote:

Carey Brown wrote:"[ACFILORU](-[ACFILORU])*"



And for numbers I am using below.



Is that correct? Having "-" twice in the pattern won't confuse it right?
3 years ago

Henry Wong wrote:

trupti nigam wrote:
ignore my previous posts.

Valid: "A-C-F-O-R-U", "U-O-A", "O-R-C-A-A"

invalid: "ACFOR", "ACF-ORU","AC-OR-FU"



My previous regular expression, when using matches(), will work for this requirement.

Henry



Which one is that?  The below?
3 years ago

Liutauras Vilda wrote:

trupti nigam wrote:Valid: "A-C-F-O-R-U", "U-O-A", "O-R-C-A-A"

invalid: "ACFOR", "ACF-ORU","AC-OR-FU"


Is it safe to say, that between every two characters must be a dash?

Well, not between every characters. It can't be:
A---B



you are right A---B is invalid. A-C is valid. The sequence of the letters does not matter as long as they are from the given list and each separated by single "-"
3 years ago

Liutauras Vilda wrote:

trupti nigam wrote:Valid: "A-C-F-O-R-U", "U-O-A", "O-R-C-A-A"

invalid: "ACFOR", "ACF-ORU","AC-OR-FU"


Is it safe to say, that between every two characters must be a dash?




that is correct. The allowed letters are "A", "C", "F", "I", "L", "O", "R", "U". they shall be separated with "-".

thanks
Pradnya
3 years ago

Carey Brown wrote:

trupti nigam wrote:The patten can have any of the letters (single) separated by "-" which means "ACF-ORU" is invalid so is "ACFOR". but "A-C-F-O-R-U" is valid.

Not sure about your use of "BUT" here.

You may want to try
"[ACFILORU]+(-[ACFILORU]+)*"



ignore my previous posts.

Valid: "A-C-F-O-R-U", "U-O-A", "O-R-C-A-A"

invalid: "ACFOR", "ACF-ORU","AC-OR-FU"

3 years ago

Henry Wong wrote:

trupti nigam wrote:
So "AF-RU-RE" is valid pattern, so is "OUIF-AC"



Disregard my last post, as that post assumes only single characters (separated by dash) are valid. You need to clarify to specify which character combinations are valid -- and in much more detail than one example.

Henry



Ok here is what I understood after talking to Sys analysts.

The patten can have any of the letters (single) separated by "-" which means "ACF-ORU" is invalid so is "ACFOR". but "A-C-F-O-R-U"  is valid. Same is true with numbers.

thanks
trupti
3 years ago

Henry Wong wrote:

trupti nigam wrote:Hope this clarifies.



Actually no. Regular expressions are very particular. You need detail examples that matches. You also need detail examples that don't match. Otherwise, you won't get to cover all the edge conditions.... However, I am in a good mood, so I can give it a shot...

trupti nigam wrote:I need to match any letters "A", "C", "F", "I", "L", "O", "R", "U" and a "-" in between. "-" can not be in the beginning and at the end letters through.



To match a single case of one of those letters, the pattern is ... "[ACFILORU]".

To match two cases of one of those letters, separated by a dash, the pattern is ... "[ACFILORU]-[ACFILORU]".

To make the second case optional, so that it can match either one or two letters, the pattern is ... "[ACFILORU](-[ACFILORU])?".

And finally, to make two or more optional cases, so that it can match either one or more letters, the pattern is ... "[ACFILORU](-[ACFILORU])*".

I will let you figure out the other pattern yourself.

Hope this helps,
Henry



Thanks,
I tried to run my unit test and I see different output when I use matcher.matches() Vs matcher.find(). What is the right method to use here?

Matcher.matches() returns false when the pattern matches but find() returns true. I am confused with these two now.

thanks
3 years ago

Jeanne Boyarsky wrote:[ACFILORU*-] Matches only one character which isn't what you want.

[ACFILORU-]* Matches zero or more of these characters.

But you have rules for the first and last characters too. Can you fill in the blanks:




For First and last character I am not using any regex pattern.
I use something like below.


Before checking the actual pattern.
3 years ago

trupti nigam wrote:I need to match any letters "A", "C", "F", "I", "L", "O", "R", "U" and a "-" in between. "-" can not be in the beginning and at the end letters through.

The other pattern to match is any nos between 1-21 and separted by "-". Again "-" can not be in the beginning and at the end letters through.


Hope this clarifies.

Thanks you!




So "AF-RU-RE" is valid pattern, so is "OUIF-AC"

Similarly "12345-678" is valid pattern so is "202122".
3 years ago
I need to match any letters "A", "C", "F", "I", "L", "O", "R", "U" and a "-" in between. "-" can not be in the beginning and at the end letters through.

The other pattern to match is any nos between 1-21 and separted by "-". Again "-" can not be in the beginning and at the end letters through.


Hope this clarifies.

Thanks you!
3 years ago
I am trying to build a regular expression where in the incoming string can have any letters ("A", "C", "F", "I", "L", "O", "R", "U". Where more than one value is reported, they shall be separated with a dash "-") .
And the other pattern can have "1", "2," ..., "21". Where more than one value is reported, they shall be separated with a dash "-"

I thought I can use these simple pattern but seems it's not working. I have gone through the tutorials.




But it seems the pattern is not working.if i give input as "AC-FU" I expect I should not get any exception but I do get it.
Can someone tell me what am I missing?

thanks
Trupti
3 years ago
Hello All,

I want to understand how to define a bean of type below in spring config file. This is Auto wired.

@Autowired
@Qualifier("tvrrmImportQueueProcessor")
private Map<String, DefaultMessageListenerContainer> tvrrmQueueProcessors;

But when I try to run my application I get below error:

Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private java.util.Map com.theice.tradevault.tradecollector.config.TvrrmImportAppJmxConfiguration.tvrrmImportQueueProcessors; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.jms.listener.DefaultMessageListenerContainer] found for dependency [map with value type org.springframework.jms.listener.DefaultMessageListenerContainer]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true), @org.springframework.beans.factory.annotation.Qualifier(value=tvrrmImportQueueProcessor)}


I have declared the bean as below in spring config.

<bean id="tvrrmImportQueueProcessor" class="java.util.HashMap"/>


thanks
Trupti


4 years ago