Here you can find the source of castToBoolean(String fieldValue)
Parameter | Description |
---|---|
fieldValue | the value of the boolean string field |
public static boolean castToBoolean(String fieldValue)
//package com.java2s; /*//from w w w . j av a 2s .c o m * Copyright (C) 2014-2016 LinkedIn Corp. All rights reserved. * * 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. */ public class Main { /** * Cast a string representation of a boolean value to a boolean primitive. * Used especially for Oracle representation of booleans as varchar2(1) * Returns true for values such as [t|true|yes|1] and false for [f|false|no]. * If a boolean value cannot be trivially parsed, false is returned. * * @param fieldValue the value of the boolean string field */ public static boolean castToBoolean(String fieldValue) { String lowerField = fieldValue.toLowerCase(); switch (lowerField) { case "y": return true; case "n": return false; case "true": return true; case "false": return false; case "t": return true; case "f": return false; case "yes": return true; case "no": return false; case "0": return false; case "1": return true; } return false; } }