trace/traceviewer/com.nokia.traceviewer/src/com/nokia/traceviewer/engine/FileMap.java
equal
deleted
inserted
replaced
|
1 /* |
|
2 * Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 * FileMap class |
|
17 * |
|
18 */ |
|
19 package com.nokia.traceviewer.engine; |
|
20 |
|
21 import java.util.ArrayList; |
|
22 import java.util.List; |
|
23 |
|
24 /** |
|
25 * Hold information about trace block positions in file |
|
26 * |
|
27 */ |
|
28 public class FileMap { |
|
29 |
|
30 /** |
|
31 * Map which holds the file pointers to messages |
|
32 */ |
|
33 private final List<Long> map; |
|
34 |
|
35 /** |
|
36 * Constructor |
|
37 */ |
|
38 public FileMap() { |
|
39 map = new ArrayList<Long>(); |
|
40 } |
|
41 |
|
42 /** |
|
43 * Insert item to map |
|
44 * |
|
45 * @param item |
|
46 * item |
|
47 */ |
|
48 public void insert(Long item) { |
|
49 map.add(item); |
|
50 } |
|
51 |
|
52 /** |
|
53 * Gets item from map |
|
54 * |
|
55 * @param index |
|
56 * index of item |
|
57 * @return item |
|
58 */ |
|
59 public Long getItem(int index) { |
|
60 long item = 0; |
|
61 if (index < 0) { |
|
62 item = 0; |
|
63 } else if (index > map.size() - 1) { |
|
64 item = 0; |
|
65 } else { |
|
66 item = map.get(index).longValue(); |
|
67 } |
|
68 return Long.valueOf(item); |
|
69 } |
|
70 |
|
71 /** |
|
72 * Gets index from map from specific offset |
|
73 * |
|
74 * @param offset |
|
75 * offset of item |
|
76 * @return index |
|
77 */ |
|
78 public int getIndexFromOffset(int offset) { |
|
79 int index = (offset / TraceViewerGlobals.blockSize); |
|
80 return index; |
|
81 } |
|
82 |
|
83 /** |
|
84 * Empties map |
|
85 */ |
|
86 public void clearMap() { |
|
87 map.clear(); |
|
88 } |
|
89 |
|
90 /** |
|
91 * Gets size of this map |
|
92 * |
|
93 * @return size |
|
94 */ |
|
95 public int size() { |
|
96 return map.size(); |
|
97 } |
|
98 } |