Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.41 KB | None | 0 0
  1. import org.apache.xmlrpc.WebServer;
  2.  
  3. import java.util.Calendar;
  4. import java.util.Locale;
  5. import java.util.TimeZone;
  6.  
  7.  
  8. public class RPCserver {
  9.  
  10. /***
  11. * Method that give inforamtion about available methods
  12. * @return String with methods(parameters) - short description
  13. */
  14.  
  15. public String show(){
  16. return "Available methods: \n" +
  17. "1. asy(int) - with given time parameter, returns value of time delayed by this value \n" +
  18. "2. echo(int, int) - returns sum of parameters \n" +
  19. "3. multiply(int, int) - returns multiplication of parameters \n" +
  20. "4. parseIntAndDoubleToString(int, double) - return concatenated parameters as string \n" +
  21. "5. upperAndConcatenate(string, string) - returns uppercase of concatenated strings \n";
  22. }
  23.  
  24. /***
  25. * Method calculates sum of given two parameters
  26. * @param x int, is the first parameter to sum
  27. * @param y int, is the second parameter to sum
  28. * @return int sum of given parameters
  29. */
  30. public Integer echo(int x, int y){
  31. return x + y;
  32. }
  33.  
  34. /***
  35. * Method calculates multiplication of two given parameters
  36. * @param x double first parameter to multiply
  37. * @param y double second parameter to multiply
  38. * @return double multiplication of givent Parameters
  39. */
  40. public Double multiply(double x, double y) {
  41. return x * y;
  42. }
  43.  
  44. /***
  45. * Method create new string with capital letters from given two strings
  46. * @param s1 String first parameter to concatenate
  47. * @param s2 String second parameter to concatenate
  48. * @return concatenated two strings in uppercase
  49. */
  50. public String upperAndConcatenate(String s1, String s2) {
  51. return (s1 + s2).toUpperCase();
  52. }
  53.  
  54. /***
  55. * Method parses int and double parameters to string as one string with space between then
  56. * @param i int parameter to parse
  57. * @param d double parameter to parse
  58. * @return concatenated with space two given parameters
  59. */
  60.  
  61. public String parseIntAndDoubleToString(int i, double d) {
  62. return String.valueOf(i) + " " + String.valueOf(d);
  63. }
  64.  
  65. /***
  66. * Return formatted place and time with the given place and language
  67. * @param place String named place that is returned with
  68. * @param language String two letters from the month display language is depend
  69. * @return concatenated place and data with format 'place, year month_in_language day hour-minute-second'
  70. */
  71.  
  72. public static String getTime(String place, String language) {
  73. Locale lo = new Locale(language);
  74. Calendar calendar = Calendar.getInstance();
  75. return place + ", " + calendar.get(Calendar.YEAR) + " " + calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, lo) + " " + calendar.get(Calendar.DAY_OF_MONTH) + " " + calendar.get(calendar.HOUR_OF_DAY) + "-" + calendar.get(calendar.MINUTE) + (String.format("-%02d",calendar.get(calendar.SECOND)));
  76. }
  77.  
  78. public Integer asy(int x, int y, int z) {
  79. System.out.println("Generowanie liczb pierwszych");
  80. try {
  81. Thread.sleep(z);
  82. } catch (InterruptedException e) {
  83. e.printStackTrace();
  84. Thread.currentThread().interrupt();
  85. }
  86. System.out.println("Wygenerowano!");
  87. List <Integer> list = primeNumbersTill(x, y);
  88. for(Integer asd : list){
  89. System.out.print(asd +" ");
  90. }
  91. }
  92. public static List<Integer> primeNumbersTill(int z, int n) {
  93. return IntStream.rangeClosed(z, n)
  94. .filter(x -> isPrime(x)).boxed()
  95. .collect(Collectors.toList());
  96. }
  97. private static boolean isPrime(int number) {
  98. return IntStream.rangeClosed(2, (int) (Math.sqrt(number)))
  99. .filter(n -> (n & 0X1) != 0)
  100. .allMatch(n -> x % n != 0);
  101. }
  102.  
  103. public static void main(String[] args) {
  104. try {
  105. System.out.println("Starting server XML-RPC");
  106. int port = 10008;
  107. WebServer server = new WebServer(port);
  108. server.addHandler("myServer", new RPCserver());
  109. server.start();
  110. System.out.println("Server succesfully started");
  111. System.out.println("Listening to the port " + port);
  112. System.out.println("To stop server, press ctrl+c");
  113. } catch (Exception e) {
  114. System.err.println("Server XML-RPC: " + e);
  115. }
  116. }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement