Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed to STRATIO (C) under one or more contributor license agreements.
   * See the NOTICE file distributed with this work for additional information
   * regarding copyright ownership.  The STRATIO (C) licenses this file
   * to you 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 com.stratio.connector.commons.util;
 
 
This class is a helper for CrossData ColumnType Created by jmgomez on 24/10/14.
 
 public final class ColumnTypeHelper {

    
The Log.
 
     static final transient Logger LOGGER = LoggerFactory.getLogger(SelectorHelper.class);

    
Constructor.
 
     private ColumnTypeHelper() {
     }

    
Return a casting value adapt to columntType.

Parameters:
columnType the columnType.
value the value.
Returns:
the casting value.
Throws:
com.stratio.crossdata.common.exceptions.ExecutionException if the casting is not possible.
 
     public static Object getCastingValue(ColumnType columnTypeObject valuethrows ExecutionException {
         validateInput(columnType);
         Object returnValue = null;
         if (value != null) {
             switch (columnType) {
 
             case :
                 ensureNumber(value);
                 returnValue = ((Numbervalue).longValue();
                 break;
             case :
                 ensureNumber(value);
                 returnValue = ((Numbervalue).doubleValue();
                 break;
             case :
                 ensureNumber(value);
                 returnValue = ((Numbervalue).floatValue();
                 break;
             case :
                 ensureNumber(value);
                 returnValue = ((Numbervalue).intValue();
                 break;
             default:
                 returnValue = value;
 
             }
         }
 
         return returnValue;
     }

    
This method validate the Input.

Parameters:
columnType the columnType.
Throws:
com.stratio.crossdata.common.exceptions.ExecutionException if a exception happens.
 
     private static void validateInput(ColumnType columnTypethrows ExecutionException {
         if (columnType==null){
             String messagge = "The ColumnType can not be null.";
             .error(messagge);
             throw new ExecutionException(messagge);
         }
     }

    
check if a object is a number.

Parameters:
value the objet.
Returns:
true if is a number false in other case.
    private static boolean isNumber(Object value) {
        return Number.class.isAssignableFrom(value.getClass());
    }

    
Ensure if a object is a number.

Parameters:
value the objet.
Throws:
com.stratio.crossdata.common.exceptions.ExecutionException if is not a number.
    private static void ensureNumber(Object valuethrows ExecutionException {
        if (!isNumber(value)) {
            String message = value.getClass().getCanonicalName() + " can not cast to a Number.";
            .error(message);
            throw new ExecutionException(message);
        }
    }
New to GrepCode? Check out our FAQ X