Util.java 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package uk.ac.ic.wlgitbridge.util;
  2. import java.io.BufferedReader;
  3. import java.io.IOException;
  4. /**
  5. * Created by Winston on 19/11/14.
  6. */
  7. public class Util {
  8. public static String entries(int entries) {
  9. if (entries == 1) {
  10. return "entry";
  11. } else {
  12. return "entries";
  13. }
  14. }
  15. public static int booleanToInt(boolean b) {
  16. if (b) {
  17. return 1;
  18. } else {
  19. return 0;
  20. }
  21. }
  22. public static boolean intToBoolean(int i) {
  23. return i != 0;
  24. }
  25. private static String removeAllSuffix(String str, String suffix) {
  26. int lastIndexOfSuffix;
  27. String result = str;
  28. while ((lastIndexOfSuffix = result.lastIndexOf(suffix)) > -1) {
  29. result = result.substring(0, lastIndexOfSuffix);
  30. }
  31. return result;
  32. }
  33. /* removeAllSuffixes("something.git///", "/", ".git") => "something" */
  34. public static String removeAllSuffixes(String str, String... suffixes) {
  35. String result = str;
  36. for (String suffix : suffixes) {
  37. result = removeAllSuffix(result, suffix);
  38. }
  39. return result;
  40. }
  41. public static String getContentsOfReader(BufferedReader reader) throws IOException {
  42. StringBuilder sb = new StringBuilder();
  43. for (String line; (line = reader.readLine()) != null; ) {
  44. sb.append(line);
  45. }
  46. return sb.toString();
  47. }
  48. }