|
| 1 | +/*- |
| 2 | + * #%L |
| 3 | + * Grid Helpers Add-on |
| 4 | + * %% |
| 5 | + * Copyright (C) 2022 - 2025 Flowing Code |
| 6 | + * %% |
| 7 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | + * you may not use this file except in compliance with the License. |
| 9 | + * You may obtain a copy of the License at |
| 10 | + * |
| 11 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | + * |
| 13 | + * Unless required by applicable law or agreed to in writing, software |
| 14 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | + * See the License for the specific language governing permissions and |
| 17 | + * limitations under the License. |
| 18 | + * #L% |
| 19 | + */ |
| 20 | +package com.flowingcode.vaadin.addons.gridhelpers; |
| 21 | + |
| 22 | +import lombok.experimental.UtilityClass; |
| 23 | + |
| 24 | +/* |
| 25 | + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license |
| 26 | + * agreements. See the NOTICE file distributed with this work for additional information regarding |
| 27 | + * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the |
| 28 | + * "License"); you may not use this file except in compliance with the License. You may obtain a |
| 29 | + * copy of the License at |
| 30 | + * |
| 31 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 32 | + * |
| 33 | + * Unless required by applicable law or agreed to in writing, software distributed under the License |
| 34 | + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
| 35 | + * or implied. See the License for the specific language governing permissions and limitations under |
| 36 | + * the License. |
| 37 | + */ |
| 38 | + |
| 39 | +@UtilityClass |
| 40 | +class StringUtils { |
| 41 | + |
| 42 | + /** |
| 43 | + * Removes control characters from both ends of this String returning {@code null} if the String |
| 44 | + * is empty ("") after the trim or if it is {@code null}. |
| 45 | + * |
| 46 | + * <pre> |
| 47 | + * StringUtils.trimToNull(null) = null |
| 48 | + * StringUtils.trimToNull("") = null |
| 49 | + * StringUtils.trimToNull(" ") = null |
| 50 | + * StringUtils.trimToNull("abc") = "abc" |
| 51 | + * StringUtils.trimToNull(" abc ") = "abc" |
| 52 | + * </pre> |
| 53 | + * |
| 54 | + * @param str the String to be trimmed, may be null |
| 55 | + * @return the trimmed String, {@code null} if only chars <= 32, empty or null String input |
| 56 | + */ |
| 57 | + static String trimToNull(String str) { |
| 58 | + if (str == null) { |
| 59 | + return null; |
| 60 | + } |
| 61 | + str = str.trim(); |
| 62 | + if (str.isEmpty()) { |
| 63 | + return null; |
| 64 | + } |
| 65 | + return str; |
| 66 | + } |
| 67 | + |
| 68 | +} |
0 commit comments