1f5e9a2415ec42c425c2bb17db46f2a9649992d80Brett Chabot/*  Copyright (c) 2000-2006 hamcrest.org
2f5e9a2415ec42c425c2bb17db46f2a9649992d80Brett Chabot */
3f5e9a2415ec42c425c2bb17db46f2a9649992d80Brett Chabotpackage org.hamcrest.text;
4f5e9a2415ec42c425c2bb17db46f2a9649992d80Brett Chabot
5f5e9a2415ec42c425c2bb17db46f2a9649992d80Brett Chabotimport org.hamcrest.Factory;
6f5e9a2415ec42c425c2bb17db46f2a9649992d80Brett Chabotimport org.hamcrest.Matcher;
7f5e9a2415ec42c425c2bb17db46f2a9649992d80Brett Chabot
8f5e9a2415ec42c425c2bb17db46f2a9649992d80Brett Chabot/**
9f5e9a2415ec42c425c2bb17db46f2a9649992d80Brett Chabot * Tests if the argument is a string that contains a substring.
10f5e9a2415ec42c425c2bb17db46f2a9649992d80Brett Chabot */
11f5e9a2415ec42c425c2bb17db46f2a9649992d80Brett Chabotpublic class StringStartsWith extends SubstringMatcher {
12f5e9a2415ec42c425c2bb17db46f2a9649992d80Brett Chabot    public StringStartsWith(String substring) {
13f5e9a2415ec42c425c2bb17db46f2a9649992d80Brett Chabot        super(substring);
14f5e9a2415ec42c425c2bb17db46f2a9649992d80Brett Chabot    }
15f5e9a2415ec42c425c2bb17db46f2a9649992d80Brett Chabot
16f5e9a2415ec42c425c2bb17db46f2a9649992d80Brett Chabot    protected boolean evalSubstringOf(String s) {
17f5e9a2415ec42c425c2bb17db46f2a9649992d80Brett Chabot        return s.startsWith(substring);
18f5e9a2415ec42c425c2bb17db46f2a9649992d80Brett Chabot    }
19f5e9a2415ec42c425c2bb17db46f2a9649992d80Brett Chabot
20f5e9a2415ec42c425c2bb17db46f2a9649992d80Brett Chabot    protected String relationship() {
21f5e9a2415ec42c425c2bb17db46f2a9649992d80Brett Chabot        return "starting with";
22f5e9a2415ec42c425c2bb17db46f2a9649992d80Brett Chabot    }
23f5e9a2415ec42c425c2bb17db46f2a9649992d80Brett Chabot
24f5e9a2415ec42c425c2bb17db46f2a9649992d80Brett Chabot    @Factory
25f5e9a2415ec42c425c2bb17db46f2a9649992d80Brett Chabot    public static Matcher<String> startsWith(String substring) {
26f5e9a2415ec42c425c2bb17db46f2a9649992d80Brett Chabot        return new StringStartsWith(substring);
27f5e9a2415ec42c425c2bb17db46f2a9649992d80Brett Chabot    }
28f5e9a2415ec42c425c2bb17db46f2a9649992d80Brett Chabot
29f5e9a2415ec42c425c2bb17db46f2a9649992d80Brett Chabot}