From dea2b2b45a7fdc084e34eb0293a8191a9c5fd86c Mon Sep 17 00:00:00 2001 From: Jonathan Rajotte Julien Date: Mon, 11 Aug 2014 13:32:50 -0400 Subject: [PATCH] tmf: lttngControl: TraceLogLvl: add valueOfString utility Change-Id: Ie0046d483c0bd47115bf0fe05660c13cbcc66ff1 Signed-off-by: Jonathan Rajotte Julien Reviewed-on: https://git.eclipse.org/r/31391 Tested-by: Hudson CI Reviewed-by: Bernd Hufmann Tested-by: Bernd Hufmann Reviewed-by: Matthew Khouzam --- .../tests/model/impl/BaseEventInfoTest.java | 6 ++-- .../control/core/model/TraceLogLevel.java | 33 ++++++++++++++--- .../core/model/impl/BaseEventInfo.java | 36 +------------------ 3 files changed, 33 insertions(+), 42 deletions(-) diff --git a/org.eclipse.linuxtools.lttng2.control.core.tests/src/org/eclipse/linuxtools/lttng2/control/core/tests/model/impl/BaseEventInfoTest.java b/org.eclipse.linuxtools.lttng2.control.core.tests/src/org/eclipse/linuxtools/lttng2/control/core/tests/model/impl/BaseEventInfoTest.java index 0bb5755c3d..871d2970cb 100644 --- a/org.eclipse.linuxtools.lttng2.control.core.tests/src/org/eclipse/linuxtools/lttng2/control/core/tests/model/impl/BaseEventInfoTest.java +++ b/org.eclipse.linuxtools.lttng2.control.core.tests/src/org/eclipse/linuxtools/lttng2/control/core/tests/model/impl/BaseEventInfoTest.java @@ -409,9 +409,9 @@ public class BaseEventInfoTest { result = fixture.getLogLevel(); assertNotNull(result); - assertEquals("TRACE_DEBUG", result.getInName()); - assertEquals("TRACE_DEBUG", result.name()); - assertEquals(14, result.ordinal()); + assertEquals("LEVEL_UNKNOWN", result.getInName()); + assertEquals("LEVEL_UNKNOWN", result.name()); + assertEquals(15, result.ordinal()); } /** diff --git a/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/model/TraceLogLevel.java b/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/model/TraceLogLevel.java index 70f1b00f3d..465312d84a 100644 --- a/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/model/TraceLogLevel.java +++ b/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/model/TraceLogLevel.java @@ -1,5 +1,5 @@ /********************************************************************** - * Copyright (c) 2012 Ericsson + * Copyright (c) 2012, 2014 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -8,13 +8,13 @@ * * Contributors: * Bernd Hufmann - Initial API and implementation + * Jonathan Rajotte - Utility function *********************************************************************/ package org.eclipse.linuxtools.internal.lttng2.control.core.model; + /** - *

* Log Level enumeration. - *

* * @author Bernd Hufmann */ @@ -71,7 +71,9 @@ public enum TraceLogLevel { /** * Private constructor - * @param name the name of state + * + * @param name + * the name of state */ private TraceLogLevel(String name) { fInName = name; @@ -86,4 +88,27 @@ public enum TraceLogLevel { public String getInName() { return fInName; } + + // ------------------------------------------------------------------------ + // Utility + // ------------------------------------------------------------------------ + /** + * Return the corresponding {@link TraceLogLevel} to String "name" + * + * @param name + * String to compare to retrieve the good {@link TraceLogLevel} + * @return the corresponding {@link TraceLogLevel} + */ + public static TraceLogLevel valueOfString(String name) { + if (name == null) { + throw new IllegalArgumentException(); + } + for (TraceLogLevel tllevel : TraceLogLevel.values()) { + if (tllevel.getInName().equalsIgnoreCase(name)) { + return tllevel; + } + } + // No match + return LEVEL_UNKNOWN; + } } diff --git a/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/model/impl/BaseEventInfo.java b/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/model/impl/BaseEventInfo.java index aee9493603..217891138c 100644 --- a/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/model/impl/BaseEventInfo.java +++ b/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/model/impl/BaseEventInfo.java @@ -121,41 +121,7 @@ public class BaseEventInfo extends TraceInfo implements IBaseEventInfo { @Override public void setLogLevel(String levelName) { - if(TraceLogLevel.TRACE_EMERG.getInName().equalsIgnoreCase(levelName)) { - fLogLevel = TraceLogLevel.TRACE_EMERG; - } else if(TraceLogLevel.TRACE_ALERT.getInName().equalsIgnoreCase(levelName)) { - fLogLevel = TraceLogLevel.TRACE_ALERT; - } else if(TraceLogLevel.TRACE_CRIT.getInName().equalsIgnoreCase(levelName)) { - fLogLevel = TraceLogLevel.TRACE_CRIT; - } else if(TraceLogLevel.TRACE_ERR.getInName().equalsIgnoreCase(levelName)) { - fLogLevel = TraceLogLevel.TRACE_ERR; - } else if(TraceLogLevel.TRACE_WARNING.getInName().equalsIgnoreCase(levelName)) { - fLogLevel = TraceLogLevel.TRACE_WARNING; - } else if(TraceLogLevel.TRACE_NOTICE.getInName().equalsIgnoreCase(levelName)) { - fLogLevel = TraceLogLevel.TRACE_NOTICE; - } else if(TraceLogLevel.TRACE_INFO.getInName().equalsIgnoreCase(levelName)) { - fLogLevel = TraceLogLevel.TRACE_INFO; - } else if(TraceLogLevel.TRACE_DEBUG_SYSTEM.getInName().equalsIgnoreCase(levelName)) { - fLogLevel = TraceLogLevel.TRACE_DEBUG_SYSTEM; - } else if(TraceLogLevel.TRACE_DEBUG_PROGRAM.getInName().equalsIgnoreCase(levelName)) { - fLogLevel = TraceLogLevel.TRACE_DEBUG_PROGRAM; - } else if(TraceLogLevel.TRACE_DEBUG_PROCESS.getInName().equalsIgnoreCase(levelName)) { - fLogLevel = TraceLogLevel.TRACE_DEBUG_PROCESS; - } else if(TraceLogLevel.TRACE_DEBUG_MODULE.getInName().equalsIgnoreCase(levelName)) { - fLogLevel = TraceLogLevel.TRACE_DEBUG_MODULE; - } else if(TraceLogLevel.TRACE_DEBUG_UNIT.getInName().equalsIgnoreCase(levelName)) { - fLogLevel = TraceLogLevel.TRACE_DEBUG_UNIT; - } else if(TraceLogLevel.TRACE_DEBUG_FUNCTION.getInName().equalsIgnoreCase(levelName)) { - fLogLevel = TraceLogLevel.TRACE_DEBUG_FUNCTION; - } else if(TraceLogLevel.TRACE_DEBUG_LINE.getInName().equalsIgnoreCase(levelName)) { - fLogLevel = TraceLogLevel.TRACE_DEBUG_LINE; - } else if(TraceLogLevel.TRACE_DEBUG.getInName().equalsIgnoreCase(levelName)) { - fLogLevel = TraceLogLevel.TRACE_DEBUG; - } else if(TraceLogLevel.LEVEL_UNKNOWN.getInName().equalsIgnoreCase(levelName)) { - fLogLevel = TraceLogLevel.LEVEL_UNKNOWN; - } else { - fLogLevel = TraceLogLevel.TRACE_DEBUG; - } + fLogLevel = TraceLogLevel.valueOfString(levelName); } @Override -- 2.34.1