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
26 * {@link StringUtils#DEFAULT_SQL_DATE}.
28 * @see StringUtils#getTimestamp(Date)
29 * @return String the current timestamp formatted
31 public static String getCurrentTimestamp() {
32 return getTimestamp(new Date());
36 * This method will format the provided {@link Date} with the
37 * {@link StringUtils#DEFAULT_SQL_DATE} format.
40 * @return string represenation of the given date
42 public static String getTimestamp(Date date) {
43 SimpleDateFormat simpleDate = new SimpleDateFormat(DEFAULT_SQL_DATE);
44 return simpleDate.format(date);
48 * Checks the input object for null and if it's null returns a dash instead.
50 * @param object an input object
51 * @return if object is null a dash is returned,
52 * otherwise {@link Object#toString()}
54 public static String prepareDashString(Object object) {
55 return prepareString(object, "-");
59 * Checks the input object for null and if's null returns an empty string instead.
61 * @param object an input object
62 * @return if object is null an empty string is returned,
63 * otherwise {@link Object#toString()}
65 public static String prepareEmptyString(Object object) {
66 return prepareString(object, "");
70 * Checks if the given object is null and returns its representation given by
73 * @param objectString a string object
74 * @param replacement a replacement
75 * @return String the representation of the object given by replacement
77 public static String prepareString(Object objectString, String replacement) {
78 return objectString == null ? replacement : objectString.toString();