To Identifier String : Identifier « Reflection « Java

Home
Java
1.2D Graphics GUI
2.3D
3.Advanced Graphics
4.Ant
5.Apache Common
6.Chart
7.Class
8.Collections Data Structure
9.Data Type
10.Database SQL JDBC
11.Design Pattern
12.Development Class
13.EJB3
14.Email
15.Event
16.File Input Output
17.Game
18.Generics
19.GWT
20.Hibernate
21.I18N
22.J2EE
23.J2ME
24.JavaFX
25.JDK 6
26.JDK 7
27.JNDI LDAP
28.JPA
29.JSP
30.JSTL
31.Language Basics
32.Network Protocol
33.PDF RTF
34.Reflection
35.Regular Expressions
36.Scripting
37.Security
38.Servlets
39.Spring
40.Swing Components
41.Swing JFC
42.SWT JFace Eclipse
43.Threads
44.Tiny Application
45.Velocity
46.Web Services SOA
47.XML
Java » Reflection » Identifier 




To Identifier String
     
/*
 * Copyright 2000,2005 wingS development team.
 *
 * This file is part of wingS (http://wingsframework.org).
 *
 * wingS is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2.1
 * of the License, or (at your option) any later version.
 *
 * Please see COPYING for the complete licence.
 */

import java.util.StringTokenizer;

/**
 * Some string manipulation utilities.
 *
 @author <a href="mailto:[email protected]">Armin Haaf</a>
 */
public class StringUtil {

  private final static char[] ALPHAS = {
      'a''b',
      'c''d''e''f''g''h',
      'i''j''k''l''m''n',
      'o''p''q''r''s''t',
      'u''v''w''x''y''z',
  };

  /**
   * All possible digits for representing a number as a String
   * This is conservative and does not include 'special'
   * characters since some browsers don't handle them right.
   * The IE for instance seems to be case insensitive in class
   * names for CSSs. Grrr.
   */
  private final static char[] DIGITS = {
      '0''1''2''3''4''5',
      '6''7''8''9''a''b',
      'c''d''e''f''g''h',
      'i''j''k''l''m''n',
      'o''p''q''r''s''t',
      'u''v''w''x''y''z',
      /* This %@&!-IE is case insensitive for certain
       * URLs and IDs
       * 'A' , 'B' ,
       * 'C' , 'D' , 'E' , 'F' , 'G' , 'H' ,
       * 'I' , 'J' , 'K' , 'L' , 'M' , 'N' ,
       * 'O' , 'P' , 'Q' , 'R' , 'S' , 'T' ,
       * 'U' , 'V' , 'W' , 'X' , 'Y' , 'Z'
       */
  };

  public static final int MAX_RADIX = DIGITS.length;

  /**
   * creates a shortest possible string representation of the given
   * long number that qualifies as an identifier in common programming
   * languages (and HTML-id's :-)
   * That is, it must start with a letter.
   *
   @param val the long value to be encoded
   @return a string represantation of the given value that qualifies
   *         as an identifier.
   */
  public static String toIdentifierString(long val) {
      char buf[] new char[14];
      int i = 0;
      if (val < 0) {
          buf[i++'_';
          val = -(val + 1);
      }
      buf[i++= ALPHAS[(int) (val % ALPHAS.length)];
      val /= ALPHAS.length;
      while (val != && i < buf.length) {
          buf[i++= DIGITS[(int) (val % DIGITS.length)];
          val /= DIGITS.length;
      }
      return new String(buf, 0, i);
  }

  
}

   
    
    
    
    
  














Related examples in the same category
1.Is Java Identifier and get Java Identifier
2.Escape Java Literal
3.Check whether the given String is a valid identifier according to the Java Language specifications.
4.Determine whether the supplied string represents a well-formed fully-qualified Java classname.
5.Determines if the specified string is permissible as a Java identifier.
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.