View Javadoc

1   package org.apache.helix.alerts;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.ArrayList;
23  import java.util.Iterator;
24  import java.util.LinkedList;
25  import java.util.List;
26  import java.util.StringTokenizer;
27  import java.util.Vector;
28  
29  public class Tuple<T> {
30  	List<T> elements;
31  	
32  	public Tuple() 
33  	{
34  		elements = new ArrayList<T>();
35  	}
36  	
37  	public int size()
38  	{
39  		return elements.size();
40  	}
41  
42  	public void add(T entry)
43  	{
44  		elements.add(entry);
45  	}
46  	
47  	public void addAll(Tuple<T> incoming)
48  	{
49  		elements.addAll(incoming.getElements());
50  	}
51  	
52  	public Iterator<T> iterator()
53  	{
54  		return elements.listIterator();
55  	}
56  	
57  	public T getElement(int ind)
58  	{
59  		return elements.get(ind);
60  	}
61  	
62  	public List<T> getElements()
63  	{
64  		return elements;
65  	}
66  	
67  	public void clear() 
68  	{
69  		elements.clear();
70  	}
71  	
72  	public static Tuple<String> fromString(String in) 
73  	{
74  		Tuple<String> tup = new Tuple<String>();
75  		if (in.length() > 0) {
76  			String[] elements = in.split(",");
77  			for (String element : elements) {
78  				tup.add(element);
79  			}
80  		}
81  		return tup;
82  	}
83  	
84  	public String toString() 
85  	{
86  		StringBuilder out = new StringBuilder();
87  		Iterator<T> it = iterator();
88  		boolean outEmpty=true;
89  		while (it.hasNext()) {
90  			if (!outEmpty) {
91  				out.append(",");
92  			}
93  			out.append(it.next());
94  			outEmpty = false;
95  		}
96  		return out.toString();
97  	}
98  }