| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- package uk.ac.ic.wlgitbridge.util;
- import uk.ac.ic.wlgitbridge.application.SSLConfig;
- import java.io.BufferedReader;
- import java.io.IOException;
- /**
- * Created by Winston on 19/11/14.
- */
- public class Util {
- private static String SERVICE_NAME;
- private static String HOSTNAME;
- private static SSLConfig SSL_CONFIG;
- private static int PORT;
- public static String entries(int entries) {
- if (entries == 1) {
- return "entry";
- } else {
- return "entries";
- }
- }
- public static int booleanToInt(boolean b) {
- if (b) {
- return 1;
- } else {
- return 0;
- }
- }
- public static boolean intToBoolean(int i) {
- return i != 0;
- }
- private static String removeAllSuffix(String str, String suffix) {
- int lastIndexOfSuffix;
- String result = str;
- while ((lastIndexOfSuffix = result.lastIndexOf(suffix)) > -1) {
- result = result.substring(0, lastIndexOfSuffix);
- }
- return result;
- }
- /* removeAllSuffixes("something.git///", "/", ".git") => "something" */
- public static String removeAllSuffixes(String str, String... suffixes) {
- String result = str;
- for (String suffix : suffixes) {
- result = removeAllSuffix(result, suffix);
- }
- return result;
- }
- public static String getContentsOfReader(BufferedReader reader) throws IOException {
- StringBuilder sb = new StringBuilder();
- for (String line; (line = reader.readLine()) != null; ) {
- sb.append(line);
- }
- return sb.toString();
- }
- public static void setServiceName(String serviceName) {
- SERVICE_NAME = serviceName;
- }
- public static String getServiceName() {
- return SERVICE_NAME;
- }
- public static void setHostname(String hostname) {
- HOSTNAME = hostname;
- }
- public static String getHostname() {
- return HOSTNAME;
- }
- public static SSLConfig getSSLConfig() {
- return SSL_CONFIG;
- }
- public static void setSSL(SSLConfig ssl) {
- SSL_CONFIG = ssl;
- }
- public static int getPort() {
- return PORT;
- }
- public static void setPort(int port) {
- PORT = port;
- }
- }
|