📄 Update year in copyright line
[jSite.git] / src / main / java / de / todesbaum / util / freenet / fcp2 / PriorityClass.java
1 /*
2  * jSite - PriorityClass.java - Copyright Â© 2006–2019 David Roden
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  */
18
19 package de.todesbaum.util.freenet.fcp2;
20
21 /**
22  * The possible priority classes. Possible values are, in order of descending
23  * priority: <code>maximum</code> (anything more important than fproxy),
24  * <code>interactive</code> (fproxy), <code>semi-interactive</code> (fproxy
25  * immediate mode large file downloads, not to disk), <code>updatable</code>
26  * (updatable site checks), <code>bulk</code> (large file downloads to disk),
27  * <code>prefetch</code>, <code>minimum</code>.
28  *
29  * @author David Roden &lt;droden@gmail.com&gt;
30  * @version $Id$
31  */
32 public final class PriorityClass {
33
34         /** Denotes <code>maximum</code> priority class. */
35         public static final PriorityClass MAXIMUM = new PriorityClass("maximum", 0);
36
37         /** Denotes <code>interactive</code> priority class. */
38         public static final PriorityClass INTERACTIVE = new PriorityClass("interactive", 1);
39
40         /** Denotes <code>semi-interactive</code> priority class. */
41         public static final PriorityClass SEMI_INTERACTIVE = new PriorityClass("semiInteractive", 2);
42
43         /** Denotes <code>updatable</code> priority class. */
44         public static final PriorityClass UPDATABLE = new PriorityClass("updatable", 3);
45
46         /** Denotes <code>bulk</code> priority class. */
47         public static final PriorityClass BULK = new PriorityClass("bulk", 4);
48
49         /** Denotes <code>prefetch</code> priority class. */
50         public static final PriorityClass PREFETCH = new PriorityClass("prefetch", 5);
51
52         /** Denotes <code>minimum</code> priority class. */
53         public static final PriorityClass MINIMUM = new PriorityClass("minimum", 6);
54
55         /** The name of the priority class. */
56         private String name;
57
58         /** The value of the priority class. */
59         private int value;
60
61         /**
62          * Creates a new priority class with the specified name and value.
63          *
64          * @param name
65          *            The name of the priority class
66          * @param value
67          *            The value of the priority class
68          */
69         private PriorityClass(String name, int value) {
70                 this.name = name;
71                 this.value = value;
72         }
73
74         /**
75          * Returns the name of this priority class.
76          *
77          * @return The name of this priority class
78          */
79         public String getName() {
80                 return name;
81         }
82
83         /**
84          * Returns the value of this priority class.
85          *
86          * @return The value of this priority class
87          */
88         public int getValue() {
89                 return value;
90         }
91
92         //
93         // STATIC METHODS
94         //
95
96         /**
97          * Returns the priority class with the given name, matched case-insensitive.
98          *
99          * @param value
100          *            The name of the priority
101          * @return The priority with the given name, or {@code null} if no priority
102          *         matches the given name
103          */
104         public static PriorityClass valueOf(String value) {
105                 for (PriorityClass priorityClass : new PriorityClass[] { MINIMUM, PREFETCH, BULK, UPDATABLE, SEMI_INTERACTIVE, INTERACTIVE, MAXIMUM }) {
106                         if (priorityClass.getName().equalsIgnoreCase(value)) {
107                                 return priorityClass;
108                         }
109                 }
110                 return null;
111         }
112
113         //
114         // OBJECT METHODS
115         //
116
117         /**
118          * {@inheritDoc}
119          */
120         @Override
121         public String toString() {
122                 return name;
123         }
124
125 }