2 * Copyright © 2017 AT&T and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.transportpce.inventory.utils;
10 import java.text.SimpleDateFormat;
11 import java.util.Date;
14 * Utility class which handles strings in inventory project.
17 public final class StringUtils {
18 public static final String DEFAULT_SQL_DATE = "yyyy-MM-dd HH:mm:ss";
20 private StringUtils() {
21 // hiding the constructor
25 * Returns the current timestamp formatted with {@link StringUtils#DEFAULT_SQL_DATE}.
27 * @see StringUtils#getTimestamp(Date)
28 * @return Timestamp represenation of the given date
30 public static String getCurrentTimestamp() {
31 return getTimestamp(new Date());
35 * This method will format the provided {@link Date} with the {@link StringUtils#DEFAULT_SQL_DATE} format.
37 * @param date link date
38 * @return string represenation of the given date
40 public static String getTimestamp(Date date) {
41 SimpleDateFormat myTimeStamp = new SimpleDateFormat(DEFAULT_SQL_DATE);
42 return myTimeStamp.format(date);
46 * Checks the input object for null and if it's null returns a dash instead.
48 * @param object an object
49 * @return if object is null a dash is returned, otherwise {@link Object#toString()}
51 public static String prepareDashString(Object object) {
52 return prepareString(object, "");
56 * Checks the input object for null and if's null returns an empty string instead.
58 * @param object an object
59 * @return if object is null an empty string is returned, otherwise {@link Object#toString()}
61 public static String prepareEmptyString(Object object) {
62 return prepareString(object, "");
66 * Checks if the given object is null and returns its representation given by replacement.
69 public static String prepareString(Object objectString, String replacement) {
70 return objectString == null ? replacement : objectString.toString();
74 * Checks if the given object is null and returns -1 .
77 public static String prepareEmptyInt(Object object) {
78 return (object == null ? "-1" : object.toString());