Render format enum added
authorAlex Kirhenshtein <alk@netxms.org>
Thu, 27 Jun 2013 14:52:30 +0000 (14:52 +0000)
committerAlex Kirhenshtein <alk@netxms.org>
Thu, 27 Jun 2013 14:52:30 +0000 (14:52 +0000)
src/java/netxms-client-api/src/main/java/org/netxms/api/client/reporting/ReportRenderFormat.java

index cd188b0..8179a92 100644 (file)
  * You should have received a copy of the GNU General Public License\r
  * along with this program; if not, write to the Free Software\r
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
- */package org.netxms.api.client.reporting;\r
+ */\r
+package org.netxms.api.client.reporting;\r
+\r
+import java.util.EnumSet;\r
+import java.util.HashMap;\r
+import java.util.Map;\r
 \r
 /**\r
  * Formats for report rendering\r
  */\r
 public enum ReportRenderFormat\r
 {\r
-       PDF(1, "pdf"),\r
-       XLS(2, "xls");\r
-       \r
+       PDF(1, "pdf"), XLS(2, "xls");\r
+\r
        private final int code;\r
-       private final String extension; \r
-       \r
+       private final String extension;\r
+\r
+       private static final Map<Integer, ReportRenderFormat> lookupTable = new HashMap<Integer, ReportRenderFormat>(2);\r
+\r
+       static\r
+       {\r
+               for(ReportRenderFormat element : EnumSet.allOf(ReportRenderFormat.class))\r
+               {\r
+                       lookupTable.put(element.getCode(), element);\r
+               }\r
+       }\r
+\r
        /**\r
         * @param code\r
         * @param extenstion\r
@@ -46,6 +60,14 @@ public enum ReportRenderFormat
                return code;\r
        }\r
 \r
+       /**\r
+        * Get by code\r
+        */\r
+       public static final ReportRenderFormat valueOf(Integer code)\r
+       {\r
+               return lookupTable.containsKey(code) ? lookupTable.get(code) : PDF;\r
+       }\r
+\r
        /**\r
         * @return the extension\r
         */\r