01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18: package org.apache.jmeter.protocol.java.control.gui;
19:
20: import java.util.ArrayList;
21: import java.util.Iterator;
22: import java.util.List;
23:
24: /**
25: * @author pete
26: *
27: * TODO To change the template for this generated type comment go to
28: * Window - Preferences - Java - Code Style - Code Templates
29: */
30: public class ClassFilter {
31:
32: protected String[] pkgs = new String[0];
33:
34: /**
35: *
36: */
37: public ClassFilter() {
38: super ();
39: }
40:
41: public void setPackges(String[] pk) {
42: this .pkgs = pk;
43: }
44:
45: public void addPackage(String pkg) {
46: String[] newpkg = new String[pkgs.length + 1];
47: System.arraycopy(pkgs, 0, newpkg, 0, pkgs.length);
48: newpkg[pkgs.length] = pkg;
49: pkgs = newpkg;
50: }
51:
52: public boolean include(String text) {
53: boolean inc = false;
54: for (int idx = 0; idx < pkgs.length; idx++) {
55: if (text.startsWith(pkgs[idx])) {
56: inc = true;
57: break;
58: }
59: }
60: return inc;
61: }
62:
63: public Object[] filterArray(List items) {
64: Iterator itr = items.iterator();
65: ArrayList newlist = new ArrayList();
66: while (itr.hasNext()) {
67: Object item = itr.next();
68: if (include((String) item)) {
69: newlist.add(item);
70: }
71: }
72: if (newlist.size() > 0) {
73: return newlist.toArray();
74: } else {
75: return new Object[0];
76: }
77: }
78:
79: public int size() {
80: return pkgs.length;
81: }
82: }
|