
package source.Utility;

//
// Utility Program for TETDM 
// Matching.java Version 1.00
// Copyright(C) 2018- TETDM CORE MEMBER ALL RIGHTS RESERVED.
// This program is provided under the license.
//

import java.util.regex.*;

public class Matching
{
    //option: 0:all, 1:top of the String, 2:ignore case(upper/lower letters)
    public static boolean matching(String str, String pat, int option)
    {
        boolean matched = false;
        
        if(option == 1)
            pat = "^"+pat;
        
        if(option == 2)
            pat = "(?i)"+pat;
        
        Pattern pattern = Pattern.compile(pat);
        Matcher matcher = pattern.matcher(str);
            
        if(matcher.find())
            matched = true;
        
        return matched;
    }
    
    //option: 0:all, 1:top of the String, 2:ignore case(upper/lower letters)
	public static boolean[] matching(String str[], String pat, int option)
	{
        boolean matched[] = new boolean[str.length];
        
		for(int i=0;i<str.length;i++)
			matched[i] = false;
        
        if(option == 1)
            pat = "^"+pat;
        
        if(option == 2)
            pat = "(?i)"+pat;
        
        Pattern pattern = Pattern.compile(pat);
        
        for(int i=0;i<str.length;i++)
        {
            Matcher matcher = pattern.matcher(str[i]);
        
            if(matcher.find())
                matched[i] = true;
        }
        
        return matched;
	}
    
    //option: 0:all, 1:top of the String, 2:ignore case(upper/lower letters)
    public static boolean[] matching(String str[], String pat[], int option)
    {
        boolean matched[] = new boolean[str.length];
        
        for(int i=0;i<str.length;i++)
            matched[i] = false;
        
        for(int j=0;j<pat.length;j++)
        {
            String pat1 = pat[j];
            
            if(option == 1)
                pat1 = "^"+pat1;
            
            if(option == 2)
                pat1 = "(?i)"+pat1;
            
            Pattern pattern = Pattern.compile(pat1);
        
            for(int i=0;i<str.length;i++)
            {
                Matcher matcher = pattern.matcher(str[i]);
            
                if(matcher.find())
                    matched[i] = true;
            }
        }
        
        return matched;
    }
}
