Java 17 Upgrade
[policy/models.git] / models-dao / src / main / java / org / onap / policy / models / dao / converters / CDataConditioner.java
index e4cfd74..f36ef58 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2019 Nordix Foundation.
+ *  Copyright (C) 2019, 2023 Nordix Foundation.
+ *  Modifications Copyright (C) 2021 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.
 
 package org.onap.policy.models.dao.converters;
 
-import javax.persistence.AttributeConverter;
-import javax.persistence.Converter;
-import javax.xml.bind.annotation.adapters.XmlAdapter;
+import com.google.re2j.Pattern;
+import jakarta.persistence.AttributeConverter;
+import jakarta.persistence.Converter;
+import jakarta.xml.bind.annotation.adapters.XmlAdapter;
 
 /**
  * The Class CDataConditioner converts a CDATA String to and from database format by removing spaces
@@ -31,6 +33,7 @@ import javax.xml.bind.annotation.adapters.XmlAdapter;
 @Converter
 public class CDataConditioner extends XmlAdapter<String, String> implements AttributeConverter<String, String> {
 
+    private static final Pattern TRAILING_SPACE_PAT = Pattern.compile("\\s+$");
     private static final String NL = "\n";
 
     @Override
@@ -59,11 +62,11 @@ public class CDataConditioner extends XmlAdapter<String, String> implements Attr
      * @param in the in
      * @return the string
      */
-    public static final String clean(final String in) {
+    public static String clean(final String in) {
         if (in == null) {
             return null;
         } else {
-            return in.replaceAll("\\s+$", "").replaceAll("\\r?\\n", NL);
+            return TRAILING_SPACE_PAT.matcher(in).replaceAll("").replaceAll("\\r?\\n", NL);
         }
     }
 }