Mass removal of all Tabs (Style Warnings)
[aaf/authz.git] / misc / env / src / main / java / org / onap / aaf / misc / env / util / Split.java
index 79a7403..4069c32 100644 (file)
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-package org.onap.aaf.misc.env.util;
-
-/**
- * Split by Char, optional Trim
- * 
- * Note: I read the String split and Pattern split code, and we can do this more efficiently for a single Character
- * 
- * Jonathan 8/20/2015
- */
-
-public class Split {
-         public static String[] split(char c, String value) {
-                 // Count items to preallocate Array (memory alloc is more expensive than counting twice)
-                 int count,idx;
-                 for(count=1,idx=value.indexOf(c);idx>=0;idx=value.indexOf(c,++idx),++count);
-                 String[] rv = new String[count];
-                 if(count==1) {
-                         rv[0]=value;
-                 } else {
-                         int last=0;
-                         count=-1;
-                         for(idx=value.indexOf(c);idx>=0;idx=value.indexOf(c,idx)) {
-                                 rv[++count]=value.substring(last,idx);
-                                 last = ++idx;
-                         }
-                         rv[++count]=value.substring(last);
-                 }
-                 return rv;
-         }
-
-         public static String[] splitTrim(char c, String value) {
-                 // Count items to preallocate Array (memory alloc is more expensive than counting twice)
-                 int count,idx;
-                 for(count=1,idx=value.indexOf(c);idx>=0;idx=value.indexOf(c,++idx),++count);
-                 String[] rv = new String[count];
-                 if(count==1) {
-                         rv[0]=value.trim();
-                 } else {
-                         int last=0;
-                         count=-1;
-                         for(idx=value.indexOf(c);idx>=0;idx=value.indexOf(c,idx)) {
-                                 rv[++count]=value.substring(last,idx).trim();
-                                 last = ++idx;
-                         }
-                         rv[++count]=value.substring(last).trim();
-                 }
-                 return rv;
-         }
-
-         public static String[] splitTrim(char c, String value, int size) {
-                 int idx;
-                 String[] rv = new String[size];
-                 if(size==1) {
-                         rv[0]=value.trim();
-                 } else {
-                         int last=0;
-                         int count=-1;
-                         size-=2;
-                         for(idx=value.indexOf(c);idx>=0 && count<size;idx=value.indexOf(c,idx)) {
-                                 rv[++count]=value.substring(last,idx).trim();
-                                 last = ++idx;
-                         }
-                         rv[++count]=value.substring(last).trim();
-                 }
-                 return rv;
-         }
-
-}
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+package org.onap.aaf.misc.env.util;\r
+\r
+/**\r
+ * Split by Char, optional Trim\r
+ * \r
+ * Note: I read the String split and Pattern split code, and we can do this more efficiently for a single Character\r
+ * \r
+ * Jonathan 8/20/2015\r
+ */\r
+\r
+public class Split {\r
+      private static final String[] BLANK = new String[0];\r
+      \r
+      public static String[] split(char c, String value) {\r
+          if(value==null) {\r
+              return BLANK;\r
+          }\r
+\r
+          // Count items to preallocate Array (memory alloc is more expensive than counting twice)\r
+          int count,idx;\r
+          for(count=1,idx=value.indexOf(c);idx>=0;idx=value.indexOf(c,++idx),++count);\r
+          String[] rv = new String[count];\r
+          if(count==1) {\r
+              rv[0]=value;\r
+          } else {\r
+              int last=0;\r
+              count=-1;\r
+              for(idx=value.indexOf(c);idx>=0;idx=value.indexOf(c,idx)) {\r
+                  rv[++count]=value.substring(last,idx);\r
+                  last = ++idx;\r
+              }\r
+              rv[++count]=value.substring(last);\r
+          }\r
+          return rv;\r
+      }\r
+\r
+      public static String[] splitTrim(char c, String value) {\r
+          if(value==null) {\r
+              return BLANK;\r
+          }\r
+          // Count items to preallocate Array (memory alloc is more expensive than counting twice)\r
+          int count,idx;\r
+          for(count=1,idx=value.indexOf(c);idx>=0;idx=value.indexOf(c,++idx),++count);\r
+          String[] rv = new String[count];\r
+          if(count==1) {\r
+              rv[0]=value.trim();\r
+          } else {\r
+              int last=0;\r
+              count=-1;\r
+              for(idx=value.indexOf(c);idx>=0;idx=value.indexOf(c,idx)) {\r
+                  rv[++count]=value.substring(last,idx).trim();\r
+                  last = ++idx;\r
+              }\r
+              rv[++count]=value.substring(last).trim();\r
+          }\r
+          return rv;\r
+      }\r
+\r
+      public static String[] splitTrim(char c, String value, int size) {\r
+          if(value==null) {\r
+              return BLANK;\r
+          }\r
+\r
+          int idx;\r
+          String[] rv = new String[size];\r
+          if(size==1) {\r
+              rv[0]=value.trim();\r
+          } else {\r
+              int last=0;\r
+              int count=-1;\r
+              size-=2;\r
+              for(idx=value.indexOf(c);idx>=0 && count<size;idx=value.indexOf(c,idx)) {\r
+                  rv[++count]=value.substring(last,idx).trim();\r
+                  last = ++idx;\r
+              }\r
+              rv[++count]=value.substring(last).trim();\r
+          }\r
+          return rv;\r
+      }\r
+\r
+}\r