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 org.apache.log4j.spi.LoggingEvent;
21  
22  import java.util.*;
23  
24  
25  /**
26   * A container class that contains a group of events split up
27   * into branches based on Identifiers
28   *
29   * @author Paul Smith <psmith@apache.org>
30   * @author Scott Deboy <sdeboy@apache.org>
31   */
32  class ChainsawEventBatch {
33      private Map<String, List<LoggingEvent>> identEventMap = new HashMap<>();
34  
35      ChainsawEventBatch() {
36      }
37  
38      /**
39       * @param ident
40       * @param e
41       */
42      void addEvent(String ident, LoggingEvent e) {
43          List<LoggingEvent> events = identEventMap.get(ident);
44  
45          if (events == null) {
46              events = new ArrayList<>();
47              identEventMap.put(ident, events);
48          }
49  
50          events.add(e);
51      }
52  
53      /**
54       * Returns an iterator of Identifier strings that this payload contains.
55       * <p>
56       * The values returned from this iterator can be used to query the
57       *
58       * @return Iterator
59       */
60      Iterator<String> identifierIterator() {
61          return identEventMap.keySet().iterator();
62      }
63  
64      /**
65       * Returns a Collection of LoggingEvent objects that
66       * are bound to the identifier
67       *
68       * @param identifier
69       * @return Collection of LoggingEvent instances
70       */
71      List<LoggingEvent> entrySet(String identifier) {
72          return identEventMap.get(identifier);
73      }
74  }