Search This Blog

Showing posts with label pattern. Show all posts
Showing posts with label pattern. Show all posts

Thursday, June 11, 2020

CamelCase Pattern finding


// Java to find CamelCase Pattern
// matching
import java.util.*;
  
class GFG{
   
// Function that prints the camel
// case pattern matching
static void CamelCase(ArrayList words,
               String pattern)
{
   
    // Map to store the hashing
    // of each words with every
    // uppercase letter found
    Map> map = new HashMap>();
   
    // Traverse the words array
    // that contains all the
    // String
    for (int i = 0; i < words.size(); i++) {
   
        // Intialise str as
        // empty
        String str = "";
   
        // length of String words[i]
        int l = words.get(i).length();
        for (int j = 0; j < l; j++) {
   
            // For every uppercase
            // letter found map
            // that uppercase to
            // original words
            if (words.get(i).charAt(j) >= 'A'
                && words.get(i).charAt(j) <= 'Z') {
                str += words.get(i).charAt(j);
                map.put(str,list(map.get(str),words.get(i)));
            }
        }
    }
   
    boolean wordFound = false;
   
    // Traverse the map for pattern
    // matching
    for (Map.Entry> it : map.entrySet()) {
   
        // If pattern matches then
        // print the corresponding
        // mapped words
        if (it.getKey().equals(pattern)) {
            wordFound = true;
            for(String s : it.getValue())
            System.out.print(s +"\n");
              
        }
    }
   
    // If word not found print
    // "No match found"
    if (!wordFound) {
        System.out.print("No match found");
    }
}
   
private static List list(List list, String str) {
    List temp = new ArrayList();
    if(list != null)
        temp.addAll(list);
    temp.add(str);
    return temp;
}
  
// Driver's Code
public static void main(String[] args)
{
    String arr[] = {"Hi", "Hello", "HelloWorld",
            "HiTech", "HiGeek", "HiTechWorld",
            "HiTechCity", "HiTechLab"
        };
  
    ArrayList words = new ArrayList(Arrays.asList(arr));
   
    // Pattern to be found
    String pattern = "HT";
   
    // Function call to find the
    // words that match to the
    // given pattern
    CamelCase(words, pattern);
   
}
}


Source : https://www.geeksforgeeks.org/camelcase-pattern-matching/?ref=leftbar-rightbar

Wednesday, October 7, 2009

Design Pattern

design pattern is a general reusable solution to a commonly occurring problem in software design. A design pattern is not a finished design that can be transformed directly into code. It is a description or template for how to solve a problem that can be used in many different situations. Object-oriented design patterns typically show relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved.

Design Pattern Types
Creational
Structural
Behavioral
Concurrency



creational design patterns are design patterns that deal with object creation mechanisms, trying to create objects in a manner suitable to the situation. The basic form of object creation could result in design problems or added complexity to the design. Creational design patterns solve this problem by somehow controlling this object creation.


structural design patterns
are design patterns that ease the design by identifying a simple way to realize relationships between entities.

behavioral design patterns are design patterns that identify common communication patterns between objects and realize these patterns. By doing so, these patterns increase flexibility in carrying out this communication.


concurrency patterns
are those types of design patterns that deal with multi-threaded programming paradigm.

Hit Counter


View My Stats