/** * @see org.dihedron.core.filters.Filter#matches(java.lang.Object) */ @Override public boolean matches(String object) { return regex.matches(object); } }
/** * Constructor. * * @param regex * the regular expression to match against. */ public NameLike(String regex) { this.regex = new Regex(regex); }
/** * Constructor. * * @param regex * a regular expression. */ public Filter(Regex regex) { this.regex = regex; logger.debug("checking regex /{}/, case {}", regex, (regex.isCaseSensitive() ? "sensitive" : "insensitive")); }
/** * @see org.dihedron.core.filters.Filter#matches(java.lang.Object) */ @Override public boolean matches(String object) { return regex.matches(object); } }
/** * Constructor. * * @param regex * the regular expression to match against. * @param caseSensitive * whether the match should be case sensitive (default: {@code true}). */ public Matches(String regex, boolean caseSensitive) { this.regex = new Regex(regex, caseSensitive); }
/** * @see org.dihedron.core.filters.Filter#matches(java.lang.Object) */ @Override public boolean matches(String object) { return regex.matches(object); } }
/** * Constructor. * * @param regex * the regular expression to match against. */ public NameLike(String regex) { this.regex = new Regex(regex); }
/** * Checks whether a resource complies with the filter criteria. */ public boolean accept(File dir, String name) { boolean result = regex.matches(name); logger.debug("checked resource '{}', result is {}", name, result); return result; }
/** * Constructor. * * @param regex * the regular expression to match against. */ public NameLike(String regex) { this.regex = new Regex(regex); }
/** * @see org.dihedron.commons.reflection.ReflectorFilter#matches(java.lang.reflect.Member) */ @Override public boolean matches(T member) { return regex.matches(member.getName()); } }
/** * Constructor. * * @param pattern * the pattern to match against file names. * @param files * an output list of files matching the given name pattern. */ public FileFinderVisitor(String pattern, List<File> files) { regex = new Regex(pattern); this.files = files; }
/** * @see org.dihedron.commons.reflection.ReflectorFilter#matches(java.lang.reflect.Member) */ @Override public boolean matches(T member) { return regex.matches(member.getName()); } }
/** * Constructor. * * @param regex * the regular expression to match against. * @param caseSensitive * whether the match should be case sensitive (default: {@code true}). */ public Matches(String regex, boolean caseSensitive) { this.regex = new Regex(regex, caseSensitive); }
/** * @see org.dihedron.commons.reflection.ReflectorFilter#matches(java.lang.reflect.Member) */ @Override public boolean matches(T member) { return regex.matches(member.getName()); } }
/** * Constructor. * * @param regex * the regular expression to match against. * @param caseSensitive * whether the match should be case sensitive (default: {@code true}). */ public Matches(String regex, boolean caseSensitive) { this.regex = new Regex(regex, caseSensitive); }
/** * @see org.dihedron.patterns.cache.Storage#list(org.dihedron.core.regex.Regex) */ @Override public String[] list(Regex regex) { if(regex != null && !resources.isEmpty()) { List<String> matches = new ArrayList<>(); for(String resource : resources) { if(regex.matches(resource)) { matches.add(resource); } } return matches.toArray(new String[matches.size()]); } return null; }
/** * Performs the actual file-system visit, matching files against the given * pattern as it goes and storing matching ones in the given list. * * @see * java.nio.file.SimpleFileVisitor#visitFile(java.lang.Object, java.nio.file.attribute.BasicFileAttributes) */ @Override public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException { Path name = path.getFileName(); if(regex.matches(name.toString())) { logger.trace("file found: {} -> {}", path.getParent(), name); files.add(path.toFile()); } return FileVisitResult.CONTINUE; } }
/** * @see org.dihedron.patterns.cache.Storage#delete(org.dihedron.core.regex.Regex) */ @Override public void delete(Regex regex) { Set<String> resources = new HashSet<String>(contents.keySet()); for (String resource : resources) { if(regex.matches(resource)){ logger.debug("removing resource '{}'", resource); Streams.safelyClose(contents.get(resource)); contents.remove(resource); } } }
/** * @see org.dihedron.patterns.cache.Storage#list(org.dihedron.core.regex.Regex) */ @Override public String[] list(Regex regex) { List<String> matched = new ArrayList<String>(); if(regex != null) { for (String resource : contents.keySet()) { if(regex.matches(resource)) { logger.trace("regular expression matches input string '{}'", resource); matched.add(resource); } } } else { matched.addAll(contents.keySet()); } return matched.toArray(new String[0]); }
/** * @see org.dihedron.patterns.cache.Storage#list(org.dihedron.core.regex.Regex) */ @Override public String[] list(Regex regex) { if(regex == null) { logger.debug("returning full list of storage contents"); return index.keySet().toArray(new String[0]); } else { logger.debug("returning list of resources matching /{}/", regex); List<String> matched = new ArrayList<String>(); for(String key : index.keySet()) { if(regex.matches(key)) { matched.add(key); } } return matched.toArray(new String[0]); } }