mnaufaldillah

Priority Jmeter

Oct 23rd, 2021
484
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.log;
  19.  
  20. import java.io.Serializable;
  21.  
  22. /**
  23.  * Class representing and holding constants for priority.
  24.  *
  25.  * @author Peter Donald
  26.  * @deprecated Will be dropped in 3.3
  27.  */
  28. @Deprecated
  29. public final class Priority
  30.     implements Serializable
  31. {
  32.     private static final long serialVersionUID = 1L;
  33.  
  34.     /**
  35.      * Developer orientated messages, usually used during development of product.
  36.      */
  37.     public static final Priority DEBUG = new Priority( "DEBUG", 5 );
  38.  
  39.     /**
  40.      * Useful information messages such as state changes, client connection, user login etc.
  41.      */
  42.     public static final Priority INFO = new Priority( "INFO", 10 );
  43.  
  44.     /**
  45.      * A problem or conflict has occurred but it may be recoverable, then
  46.      * again it could be the start of the system failing.
  47.      */
  48.     public static final Priority WARN = new Priority( "WARN", 15 );
  49.  
  50.     /**
  51.      * A problem has occurred but it is not fatal. The system will still function.
  52.      */
  53.     public static final Priority ERROR = new Priority( "ERROR", 20 );
  54.  
  55.     /**
  56.      * Something caused whole system to fail. This indicates that an administrator
  57.      * should restart the system and try to fix the problem that caused the failure.
  58.      */
  59.     public static final Priority FATAL_ERROR = new Priority( "FATAL_ERROR", 25 );
  60.  
  61.     /**
  62.      * Do not log anything.
  63.      */
  64.     public static final Priority NONE = new Priority( "NONE", Integer.MAX_VALUE );
  65.  
  66.     private final String m_name;
  67.     private final int m_priority;
  68.  
  69.     /**
  70.      * Retrieve a Priority object for the name parameter.
  71.      *
  72.      * @param priority the priority name
  73.      * @return the Priority for name
  74.      */
  75.     public static Priority getPriorityForName( final String priority )
  76.     {
  77.         if( Priority.DEBUG.getName().equals( priority ) )
  78.         {
  79.             return Priority.DEBUG;
  80.         }
  81.         else if( Priority.INFO.getName().equals( priority ) )
  82.         {
  83.             return Priority.INFO;
  84.         }
  85.         else if( Priority.WARN.getName().equals( priority ) )
  86.         {
  87.             return Priority.WARN;
  88.         }
  89.         else if( Priority.ERROR.getName().equals( priority ) )
  90.         {
  91.             return Priority.ERROR;
  92.         }
  93.         else if( Priority.FATAL_ERROR.getName().equals( priority ) )
  94.         {
  95.             return Priority.FATAL_ERROR;
  96.         }
  97.         else if( Priority.NONE.getName().equals( priority ) )
  98.         {
  99.             return Priority.NONE;
  100.         }
  101.         else
  102.         {
  103.             return Priority.DEBUG;
  104.         }
  105.     }
  106.  
  107.     /**
  108.      * Private Constructor to block instantiation outside class.
  109.      *
  110.      * @param name the string name of priority
  111.      * @param priority the numerical code of priority
  112.      */
  113.     private Priority( final String name, final int priority )
  114.     {
  115.         if( null == name )
  116.         {
  117.             throw new NullPointerException( "name" );
  118.         }
  119.  
  120.         m_name = name;
  121.         m_priority = priority;
  122.     }
  123.  
  124.     /**
  125.      * Overridden string to display Priority in human readable form.
  126.      *
  127.      * @return the string describing priority
  128.      */
  129.     @Override
  130.     public String toString()
  131.     {
  132.         return "Priority[" + getName() + "/" + getValue() + "]";
  133.     }
  134.  
  135.     /**
  136.      * Get numerical value associated with priority.
  137.      *
  138.      * @return the numerical value
  139.      */
  140.     public int getValue()
  141.     {
  142.         return m_priority;
  143.     }
  144.  
  145.     /**
  146.      * Get name of priority.
  147.      *
  148.      * @return the priorities name
  149.      */
  150.     public String getName()
  151.     {
  152.         return m_name;
  153.     }
  154.  
  155.     /**
  156.      * Test whether this priority is greater than other priority.
  157.      *
  158.      * @param other the other Priority
  159.      * @return TRUE if the priority is greater else FALSE
  160.      */
  161.     public boolean isGreater( final Priority other )
  162.     {
  163.         return m_priority > other.getValue();
  164.     }
  165.  
  166.     /**
  167.      * Test whether this priority is lower than other priority.
  168.      *
  169.      * @param other the other Priority
  170.      * @return TRUE if the priority is lower else FALSE
  171.      */
  172.     public boolean isLower( final Priority other )
  173.     {
  174.         return m_priority < other.getValue();
  175.     }
  176.  
  177.     /**
  178.      * Test whether this priority is lower or equal to other priority.
  179.      *
  180.      * @param other the other Priority
  181.      * @return TRUE if the priority is lower or equal else FALSE
  182.      */
  183.     public boolean isLowerOrEqual( final Priority other )
  184.     {
  185.         return m_priority <= other.getValue();
  186.     }
  187.  
  188.     /**
  189.      * Helper method that replaces deserialized object with correct singleton.
  190.      *
  191.      * @return the singleton version of object
  192.      */
  193.     private Object readResolve()
  194.     {
  195.         return getPriorityForName( m_name );
  196.     }
  197. }
RAW Paste Data