001/* 002 * oauth2-oidc-sdk 003 * 004 * Copyright 2012-2016, Connect2id Ltd and contributors. 005 * 006 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use 007 * this file except in compliance with the License. You may obtain a copy of the 008 * License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software distributed 013 * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 014 * CONDITIONS OF ANY KIND, either express or implied. See the License for the 015 * specific language governing permissions and limitations under the License. 016 */ 017 018package com.nimbusds.oauth2.sdk.util; 019 020 021/** 022 * String utilities. Replicates Apache Commons Lang 3. 023 */ 024public final class StringUtils { 025 026 027 /** 028 * Returns {@code true} if the specified char sequence is all blank, 029 * empty or {@code null}. 030 * 031 * @param cs The char sequence. May be {@code null}. 032 * 033 * @return {@code true} if the specified char sequence is all blank, 034 * empty or {@code null}, else {@code false}. 035 */ 036 public static boolean isBlank(CharSequence cs) { 037 038 int strLen; 039 if (cs != null && (strLen = cs.length()) != 0) { 040 for(int i = 0; i < strLen; ++i) { 041 if (!Character.isWhitespace(cs.charAt(i))) { 042 return false; 043 } 044 } 045 046 return true; 047 } else { 048 return true; 049 } 050 } 051 052 053 /** 054 * Returns {@code true} if the specified char sequence is not all 055 * blank, not empty and not {@code null}. 056 * 057 * @param cs The char sequence. May be {@code null}. 058 * 059 * @return {@code true} if the specified char sequence is not all 060 * blank, not empty and not {@code null}, else {@code false}. 061 */ 062 public static boolean isNotBlank(CharSequence cs) { 063 064 return !isBlank(cs); 065 } 066 067 068 /** 069 * Prevents public instantiation. 070 */ 071 private StringUtils() {} 072}