public boolean match(String pattern)
    {
        Queue<Entry<String, NfaNode>> queue = new LinkedList<>();
        queue.addAll(start.getAllTransitions());
        if (finalStates.contains(start) || epsilonTransitionsToFinal(start))
            queue.add(createEntry("~", start));
        
        Entry<String, NfaNode> entry = null;
        for (int i = 0; i < pattern.length(); i++)
        {
            Set<Entry<String, NfaNode>> toAdd = new HashSet<>();
            char c = pattern.charAt(i);
            while (!queue.isEmpty())
            {
                entry = queue.poll();
                
                if (entry.getKey().contains(EPSILON))
                    queue.addAll(entry.getValue().getAllTransitions());
                
                if (entry.getKey().charAt(0) == c)
                {
                    toAdd.addAll(entry.getValue().getAllTransitions());
                    if (i == pattern.length()-1 && (finalStates.contains(entry.getValue()) || epsilonTransitionsToFinal(entry.getValue())))
                        return true;
                }
            }
            queue.addAll(toAdd);
        }
        return false;
    }