Commit | Line | Data |
---|---|---|
5d10d135 ASL |
1 | /******************************************************************************* |
2 | * Copyright (c) 2009 Ericsson | |
3 | * | |
4 | * All rights reserved. This program and the accompanying materials are | |
5 | * made available under the terms of the Eclipse Public License v1.0 which | |
6 | * accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | package org.eclipse.linuxtools.lttng.state.model; | |
13 | ||
14 | import java.util.Stack; | |
15 | ||
16 | import org.eclipse.linuxtools.lttng.TraceDebug; | |
17 | import org.eclipse.linuxtools.lttng.state.StateStrings.BdevMode; | |
18 | ||
19 | /** | |
20 | * <b><u>LttvBdevState</u></b> | |
21 | * <p> | |
22 | * | |
23 | */ | |
24 | public class LttngBdevState implements Cloneable { | |
25 | // ======================================================================== | |
26 | // Data | |
27 | // ======================================================================= | |
28 | private Stack<BdevMode> mode_stack = new Stack<BdevMode>() ; | |
29 | ||
30 | ||
31 | // ======================================================================== | |
32 | // Constructor | |
33 | // ======================================================================= | |
34 | public LttngBdevState() { | |
35 | mode_stack.push(BdevMode.LTTV_BDEV_UNKNOWN); | |
36 | } | |
37 | ||
38 | // ======================================================================== | |
39 | // Methods | |
40 | // ======================================================================= | |
41 | public void clearBdevStack() { | |
42 | mode_stack.clear(); | |
43 | } | |
44 | ||
45 | public void clearAndSetBaseToBdevStack(BdevMode newState) { | |
46 | mode_stack.clear(); | |
47 | // Ensure that there is always at least 1 item in the stack | |
48 | mode_stack.push(newState); | |
49 | } | |
50 | ||
51 | public void pushToBdevStack(BdevMode newState) { | |
52 | mode_stack.push(newState); | |
53 | } | |
54 | ||
55 | public BdevMode popFromBdevStack() { | |
56 | ||
57 | BdevMode returnedMode = mode_stack.pop(); | |
58 | ||
59 | if (mode_stack.size() < 1) { | |
60 | TraceDebug.debug("Removing last item from mode stack is not allowed! (popFromModeStack)"); | |
61 | mode_stack.push(BdevMode.LTTV_BDEV_UNKNOWN); | |
62 | } | |
63 | ||
64 | return returnedMode; | |
65 | } | |
66 | ||
67 | public BdevMode peekFromBdevStack() { | |
68 | return mode_stack.peek(); | |
69 | } | |
70 | ||
71 | ||
cc6eec3e | 72 | @Override |
5d10d135 ASL |
73 | @SuppressWarnings("unchecked") |
74 | public LttngBdevState clone() { | |
75 | LttngBdevState newState = null; | |
76 | ||
77 | try { | |
78 | newState = (LttngBdevState)super.clone(); | |
79 | // Clone should work correctly for all stack object that contain basic java object (String, Long, etc...) | |
80 | newState.mode_stack = (Stack<BdevMode>)this.mode_stack.clone(); | |
81 | } | |
82 | catch ( CloneNotSupportedException e ) { | |
83 | System.out.println("Cloning failed with : " + e.getMessage() ); | |
84 | } | |
85 | ||
86 | return newState; | |
87 | } | |
88 | ||
89 | } |