Coverage Report - org.kuali.student.contract.writer.JavaEnumConstantCalculator
 
Classes in this File Line Coverage Branch Coverage Complexity
JavaEnumConstantCalculator
0%
0/29
0%
0/12
3
 
 1  
 /*
 2  
  * Copyright 2010 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may        obtain a copy of the License at
 7  
  *
 8  
  *         http://www.osedu.org/licenses/ECL-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.student.contract.writer;
 17  
 
 18  
 /**
 19  
  *
 20  
  * @author nwright
 21  
  */
 22  
 public class JavaEnumConstantCalculator
 23  
 {
 24  
 
 25  
  private String name;
 26  
 
 27  
  public JavaEnumConstantCalculator (String name)
 28  0
  {
 29  0
   this.name = name;
 30  0
  }
 31  
 
 32  
  public String calc ()
 33  
  {
 34  0
   StringBuilder buf = new StringBuilder (name.length () + 3);
 35  
   // do the first character so we don't prepend the first with a _ if it is upper
 36  0
   char c = Character.toUpperCase (name.charAt (0));
 37  0
   buf.append (c);
 38  0
   boolean lastUpper = Character.isUpperCase (c);
 39  0
   for (int i = 1; i < name.length (); i ++)
 40  
   {
 41  0
    c = name.charAt (i);
 42  0
    if (Character.isUpperCase (c))
 43  
    {
 44  0
     if ( ! lastUpper)
 45  
     {
 46  0
      buf.append ('_');
 47  
     }
 48  0
     lastUpper = true;
 49  
    }
 50  
    else
 51  
    {
 52  0
     lastUpper = false;
 53  
    }
 54  
 
 55  0
    buf.append (Character.toUpperCase (c));
 56  
   }
 57  
 
 58  0
   return buf.toString ();
 59  
  }
 60  
 
 61  
  public String reverse ()
 62  
  {
 63  0
   StringBuffer buf = new StringBuffer (name.length ());
 64  0
   boolean uppercase = true;
 65  0
   for (int i = 0; i < name.length (); i ++)
 66  
   {
 67  0
    char c = name.charAt (i);
 68  0
    if (uppercase)
 69  
    {
 70  0
     c = Character.toUpperCase (c);
 71  0
     uppercase = false;
 72  
    }
 73  
    else
 74  
    {
 75  0
     c = Character.toLowerCase (c);
 76  
    }
 77  0
    if (c == '_')
 78  
    {
 79  0
     uppercase = true;
 80  0
     continue;
 81  
    }
 82  0
    buf.append (c);
 83  
   }
 84  
 
 85  0
   return buf.toString ();
 86  
  }
 87  
 
 88  
 }