Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * Copyright 2007 Daniel Spiewak
  * 
  * Licensed under the Apache License, Version 2.0 (the "License"); 
  * you may not use this file except in compliance with the License. 
  * You may obtain a copy of the License at
  * 
  *	    http://www.apache.org/licenses/LICENSE-2.0 
  * 
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.java.ao.schema;
import static com.google.common.base.Preconditions.*;
import static net.java.ao.schema.UnderScoreUtils.*;

Imposes an underscore word-separation convention upon field names. This will convert field in the following way:

Method NameReturns Entity?Field Name
getFirstNamefalsefirst_name
setLastNamefalselast_name
getCompanytruecompany_id
isCoolfalsecool

This converter allows for both all-lowercase and all-uppercase field name conventions. For example, depending on the configuration, getLastName may convert to "LAST_NAME".

This converter is all that is required to emulate the ActiveRecord field name conversion.

Author(s):
Daniel Spiewak
    private final Case fieldNameCase;

    
Creates a new field name converter in which all field names will be either fully uppercase or fully lowercase.

Parameters:
fieldNameCase the case to use for field names
    public UnderscoreFieldNameConverter(Case fieldNameCase)
    {
        this. = checkNotNull(fieldNameCase);
    }
    public UnderscoreFieldNameConverter(Case fieldNameCaseList<FieldNameResolverfieldNameResolvers)
    {
        super(fieldNameResolvers);
        this. = checkNotNull(fieldNameCase);
    }
    @Override
    public String convertName(String name)
    {
        return .apply(camelCaseToUnderScore(name));
    }
New to GrepCode? Check out our FAQ X