History

Added GridSolutionsFramework.sln to source control.

StephenCWills committed 14 years ago

Commit c5f7ca6No parent (first commit)915 files · +335125 −-73Browse files

Showing the changes to Source/Libraries/TSFJavaLibrary/src/org/gpa/tsf/util/StringExtensions.java (1 of 915 files). Show all

Unified · Split

Source/Libraries/TSFJavaLibrary/src/org/gpa/tsf/util/StringExtensions.java+88−0
@@ -0,0 +1,88 @@
1+//******************************************************************************************************
2+// StringExtensions.java - Gbtc
3+//
4+// Copyright � 2010, Grid Protection Alliance. All Rights Reserved.
5+//
6+// Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
7+// the NOTICE file distributed with this work for additional information regarding copyright ownership.
8+// The GPA licenses this file to you under the Eclipse Public License -v 1.0 (the "License"); you may
9+// not use this file except in compliance with the License. You may obtain a copy of the License at:
10+//
11+// http://www.opensource.org/licenses/eclipse-1.0.php
12+//
13+// Unless agreed to in writing, the subject software distributed under the License is distributed on an
14+// "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the
15+// License for the specific language governing permissions and limitations.
16+//
17+// Code Modification History:
18+// ----------------------------------------------------------------------------------------------------
19+// 04/18/2012 - Stephen C. Wills
20+// Generated original version of source code.
21+//
22+//******************************************************************************************************
23+
24+package org.gpa.tsf.util;
25+
26+/**
27+ * Utility class that provides additional functionality for strings.
28+ */
29+public class StringExtensions
30+{
31+ /**
32+ * Determines whether the given string is null or the empty string.
33+ *
34+ * @param str the string to be checked
35+ * @return true if the string is null or empty; false otherwise
36+ */
37+ public static boolean isNullOrEmpty(String str)
38+ {
39+ return (str == null) || str.isEmpty();
40+ }
41+
42+ /**
43+ * Determines whether the given string is null or contains
44+ * nothing but whitespace characters.
45+ *
46+ * @param str the string to be checked
47+ * @return true if the string is null or whitespace; false otherwise
48+ */
49+ public static boolean isNullOrWhitespace(String str)
50+ {
51+ return (str == null) || str.trim().isEmpty();
52+ }
53+
54+ /**
55+ * Converts null strings to the empty string. If a string is provided
56+ * which is not null, no operation is performed and the string is
57+ * returned as-is.
58+ *
59+ * @param str the string to be checked
60+ * @return the empty string if the parameter is null; otherwise the
61+ * parameter itself is returned
62+ */
63+ public static String toNonNull(String str)
64+ {
65+ return toNonNull(str, "");
66+ }
67+
68+ /**
69+ * Converts null strings to the given default string value. If a
70+ * string is provided which is not null, no operation is performed
71+ * and the string is returned as-is.
72+ *
73+ * @param str the string to be checked
74+ * @param defaultValue the default value to return if the provided
75+ * string happens to be null
76+ * @return the default value if the first parameter is null; otherwise
77+ * the first parameter itself is returned
78+ */
79+ public static String toNonNull(String str, String defaultValue)
80+ {
81+ if (str != null)
82+ return str;
83+ else if (defaultValue != null)
84+ return defaultValue;
85+ else
86+ return "";
87+ }
88+}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t