@Override
 public PatternMatch matches(String str) {
   PatternMatch match = m1.matches(str);
   // done for short circuit
   if (match.isMatched()) {
     return match.and(m2.matches(str));
   } else {
     return match;
   }
 }
 public boolean matches(@NotNull final String name, @NotNull final String pattern) {
   final AnAction anAction = myActionManager.getAction(name);
   if (!(anAction instanceof ActionGroup)) {
     final Presentation presentation = anAction.getTemplatePresentation();
     final String text = presentation.getText();
     final String description = presentation.getDescription();
     final Pattern compiledPattern = getPattern(pattern);
     if ((text != null && myMatcher.matches(text, compiledPattern))
         || (description != null && myMatcher.matches(description, compiledPattern))) {
       return true;
     }
   }
   return false;
 }
 /**
  * Builds a {@link java.util.Vector} containing Strings which each name a file who's name matches
  * the pattern set by setPattern(String). The classpath is searched recursively, so use with
  * caution.
  *
  * @return Vector<String> containing matching filenames
  */
 public Vector<String> findMatches() {
   Vector<String> matches = new Vector<String>();
   URLClassLoader cl = getURLClassLoader();
   if (cl == null) {
     throw new XWorkException("unable to attain an URLClassLoader");
   }
   URL[] parentUrls = cl.getURLs();
   compiledPattern = (int[]) patternMatcher.compilePattern(pattern);
   for (URL url : parentUrls) {
     if (!"file".equals(url.getProtocol())) {
       continue;
     }
     URI entryURI;
     try {
       entryURI = url.toURI();
     } catch (URISyntaxException e) {
       continue;
     }
     File entry = new File(entryURI);
     Vector<String> results = checkEntries(entry.list(), entry, "");
     if (results != null) {
       matches.addAll(results);
     }
   }
   return matches;
 }
  public static List<LinkedHashMap<String, Object>> getPhrases(
      GraphDatabaseService db, String text, GraphManager graphManager) {
    // This method trains a model on a supplied label and text content
    Map<Long, Integer> patternMatchers =
        PatternMatcher.match(GraphManager.ROOT_TEMPLATE, text, db, graphManager);

    // Translate map to phrases
    List<LinkedHashMap<String, Object>> results =
        patternMatchers
            .keySet()
            .stream()
            .map(
                a -> {
                  LinkedHashMap<String, Object> linkHashMap = new LinkedHashMap<>();
                  linkHashMap.put("feature", NodeManager.getNodeFromGlobalCache(a).get("phrase"));
                  linkHashMap.put("frequency", patternMatchers.get(a));
                  return linkHashMap;
                })
            .collect(Collectors.toList());

    results.sort(
        (a, b) -> {
          Integer diff = ((Integer) a.get("frequency")) - ((Integer) b.get("frequency"));
          return diff > 0 ? -1 : diff.equals(0) ? 0 : 1;
        });

    return results;
  }
  private Vector<String> checkEntries(String[] entries, File parent, String prefix) {

    if (entries == null) {
      return null;
    }

    Vector<String> matches = new Vector<String>();
    for (String listEntry : entries) {
      File tempFile;
      if (!"".equals(prefix)) {
        tempFile = new File(parent, prefix + "/" + listEntry);
      } else {
        tempFile = new File(parent, listEntry);
      }
      if (tempFile.isDirectory() && !(".".equals(listEntry) || "..".equals(listEntry))) {
        if (!"".equals(prefix)) {
          matches.addAll(checkEntries(tempFile.list(), parent, prefix + "/" + listEntry));
        } else {
          matches.addAll(checkEntries(tempFile.list(), parent, listEntry));
        }
      } else {

        String entryToCheck;
        if ("".equals(prefix)) {
          entryToCheck = listEntry;
        } else {
          entryToCheck = prefix + "/" + listEntry;
        }

        if (compared.contains(entryToCheck)) {
          continue;
        } else {
          compared.add(entryToCheck);
        }

        boolean doesMatch =
            patternMatcher.match(new HashMap<String, String>(), entryToCheck, compiledPattern);
        if (doesMatch) {
          matches.add(entryToCheck);
        }
      }
    }
    return matches;
  }
  /**
   * Filters a collection according to the include and exclude parameters.
   *
   * @param c The collection to filter.
   * @return A filtered collection.
   */
  protected Collection filterCollection(Collection c) {
    ArrayList<Object> result = new ArrayList<Object>();

    PatternMatcher pm = new Perl5Matcher();

    for (Iterator i = c.iterator(); i.hasNext(); ) {
      String pageName = null;
      Object objectje = i.next();
      if (objectje instanceof WikiPage) {
        pageName = ((WikiPage) objectje).getName();
      } else {
        pageName = (String) objectje;
      }

      //
      //  If include parameter exists, then by default we include only those
      //  pages in it (excluding the ones in the exclude pattern list).
      //
      //  include='*' means the same as no include.
      //
      boolean includeThis = m_include == null;

      if (m_include != null) {
        for (int j = 0; j < m_include.length; j++) {
          if (pm.matches(pageName, m_include[j])) {
            includeThis = true;
            break;
          }
        }
      }

      if (m_exclude != null) {
        for (int j = 0; j < m_exclude.length; j++) {
          if (pm.matches(pageName, m_exclude[j])) {
            includeThis = false;
            break; // The inner loop, continue on the next item
          }
        }
      }

      if (includeThis) {
        if (objectje instanceof WikiPage) {
          result.add(objectje);
        } else {
          result.add(pageName);
        }
        //
        //  if we want to show the last modified date of the most recently change page, we keep a
        // "high watermark" here:
        WikiPage page = null;
        if (m_lastModified) {
          page = m_engine.getPage(pageName);
          if (page != null) {
            Date lastModPage = page.getLastModified();
            if (log.isDebugEnabled()) {
              log.debug("lastModified Date of page " + pageName + " : " + m_dateLastModified);
            }
            if (lastModPage.after(m_dateLastModified)) {
              m_dateLastModified = lastModPage;
            }
          }
        }
      }
    }

    return result;
  }
 @Override
 public String toString() {
   return "(" + m1.toString() + " and " + m2.toString() + ")";
 }