1 package com.atlassian.plugin.util;
2
3 /**
4 * String utility methods designed for memory / cpu efficiency
5 */
6 public class EfficientStringUtils
7 {
8 /**
9 * Test to see if a given string ends with some suffixes. Avoids the cost
10 * of concatenating the suffixes together
11 * @param src the source string to be tested
12 * @param suffixes the set of suffixes
13 * @return true if src ends with the suffixes concatenated together
14 */
15 public static boolean endsWith(final String src, final String... suffixes)
16 {
17 int pos = src.length();
18
19 for (int i = suffixes.length - 1; i >= 0; i--)
20 {
21 final String suffix = suffixes[i];
22 pos -= suffix.length();
23 if (!src.startsWith(suffix, pos))
24 {
25 return false;
26 }
27 }
28 return true;
29 }
30 }