| 1 | /********************************************************************** |
| 2 | * Copyright (c) 2012, 2014 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 | * Bernd Hufmann - Initial API and implementation |
| 11 | *********************************************************************/ |
| 12 | package org.eclipse.tracecompass.internal.lttng2.control.core.model; |
| 13 | |
| 14 | |
| 15 | /** |
| 16 | * Type of log Level enumeration. |
| 17 | * |
| 18 | * @author Bernd Hufmann |
| 19 | */ |
| 20 | public enum LogLevelType { |
| 21 | |
| 22 | // ------------------------------------------------------------------------ |
| 23 | // Enum definition |
| 24 | // ------------------------------------------------------------------------ |
| 25 | /** range of log levels [0,logLevel] */ |
| 26 | LOGLEVEL("<=", "RANGE"), //$NON-NLS-1$ //$NON-NLS-2$ |
| 27 | |
| 28 | /** all log level */ |
| 29 | LOGLEVEL_ALL("", "ALL"), //$NON-NLS-1$//$NON-NLS-2$ |
| 30 | |
| 31 | /** single log level */ |
| 32 | LOGLEVEL_ONLY("==", "SINGLE"), //$NON-NLS-1$ //$NON-NLS-2$ |
| 33 | |
| 34 | /** no log level */ |
| 35 | LOGLEVEL_NONE("", "UNKNOWN"); //$NON-NLS-1$ //$NON-NLS-2$ |
| 36 | |
| 37 | // ------------------------------------------------------------------------ |
| 38 | // Constuctors |
| 39 | // ------------------------------------------------------------------------ |
| 40 | |
| 41 | /** |
| 42 | * Private constructor |
| 43 | * |
| 44 | * @param name |
| 45 | * the name of state |
| 46 | */ |
| 47 | private LogLevelType(String shortName, String miName) { |
| 48 | fShortName = shortName; |
| 49 | fMiName = miName; |
| 50 | } |
| 51 | |
| 52 | // ------------------------------------------------------------------------ |
| 53 | // Attributes |
| 54 | // ------------------------------------------------------------------------ |
| 55 | /** |
| 56 | * Name of enum. |
| 57 | */ |
| 58 | private final String fShortName; |
| 59 | private final String fMiName; |
| 60 | |
| 61 | // ------------------------------------------------------------------------ |
| 62 | // Accessors |
| 63 | // ------------------------------------------------------------------------ |
| 64 | /** |
| 65 | * @return short string |
| 66 | */ |
| 67 | public String getShortName() { |
| 68 | return fShortName; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * @return machine interface name string |
| 73 | */ |
| 74 | public String getMiName() { |
| 75 | return fMiName; |
| 76 | } |
| 77 | |
| 78 | // ------------------------------------------------------------------------ |
| 79 | // Utility |
| 80 | // ------------------------------------------------------------------------ |
| 81 | /** |
| 82 | * Return the corresponding {@link LogLevelType} to String "name" |
| 83 | * |
| 84 | * @param name |
| 85 | * String to compare to retrieve the good LogLevelType |
| 86 | * @return the corresponding {@link LogLevelType} |
| 87 | */ |
| 88 | public static LogLevelType valueOfString(String name) { |
| 89 | if (name == null) { |
| 90 | throw new IllegalArgumentException(); |
| 91 | } |
| 92 | for (LogLevelType lltype : LogLevelType.values()) { |
| 93 | if (!lltype.equals(LOGLEVEL_NONE)) { |
| 94 | boolean isEqual = lltype.fShortName.equalsIgnoreCase(name) || lltype.fMiName.equalsIgnoreCase(name); |
| 95 | if (isEqual) { |
| 96 | return lltype; |
| 97 | } |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | // No match |
| 102 | return LogLevelType.LOGLEVEL_NONE; |
| 103 | } |
| 104 | } |