1 /*
2 * Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
125 return Collections.emptyList();
126 return Arrays.asList(text.split(sep));
127 }
128
129 /**
130 * Checks if two lists of strings are equal.
131 * @param l1 the first list of strings to be compared
132 * @param l2 the second list of strings to be compared
133 * @throws Error if the lists are not equal
134 */
135 public void checkEqual(List<String> l1, List<String> l2) throws Error {
136 if (!Objects.equals(l1, l2)) {
137 // l1 and l2 cannot both be null
138 if (l1 == null)
139 throw new Error("comparison failed: l1 is null");
140 if (l2 == null)
141 throw new Error("comparison failed: l2 is null");
142 // report first difference
143 for (int i = 0; i < Math.min(l1.size(), l2.size()); i++) {
144 String s1 = l1.get(i);
145 String s2 = l1.get(i);
146 if (!Objects.equals(s1, s2)) {
147 throw new Error("comparison failed, index " + i +
148 ", (" + s1 + ":" + s2 + ")");
149 }
150 }
151 throw new Error("comparison failed: l1.size=" + l1.size() + ", l2.size=" + l2.size());
152 }
153 }
154
155 /**
156 * Filters a list of strings according to the given regular expression.
157 * @param regex the regular expression
158 * @param lines the strings to be filtered
159 * @return the strings matching the regular expression
160 */
161 public List<String> grep(String regex, List<String> lines) {
162 return grep(Pattern.compile(regex), lines);
163 }
164
165 /**
|
1 /*
2 * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
125 return Collections.emptyList();
126 return Arrays.asList(text.split(sep));
127 }
128
129 /**
130 * Checks if two lists of strings are equal.
131 * @param l1 the first list of strings to be compared
132 * @param l2 the second list of strings to be compared
133 * @throws Error if the lists are not equal
134 */
135 public void checkEqual(List<String> l1, List<String> l2) throws Error {
136 if (!Objects.equals(l1, l2)) {
137 // l1 and l2 cannot both be null
138 if (l1 == null)
139 throw new Error("comparison failed: l1 is null");
140 if (l2 == null)
141 throw new Error("comparison failed: l2 is null");
142 // report first difference
143 for (int i = 0; i < Math.min(l1.size(), l2.size()); i++) {
144 String s1 = l1.get(i);
145 String s2 = l2.get(i);
146 if (!Objects.equals(s1, s2)) {
147 throw new Error("comparison failed, index " + i +
148 ", (" + s1 + ":" + s2 + ")");
149 }
150 }
151 throw new Error("comparison failed: l1.size=" + l1.size() + ", l2.size=" + l2.size());
152 }
153 }
154
155 /**
156 * Filters a list of strings according to the given regular expression.
157 * @param regex the regular expression
158 * @param lines the strings to be filtered
159 * @return the strings matching the regular expression
160 */
161 public List<String> grep(String regex, List<String> lines) {
162 return grep(Pattern.compile(regex), lines);
163 }
164
165 /**
|