View Javadoc
1   package org.kuali.ole.sip2.common;
2   
3   import java.util.Currency;
4   import java.util.Locale;
5   
6   /**
7    * Created by gayathria on 15/12/14.
8    */
9   public class OLESIP2Util {
10  
11      /*
12      Used to get default currency instance
13       */
14  
15      public static Currency getDefaultCurrency() {
16          return Currency.getInstance(Locale.getDefault());
17      }
18  
19      /**
20       * Converts the given boolean to string. false = 0, true = 1.
21       *
22       * @param value boolean value
23       * @return false = 0, true = 1
24       */
25      public static String bool2Int(boolean value) {
26          if (value) {
27              return "1";
28          }
29          return "0";
30      }
31  
32      /**
33       * Converts the given boolean to character. false = N, true = Y.
34       *
35       * @param value boolean value
36       * @return false = N, true = Y
37       */
38      public static String bool2Char(boolean value) {
39          if (value) {
40              return "Y";
41          }
42          return "N";
43      }
44  
45      /**
46       * Converts the given boolean to character. false = ' ', true = 'Y'.
47       *
48       * @param value boolean value
49       * @return false = ' ', true = 'Y'
50       */
51      public static String bool2CharEmpty(boolean value) {
52          if (value) {
53              return "Y";
54          }
55          return " ";
56      }
57  
58      /**
59       * Converts the given integer to a fixed length string by adding
60       * leading zeros to the given number that its length equals to the
61       * given length.
62       *
63       * @param value  integer value to be converted
64       * @param length length of the output string
65       * @return string presentation of the given integer
66       */
67      public static String intToFixedLengthString(int value, int length) {
68          return String.format("%0" + length + "d", value);
69      }
70  }