001/* 002 * JKNIV, whinstone one contract to access your database. 003 * 004 * Copyright (C) 2017, the original author or authors. 005 * 006 * This library is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU Lesser General Public 008 * License as published by the Free Software Foundation; either 009 * version 2.1 of the License. 010 * 011 * This library is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 * Lesser General Public License for more details. 015 * 016 * You should have received a copy of the GNU Lesser General Public 017 * License along with this library; if not, write to the Free Software Foundation, Inc., 018 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 019 */ 020package net.sf.jkniv.whinstone; 021 022/** 023 * Convert string names from <code>underscore</code> 024 * to <code>camel case</code> java attribute style, 025 * underscores or dashes which is skipped. 026 * 027 * <p>For example <tt>CUSTOMER_ID</tt> is mapped as <tt>customerId</tt>.</p> 028 * 029 * @author Alisson Gomes 030 */ 031public class UnderscoreToCamelCaseMapper implements JdbcColumnMapper 032{ 033 public String map(final String column) 034 { 035 StringBuilder sb = new StringBuilder(); 036 boolean toUpper = false; 037 char[] columnCopy = null; 038 if(column.indexOf(".") < 0) 039 columnCopy = column.toLowerCase().toCharArray(); 040 else 041 columnCopy = column.toCharArray(); 042 for (char ch : columnCopy) 043 { 044 char cased = ch; 045 if (ch == '_' || ch == '-') 046 { 047 toUpper = true; 048 continue; 049 } 050 if (toUpper) 051 { 052 cased = Character.toUpperCase(ch); 053 toUpper = false; 054 } 055 sb.append(cased); 056 } 057 return sb.toString(); 058 } 059}