com.mark59.datahunter.api.application.DataHunterUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mark59-datahunter-api Show documentation
Show all versions of mark59-datahunter-api Show documentation
REST Api for the Mark59 DataHunter Web Application
The newest version!
/*
* Copyright 2019 Mark59.com
*
* 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.
*/
package com.mark59.datahunter.api.application;
import java.util.Map;
import java.util.Map.Entry;
/**
* General utilities for DataHunter:
*
* @author Philip Webb
* Written: Australian Autumn 2022
*
*/
public class DataHunterUtils {
/**
* Check if a string is empty.
*
* @param s String being checked
* @return true if null or blank, otherwise true
*/
public static boolean isEmpty(final String s) {
return s == null || s.trim().isEmpty();
}
/**
* Convenience method to print out a Map
*
* @param Map entry key
* @param Map entry value
* @param map map to pretty print
* @return formatted string representation of the map
*/
public static String prettyPrintMap (final Map map) {
String prettyOut = "\n ------------------------------- ";
if (map != null && !map.isEmpty() ){
for (Entry mapEntry: map.entrySet()) {
prettyOut+= "\n | " + mapEntry.getKey() + " | " + mapEntry.getValue() + " | " ;
}
} else {
prettyOut+= "\n | empty or null map | " ;
}
return prettyOut+= "\n ------------------------------- \n";
}
/**
* Convenience method to print out a Map (HTTP formatted)
*
* @param Map entry key
* @param Map entry value
* @param map map to pretty print
* @return http (table) formatted representation of the map
*/
public static String prettyHttpPrintMap (final Map map) {
String prettyOut = "
";
if (map != null && !map.isEmpty() ){
prettyOut+= "";
for (Entry mapEntry: map.entrySet()) {
prettyOut+= "" + mapEntry.getKey() + " : " + mapEntry.getValue() + " " ;
}
prettyOut+= "
";
} else {
prettyOut+= "
(no sql parameters) " ;
}
return prettyOut;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy