KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > math > Base62Coder


1 /* ************************************************************************** *
2  * Copyright (C) 2004 NightLabs GmbH, Marco Schulze *
3  * All rights reserved. *
4  * http://www.NightLabs.de *
5  * *
6  * This program and the accompanying materials are free software; you can re- *
7  * distribute it and/or modify it under the terms of the GNU General Public *
8  * License as published by the Free Software Foundation; either ver 2 of the *
9  * License, or any later version. *
10  * *
11  * This module is distributed in the hope that it will be useful, but WITHOUT *
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FIT- *
13  * NESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more *
14  * details. *
15  * *
16  * You should have received a copy of the GNU General Public License along *
17  * with this module; if not, write to the Free Software Foundation, Inc.: *
18  * 59 Temple Place, Suite 330 *
19  * Boston MA 02111-1307 *
20  * USA *
21  * *
22  * Or get it online: *
23  * http://www.opensource.org/licenses/gpl-license.php *
24  * *
25  * In case, you want to use this module or parts of it in a proprietary pro- *
26  * ject, you can purchase it under the NightLabs Commercial License. Please *
27  * contact NightLabs GmbH under info AT nightlabs DOT com for more infos or *
28  * visit http://www.NightLabs.com *
29  * ************************************************************************** */

30
31 /*
32  * Created on May 18, 2005
33  */

34 package com.nightlabs.math;
35
36 /**
37  * @author Marco Schulze - marco at nightlabs dot de
38  */

39 public class Base62Coder
40 extends BaseNCoder
41 {
42     private static Base62Coder _sharedInstance = null;
43
44     /**
45      * You can either use your own instance or a shared instance of this class.
46      * It makes sense, to use the shared instance.
47      */

48     public static Base62Coder sharedInstance()
49     {
50         if (_sharedInstance == null)
51             _sharedInstance = new Base62Coder();
52
53         return _sharedInstance;
54     }
55
56     /**
57      * @param include09 Whether or not the symbols should include '0', '1'...'9'.
58      * If <tt>true</tt>, the first symbol will be '0' and the last 'T', if <tt>false</tt>,
59      * the range is 'A'..'Z'
60      */

61     public Base62Coder()
62     {
63         char[] symbols = new char[62];
64         char c = '0';
65         for (int i = 0; i < 10; ++i) {
66             symbols[i] = c++;
67         }
68         c = 'A';
69         for (int i = 10; i < 36; ++i) {
70             symbols[i] = c++;
71         }
72         c = 'a';
73         for (int i = 36; i < 62; ++i) {
74             symbols[i] = c++;
75         }
76
77         init(symbols);
78     }
79
80 }
81
Popular Tags