View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      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.log4j.chainsaw;
19  
20  import java.util.ArrayList;
21  import java.util.HashMap;
22  import java.util.Iterator;
23  import java.util.List;
24  import java.util.Map;
25  
26  import org.apache.log4j.spi.LoggingEvent;
27  
28  
29  /***
30   * A container class that contains a group of events split up
31   * into branches based on Identifiers
32   * @author Paul Smith <psmith@apache.org>
33   * @author Scott Deboy <sdeboy@apache.org>
34   *
35   */
36  class ChainsawEventBatch {
37    private Map identEventMap = new HashMap();
38  
39    ChainsawEventBatch() {
40    }
41  
42    /***
43     * @param ident
44     * @param e
45     */
46    void addEvent(String ident, LoggingEvent e) {
47      List events = (List)identEventMap.get(ident);
48  
49      if (events == null) {
50        events = new ArrayList();
51        identEventMap.put(ident, events);
52      }
53  
54      events.add(e);
55    }
56  
57    /***
58     * Returns an iterator of Identifier strings that this payload contains.
59     *
60     * The values returned from this iterator can be used to query the
61     *
62     * @return Iterator
63     */
64    Iterator identifierIterator() {
65      return identEventMap.keySet().iterator();
66    }
67  
68    /***
69     * Returns a Collection of LoggingEvent objects that
70     * are bound to the identifier
71     * @param identifier
72     * @return Collection of LoggingEvent instances
73     */
74    List entrySet(String identifier) {
75      return (List) identEventMap.get(identifier);
76    }
77  }