aspose file tools*
The moose likes Java in General and the fly likes How pattern works?  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How pattern works?  " Watch "How pattern works?  " New topic
Author

How pattern works?

AshutoshP Patil
Ranch Hand

Joined: May 04, 2010
Posts: 32

hi,
can anybody please help me out in the below mentioned factors

1)how the pattern works ? is it a abstract class or singleton class?

2)the part // 1 " st.mt1.find();" which calls the method find() returns a Boolean value true or false .
but the return of this method is not assigned to any variable ? Then how this works ?

Thanks in Advance




AshutoshP
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

AshutoshP Patil wrote:1)how the pattern works ? is it a abstract class or singleton class?

Not sure what you're asking here. Pattern is a class, it has static methods, it has instance methods, like many other classes.
2)the part // 1 " st.mt1.find();" which calls the method find() returns a Boolean value true or false .
but the return of this method is not assigned to any variable ? Then how this works ?

Just because a method returns a variable doesn't mean it has to be used.
AshutoshP Patil
Ranch Hand

Joined: May 04, 2010
Posts: 32
@david just because the method returns the variable it has to be used


my point is since this function is returning a Boolean value , it must be contained into a variable.(may or may not be used)

John de Michele
Rancher

Joined: Mar 09, 2009
Posts: 600
AshutoshP Patil wrote:
my point is since this function is returning a Boolean value , it must be contained into a variable.(may or may not be used)


No, actually it doesn't. The JVM will happily toss out values and references that you don't assign.

John.
AshutoshP Patil
Ranch Hand

Joined: May 04, 2010
Posts: 32

ok i got. thanks john.
can you please go ahead how this compile method works ?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Why *wouldn't* it work? Have you looked at the Matcher docs?
AshutoshP Patil
Ranch Hand

Joined: May 04, 2010
Posts: 32
my doubt is how the compile method can take two values
one when it is passed as actual argument
another after passed to method " st.pt1=((Pattern)ob).compile(s[0]);"

will it modify upon the previous pattern instance?

thanks for reply.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I'm still not sure what you're asking, sorry.
Larry Frissell
Ranch Hand

Joined: May 16, 2008
Posts: 82
    
    2
my doubt is how the compile method can take two values
one when it is passed as actual argument
another after passed to method " st.pt1=((Pattern)ob).compile(s[0]);"


compile is not taking two values, in the code ob1 is an instance of Pattern created using the Pattern method "compile(String regex)" then in the method getFormattedObject, the if statement determines that the object is an instance of Pattern. if true, then the Stores object pt1 will equal a Pattern object resulting from the compile(s[0]) or compile("H[a-b][k-m").

Larry
AshutoshP Patil
Ranch Hand

Joined: May 04, 2010
Posts: 32
thanks i got.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How pattern works?