1 package org.wcb.autohome.factories;
2
3 /***
4 * Copyright (C) 1999 Walter Bogaardt
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19 *
20 * Project: Alice X10 Home Automation
21 */
22 import org.wcb.autohome.interfaces.X10DeviceConstants;
23
24 /***
25 * Project: Alice X10 Home Automation
26 * Filename: $Id: FactoryUtilities.java,v 1.3 2004/02/25 21:38:36 wbogaardt Exp $
27 * Abstract: This class is a consolidation of methods that have been commonly called
28 * throught the application rather than keeping reimplementing the same function
29 * over and over.
30 *@author wbogaardt
31 *@version 1.0
32 */
33 public class FactoryUtilities implements X10DeviceConstants {
34
35 /***
36 * Takes a string and returns the first
37 * character in that string as a char value.
38 * @param val the String to get the house code from
39 * @return The character of the first position in the string (Defaults to 'A');
40 */
41 public static char getHouseCode(String val) {
42 char returnVal = 'A';
43 try
44 {
45 returnVal = val.charAt(0);
46 }
47 catch (Exception err)
48 {
49 returnVal = 'A';
50 }
51 return returnVal;
52 }
53
54 /***
55 * Takes a String representation of something like
56 * A1 and parses the integer from the string.
57 * If the entered integers
58 * are greater than 16 then 16 is returned;
59 * @param val the String value to get the device code from.
60 * @return the device code defaults to 1 or 16.
61 */
62 public static int getDeviceCode(String val) {
63 int returnVal = 0;
64 try
65 {
66 returnVal = Integer.parseInt(val.substring(1));
67 }
68 catch (NumberFormatException err)
69 {
70 return 1;
71 }
72 if (returnVal > 16)
73 {
74 returnVal = 16;
75 }
76 return returnVal;
77 }
78
79 /***
80 * Gets the integer value from a string
81 * @param value The string to get the integer from
82 * @return The int otherwise a default value of 1
83 */
84 public static int getIntValue(String value) {
85 try
86 {
87 return Integer.parseInt(value);
88 }
89 catch (NumberFormatException nfe)
90 {
91 return 1;
92 }
93 }
94 }
95