Advertisement
bobo_bobkata

Untitled

Oct 23rd, 2019
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.15 KB | None | 0 0
  1. package Momchil.ZaSrqda;
  2.  
  3. import java.util.Arrays;
  4. import java.util.LinkedHashMap;
  5. import java.util.Map;
  6. import java.util.concurrent.atomic.AtomicInteger;
  7.  
  8. public class Main {
  9. private static Map<String, Integer> map = new LinkedHashMap<>();
  10.  
  11. static {
  12. map.put(".", 75);
  13.  
  14. map.put("A", 193);
  15. map.put("B", 194);
  16. map.put("C", 195);
  17. map.put("D", 196);
  18. map.put("E", 197);
  19. map.put("F", 198);
  20. map.put("G", 199);
  21. map.put("H", 200);
  22. map.put("I", 201);
  23.  
  24. map.put("J", 209);
  25. map.put("K", 210);
  26. map.put("L", 211);
  27. map.put("M", 212);
  28. map.put("N", 213);
  29. map.put("O", 214);
  30. map.put("P", 215);
  31. map.put("Q", 216);
  32. map.put("R", 217);
  33.  
  34. map.put("S", 226);
  35. map.put("T", 227);
  36. map.put("U", 228);
  37. map.put("V", 229);
  38. map.put("W", 230);
  39. map.put("X", 231);
  40. map.put("Y", 232);
  41. map.put("Z", 233);
  42.  
  43. map.put("a", 129);
  44. map.put("b", 130);
  45. map.put("c", 131);
  46. map.put("d", 132);
  47. map.put("e", 133);
  48. map.put("f", 134);
  49. map.put("g", 135);
  50. map.put("h", 136);
  51. map.put("i", 137);
  52.  
  53. map.put("j", 145);
  54. map.put("k", 146);
  55. map.put("l", 147);
  56. map.put("m", 148);
  57. map.put("n", 149);
  58. map.put("o", 150);
  59. map.put("p", 151);
  60. map.put("q", 152);
  61. map.put("r", 152);
  62.  
  63. map.put("s", 162);
  64. map.put("t", 163);
  65. map.put("u", 164);
  66. map.put("v", 165);
  67. map.put("w", 166);
  68. map.put("x", 167);
  69. map.put("y", 168);
  70. map.put("z", 169);
  71.  
  72. map.put("#", 123);
  73.  
  74. map.put("0", 240);
  75. map.put("1", 241);
  76. map.put("2", 242);
  77. map.put("3", 243);
  78. map.put("4", 244);
  79. map.put("5", 245);
  80. map.put("6", 246);
  81. map.put("7", 247);
  82. map.put("8", 248);
  83. map.put("9", 249);
  84.  
  85. map.put("CR", 13);
  86. map.put("LF", 37);
  87.  
  88. map.put(" ", 64);
  89. }
  90.  
  91. public static void main(String[] args) {
  92. String names = "Borislav Radoslavov Nachev";
  93. String number = "#6";
  94. String date = "01.07.2003";
  95. String[][] asciiInfo = getAsciiValues(new String[]{names, number, date});
  96. pribtMatrix(asciiInfo);
  97. String[][] ebcdicInfo = getEbcidcValues(new String[]{names, number, date});
  98. pribtMatrix(ebcdicInfo);
  99. }
  100. //TODO add carrige new line feed
  101. public static void pribtMatrix(String[][] matrix) {
  102. for (int i = 0; i < matrix.length; i++) {
  103. for (int j = 0; j < matrix[i].length; j++) {
  104. System.out.println(matrix[i][j] + " ");
  105. }
  106. System.out.println();
  107. }
  108. }
  109.  
  110. public static String[][] getEbcidcValues(String[] words) {
  111. String[][] matrix = new String[3][3];
  112. for (int i = 0; i < words.length; i++) {
  113. matrix[0][i] = formatArray(words[i], getBinaryEbcidValues(words[i]));
  114. matrix[1][i] = formatArray(words[i], getOctalEbcidValues(words[i]));
  115. matrix[2][i] = formatArray(words[i], getHexEbcidValues(words[i]));
  116. }
  117. return matrix;
  118. }
  119.  
  120. public static String[] getBinaryEbcidValues(String names) {
  121. return Arrays.stream(names.split("")).map(e -> Integer.toBinaryString(map.get(e))).toArray(String[]::new);
  122. }
  123.  
  124. public static String[] getOctalEbcidValues(String names) {
  125. return Arrays.stream(names.split("")).map(e -> Integer.toOctalString(map.get(e))).toArray(String[]::new);
  126. }
  127.  
  128. public static String[] getHexEbcidValues(String names) {
  129. return Arrays.stream(names.split("")).map(e -> Integer.toHexString(map.get(e))).toArray(String[]::new);
  130. }
  131.  
  132. public static String[][] getAsciiValues(String[] words) {
  133. String[][] matrix = new String[3][3];
  134. for (int i = 0; i < words.length; i++) {
  135. matrix[0][i] = formatArray(words[i], getBinaryAsciiValues(words[i]));
  136. matrix[1][i] = formatArray(words[i], getOctalAsciiValues(words[i]));
  137. matrix[2][i] = formatArray(words[i], getHexAsciiValues(words[i]));
  138. }
  139. return matrix;
  140. }
  141.  
  142. private static String formatArray(String names, String[] array) {
  143. final String[] toReturn = {""};
  144. AtomicInteger index = new AtomicInteger();
  145. Arrays.stream(array).forEach(e -> toReturn[0] += String.format("%c -> %s ", names.charAt(index.getAndIncrement()), e));
  146. return toReturn[0];
  147. }
  148.  
  149. public static String[] getBinaryAsciiValues(String names) {
  150. return Arrays.stream(names.split("")).map(e -> Integer.toBinaryString(e.charAt(0))).toArray(String[]::new);
  151. }
  152.  
  153. public static String[] getOctalAsciiValues(String names) {
  154. return Arrays.stream(names.split("")).map(e -> Integer.toOctalString(e.charAt(0))).toArray(String[]::new);
  155. }
  156.  
  157. public static String[] getHexAsciiValues(String names) {
  158. return Arrays.stream(names.split("")).map(e -> Integer.toHexString(e.charAt(0))).toArray(String[]::new);
  159. }
  160. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement