From 041cc39421d33534a18b932fcca5a9dd371e961b Mon Sep 17 00:00:00 2001 From: Nathanael Jourdane Date: Wed, 20 Apr 2016 15:27:28 +0200 Subject: [PATCH] improve utils package hierarchy. --- src/main/java/eu/omp/irap/vespa/epntapclient/votable/utils/Const.java | 43 ------------------------------------------- src/main/java/eu/omp/irap/vespa/epntapclient/votable/utils/Consts.java | 43 +++++++++++++++++++++++++++++++++++++++++++ src/main/java/eu/omp/irap/vespa/epntapclient/votable/utils/Debug.java | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main/java/eu/omp/irap/vespa/epntapclient/votable/utils/Strings.java | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main/java/eu/omp/irap/vespa/epntapclient/votable/utils/Utils.java | 114 ------------------------------------------------------------------------------------------------------------------ 5 files changed, 186 insertions(+), 157 deletions(-) delete mode 100644 src/main/java/eu/omp/irap/vespa/epntapclient/votable/utils/Const.java create mode 100644 src/main/java/eu/omp/irap/vespa/epntapclient/votable/utils/Consts.java create mode 100644 src/main/java/eu/omp/irap/vespa/epntapclient/votable/utils/Debug.java create mode 100644 src/main/java/eu/omp/irap/vespa/epntapclient/votable/utils/Strings.java delete mode 100644 src/main/java/eu/omp/irap/vespa/epntapclient/votable/utils/Utils.java diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/votable/utils/Const.java b/src/main/java/eu/omp/irap/vespa/epntapclient/votable/utils/Const.java deleted file mode 100644 index e0a5bcf..0000000 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/votable/utils/Const.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * This file is a part of EpnTAPClient. - * This program aims to provide EPN-TAP support for software clients, like CASSIS spectrum analyzer. - * See draft specifications: https://voparis-confluence.obspm.fr/pages/viewpage.action?pageId=559861 - * Copyright (C) 2016 Institut de Recherche en Astrophysique et Planétologie. - * - * This program is free software: you can - * redistribute it and/or modify it under the terms of the GNU General Public License as published - * by the Free Software Foundation, either version 3 of the License, or (at your option) any later - * version. This program is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. You should have received a copy of - * the GNU General Public License along with this program. If not, see - * . - */ - -package eu.omp.irap.vespa.epntapclient.votable.utils; - -/** - * This class defines widely-used constants. - * - * @author N. Jourdane - */ -public class Const { - - /** The character set used (for http requests, writing in files, etc.). */ - public static final String ENCODING = "UTF-8"; - - /** The temporary directory path. */ - public static final String TMP_DIR = System.getProperty("java.io.tmpdir"); - - /** The URL of the registry used by default to get the services. */ - public static final String DEFAULT_REGISTRY_URL = "http://gavo.aip.de/tap"; - // http://reg.g-vo.org/tap - // http://dc.zah.uni-heidelberg.de/tap - // http://gavo.aip.de/tap - // http://voparis-cdpp.obspm.fr/tap - - - /** Constructor to hide the implicit public one. */ - private Const() { - } -} diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/votable/utils/Consts.java b/src/main/java/eu/omp/irap/vespa/epntapclient/votable/utils/Consts.java new file mode 100644 index 0000000..e122004 --- /dev/null +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/votable/utils/Consts.java @@ -0,0 +1,43 @@ +/* + * This file is a part of EpnTAPClient. + * This program aims to provide EPN-TAP support for software clients, like CASSIS spectrum analyzer. + * See draft specifications: https://voparis-confluence.obspm.fr/pages/viewpage.action?pageId=559861 + * Copyright (C) 2016 Institut de Recherche en Astrophysique et Planétologie. + * + * This program is free software: you can + * redistribute it and/or modify it under the terms of the GNU General Public License as published + * by the Free Software Foundation, either version 3 of the License, or (at your option) any later + * version. This program is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. You should have received a copy of + * the GNU General Public License along with this program. If not, see + * . + */ + +package eu.omp.irap.vespa.epntapclient.votable.utils; + +/** + * This class defines widely-used constants. + * + * @author N. Jourdane + */ +public class Consts { + + /** The character set used (for http requests, writing in files, etc.). */ + public static final String ENCODING = "UTF-8"; + + /** The temporary directory path. */ + public static final String TMP_DIR = System.getProperty("java.io.tmpdir"); + + /** The URL of the registry used by default to get the services. */ + public static final String DEFAULT_REGISTRY_URL = "http://gavo.aip.de/tap"; + // http://reg.g-vo.org/tap + // http://dc.zah.uni-heidelberg.de/tap + // http://gavo.aip.de/tap + // http://voparis-cdpp.obspm.fr/tap + + + /** Constructor to hide the implicit public one. */ + private Consts() { + } +} diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/votable/utils/Debug.java b/src/main/java/eu/omp/irap/vespa/epntapclient/votable/utils/Debug.java new file mode 100644 index 0000000..1d27941 --- /dev/null +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/votable/utils/Debug.java @@ -0,0 +1,57 @@ +/* + * This file is a part of EpnTAPClient. + * This program aims to provide EPN-TAP support for software clients, like CASSIS spectrum analyzer. + * See draft specifications: https://voparis-confluence.obspm.fr/pages/viewpage.action?pageId=559861 + * Copyright (C) 2016 Institut de Recherche en Astrophysique et Planétologie. + * + * This program is free software: you can + * redistribute it and/or modify it under the terms of the GNU General Public License as published + * by the Free Software Foundation, either version 3 of the License, or (at your option) any later + * version. This program is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. You should have received a copy of + * the GNU General Public License along with this program. If not, see + * . + */ + +package eu.omp.irap.vespa.epntapclient.votable.utils; + +import java.io.FileWriter; +import java.io.IOException; +import java.util.logging.Logger; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +/** + * @author N. Jourdane + */ +public class Debug { + + /** The logger for the class Debug. */ + private static final Logger logger = Logger.getLogger(Debug.class.getName()); + + + /** + * Print the specified object in JSON format in a file on the temporary directory. + * + * @param title The name of the file. + * @param obj the object to print in a file. + * @return The path of the file. + */ + public static String printObject(String title, Object obj) { + Gson gson = new GsonBuilder().setPrettyPrinting().create(); + String json = gson.toJson(obj); + String path = Consts.TMP_DIR + "/" + title + ".json"; + try (FileWriter writer = new FileWriter(path)) { + writer.write(json); + + } catch (IOException e) { + Debug.logger.warning("Can not print in the file " + path + e); + } + Debug.logger.info("A json file representing " + title + " (" + obj.getClass().getName() + + ") has been created on " + path); + + return path; + } +} diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/votable/utils/Strings.java b/src/main/java/eu/omp/irap/vespa/epntapclient/votable/utils/Strings.java new file mode 100644 index 0000000..884f9d2 --- /dev/null +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/votable/utils/Strings.java @@ -0,0 +1,86 @@ +/* + * This file is a part of EpnTAPClient. + * This program aims to provide EPN-TAP support for software clients, like CASSIS spectrum analyzer. + * See draft specifications: https://voparis-confluence.obspm.fr/pages/viewpage.action?pageId=559861 + * Copyright (C) 2016 Institut de Recherche en Astrophysique et Planétologie. + * + * This program is free software: you can + * redistribute it and/or modify it under the terms of the GNU General Public License as published + * by the Free Software Foundation, either version 3 of the License, or (at your option) any later + * version. This program is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. You should have received a copy of + * the GNU General Public License along with this program. If not, see + * . + */ + +package eu.omp.irap.vespa.epntapclient.votable.utils; + +import java.util.logging.Logger; + +/** + * @author N. Jourdane + */ +public class Strings { + + /** The logger for the class Utils. */ + private static final Logger logger = Logger.getLogger(Strings.class.getName()); + + + /** Private constructor to hide the implicit public one. */ + private Strings() { + } + + + /** + * StringJoiner has the same purpose of Java 8 StringJoiner, it has been rewritten for Java7 + * compatibility. + * + * @author N. Jourdane + */ + public static class StringJoiner { + + /** The string joiner separator to put between each word, ie. ';'. */ + private String separator; + + /** The resulting string, ie. "foo;bar". */ + private String string; + + + /** + * Method constructor for the String joiner. + * + * @param separator The string joiner separator to put between each word, ie. ';'. + */ + public StringJoiner(String separator) { + this.separator = separator; + string = new String(); + } + + /** + * Add a new word to the joiner. + * + * @param text The word to add. + */ + public void add(String text) { + if (string.isEmpty()) { + string = text; + } else { + string += separator + text; + } + } + + /** + * @return true if the string joiner content is empty. + */ + public boolean isEmpty() { + return string.isEmpty(); + } + + @Override + public String toString() { + return string; + } + } + +} diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/votable/utils/Utils.java b/src/main/java/eu/omp/irap/vespa/epntapclient/votable/utils/Utils.java deleted file mode 100644 index 6d86b77..0000000 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/votable/utils/Utils.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * This file is a part of EpnTAPClient. - * This program aims to provide EPN-TAP support for software clients, like CASSIS spectrum analyzer. - * See draft specifications: https://voparis-confluence.obspm.fr/pages/viewpage.action?pageId=559861 - * Copyright (C) 2016 Institut de Recherche en Astrophysique et Planétologie. - * - * This program is free software: you can - * redistribute it and/or modify it under the terms of the GNU General Public License as published - * by the Free Software Foundation, either version 3 of the License, or (at your option) any later - * version. This program is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. You should have received a copy of - * the GNU General Public License along with this program. If not, see - * . - */ - -package eu.omp.irap.vespa.epntapclient.votable.utils; - -import java.io.FileWriter; -import java.io.IOException; -import java.util.logging.Logger; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; - -/** - * @author N. Jourdane - */ -public class Utils { - - /** The logger for the class Utils. */ - private static final Logger logger = Logger.getLogger(Utils.class.getName()); - - - /** Private constructor to hide the implicit public one. */ - private Utils() { - } - - - /** - * StringJoiner has the same purpose of Java 8 StringJoiner, it has been rewritten for Java7 - * compatibility. - * - * @author N. Jourdane - */ - public static class StringJoiner { - - /** The string joiner separator to put between each word, ie. ';'. */ - private String separator; - - /** The resulting string, ie. "foo;bar". */ - private String string; - - - /** - * Method constructor for the String joiner. - * - * @param separator The string joiner separator to put between each word, ie. ';'. - */ - public StringJoiner(String separator) { - this.separator = separator; - string = new String(); - } - - /** - * Add a new word to the joiner. - * - * @param text The word to add. - */ - public void add(String text) { - if (string.isEmpty()) { - string = text; - } else { - string += separator + text; - } - } - - /** - * @return true if the string joiner content is empty. - */ - public boolean isEmpty() { - return string.isEmpty(); - } - - @Override - public String toString() { - return string; - } - } - - - /** - * Print the specified object in JSON format in a file on the temporary directory. - * - * @param title The name of the file. - * @param obj the object to print in a file. - * @return The path of the file. - */ - public static String printObject(String title, Object obj) { - Gson gson = new GsonBuilder().setPrettyPrinting().create(); - String json = gson.toJson(obj); - String path = Const.TMP_DIR + "/" + title + ".json"; - try (FileWriter writer = new FileWriter(path)) { - writer.write(json); - - } catch (IOException e) { - Utils.logger.warning("Can not print in the file " + path + e); - } - Utils.logger.info("A json file representing " + title + " (" + obj.getClass().getName() - + ") has been created on " + path); - - return path; - } -} -- libgit2 0.21.2