Package org.eclipse.jgit.fnmatch

Examples of org.eclipse.jgit.fnmatch.FileNameMatcher


  private static boolean isHostPattern(final String s) {
    return s.indexOf('*') >= 0 || s.indexOf('?') >= 0;
  }

  private static boolean isHostMatch(final String pattern, final String name) {
    final FileNameMatcher fn;
    try {
      fn = new FileNameMatcher(pattern, null);
    } catch (InvalidPatternException e) {
      return false;
    }
    fn.append(name);
    return fn.isMatch();
  }
View Full Code Here


      pattern = "/" + pattern;
    }

    if (pattern.contains("*") || pattern.contains("?") || pattern.contains("[")) {
      try {
        matcher = new FileNameMatcher(pattern, Character.valueOf('/'));
      } catch (InvalidPatternException e) {
        e.printStackTrace();
      }
    }
  }
View Full Code Here

      pattern = "/" + pattern; //$NON-NLS-1$
    }

    if (pattern.contains("*") || pattern.contains("?") || pattern.contains("[")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
      try {
        matcher = new FileNameMatcher(pattern, Character.valueOf('/'));
      } catch (InvalidPatternException e) {
        // Ignore pattern exceptions
      }
    }
  }
View Full Code Here

  private static boolean isHostPattern(final String s) {
    return s.indexOf('*') >= 0 || s.indexOf('?') >= 0;
  }

  private static boolean isHostMatch(final String pattern, final String name) {
    final FileNameMatcher fn;
    try {
      fn = new FileNameMatcher(pattern, null);
    } catch (InvalidPatternException e) {
      return false;
    }
    fn.append(name);
    return fn.isMatch();
  }
View Full Code Here

public class FileNameMatcherTest extends TestCase {

  private void assertMatch(final String pattern, final String input,
      final boolean matchExpected, final boolean appendCanMatchExpected)
      throws InvalidPatternException {
    final FileNameMatcher matcher = new FileNameMatcher(pattern, null);
    matcher.append(input);
    assertEquals(matchExpected, matcher.isMatch());
    assertEquals(appendCanMatchExpected, matcher.canAppendMatch());
  }
View Full Code Here

  private void assertFileNameMatch(final String pattern, final String input,
      final char excludedCharacter, final boolean matchExpected,
      final boolean appendCanMatchExpected)
      throws InvalidPatternException {
    final FileNameMatcher matcher = new FileNameMatcher(pattern,
        new Character(excludedCharacter));
    matcher.append(input);
    assertEquals(matchExpected, matcher.isMatch());
    assertEquals(appendCanMatchExpected, matcher.canAppendMatch());
  }
View Full Code Here

    assertFileNameMatch("a?b", "a\\b", '\\', false, false);
  }

  public void testReset() throws Exception {
    final String pattern = "helloworld";
    final FileNameMatcher matcher = new FileNameMatcher(pattern, null);
    matcher.append("helloworld");
    assertEquals(true, matcher.isMatch());
    assertEquals(false, matcher.canAppendMatch());
    matcher.reset();
    matcher.append("hello");
    assertEquals(false, matcher.isMatch());
    assertEquals(true, matcher.canAppendMatch());
    matcher.append("world");
    assertEquals(true, matcher.isMatch());
    assertEquals(false, matcher.canAppendMatch());
    matcher.append("to much");
    assertEquals(false, matcher.isMatch());
    assertEquals(false, matcher.canAppendMatch());
    matcher.reset();
    matcher.append("helloworld");
    assertEquals(true, matcher.isMatch());
    assertEquals(false, matcher.canAppendMatch());
  }
View Full Code Here

    assertEquals(false, matcher.canAppendMatch());
  }

  public void testCreateMatcherForSuffix() throws Exception {
    final String pattern = "helloworld";
    final FileNameMatcher matcher = new FileNameMatcher(pattern, null);
    matcher.append("hello");
    final FileNameMatcher childMatcher = matcher.createMatcherForSuffix();
    assertEquals(false, matcher.isMatch());
    assertEquals(true, matcher.canAppendMatch());
    assertEquals(false, childMatcher.isMatch());
    assertEquals(true, childMatcher.canAppendMatch());
    matcher.append("world");
    assertEquals(true, matcher.isMatch());
    assertEquals(false, matcher.canAppendMatch());
    assertEquals(false, childMatcher.isMatch());
    assertEquals(true, childMatcher.canAppendMatch());
    childMatcher.append("world");
    assertEquals(true, matcher.isMatch());
    assertEquals(false, matcher.canAppendMatch());
    assertEquals(true, childMatcher.isMatch());
    assertEquals(false, childMatcher.canAppendMatch());
    childMatcher.reset();
    assertEquals(true, matcher.isMatch());
    assertEquals(false, matcher.canAppendMatch());
    assertEquals(false, childMatcher.isMatch());
    assertEquals(true, childMatcher.canAppendMatch());
    childMatcher.append("world");
    assertEquals(true, matcher.isMatch());
    assertEquals(false, matcher.canAppendMatch());
    assertEquals(true, childMatcher.isMatch());
    assertEquals(false, childMatcher.canAppendMatch());
  }
View Full Code Here

    assertEquals(false, childMatcher.canAppendMatch());
  }

  public void testCopyConstructor() throws Exception {
    final String pattern = "helloworld";
    final FileNameMatcher matcher = new FileNameMatcher(pattern, null);
    matcher.append("hello");
    final FileNameMatcher copy = new FileNameMatcher(matcher);
    assertEquals(false, matcher.isMatch());
    assertEquals(true, matcher.canAppendMatch());
    assertEquals(false, copy.isMatch());
    assertEquals(true, copy.canAppendMatch());
    matcher.append("world");
    assertEquals(true, matcher.isMatch());
    assertEquals(false, matcher.canAppendMatch());
    assertEquals(false, copy.isMatch());
    assertEquals(true, copy.canAppendMatch());
    copy.append("world");
    assertEquals(true, matcher.isMatch());
    assertEquals(false, matcher.canAppendMatch());
    assertEquals(true, copy.isMatch());
    assertEquals(false, copy.canAppendMatch());
    copy.reset();
    assertEquals(true, matcher.isMatch());
    assertEquals(false, matcher.canAppendMatch());
    assertEquals(false, copy.isMatch());
    assertEquals(true, copy.canAppendMatch());
    copy.append("helloworld");
    assertEquals(true, matcher.isMatch());
    assertEquals(false, matcher.canAppendMatch());
    assertEquals(true, copy.isMatch());
    assertEquals(false, copy.canAppendMatch());
  }
View Full Code Here

      pattern = "/" + pattern;
    }

    if (pattern.contains("*") || pattern.contains("?") || pattern.contains("[")) {
      try {
        matcher = new FileNameMatcher(pattern, new Character('/'));
      } catch (InvalidPatternException e) {
        e.printStackTrace();
      }
    }
  }
View Full Code Here

TOP

Related Classes of org.eclipse.jgit.fnmatch.FileNameMatcher

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.