Guest User

Untitled

a guest
Jun 22nd, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. package maptest;
  2. import java.util.HashMap;
  3. class WritableString{
  4. String field;
  5. public String toString(){
  6. return field;
  7. }
  8. public String write(final String str){
  9. field = str;
  10. return field;
  11. }
  12. }
  13. class UploadData{
  14. WritableString time; // t
  15. class Source{
  16. WritableString ip = new WritableString(); // i
  17. WritableString countryCode = new WritableString(); // c
  18. WritableString category = new WritableString(); // ra
  19. }
  20. class Destination{
  21. WritableString ip = new WritableString(); // di
  22. WritableString countryCode = new WritableString(); // dc
  23. WritableString hostName = new WritableString(); // ho
  24. WritableString port = new WritableString(); // po
  25. WritableString path = new WritableString(); // pa
  26. }
  27. Source src = new Source();
  28. Destination dst = new Destination();
  29. HashMap<String,Object> map = new HashMap<String,Object>();
  30. /**
  31. * write to the specified field,
  32. * return true if write successfully.
  33. */
  34. public boolean write(String fieldName,String val){
  35. WritableString toWrite = (WritableString)map.get(fieldName);
  36. if(toWrite == null) {
  37. return false;
  38. }
  39. toWrite.write(val);
  40. return true;
  41. }
  42. private void init(){
  43. map.put("t", time);
  44. map.put("i", src.ip);
  45. map.put("c", src.countryCode);
  46. map.put("ra", src.category);
  47. map.put("di", dst.ip);
  48. map.put("dc", dst.countryCode);
  49. map.put("ho", dst.hostName);
  50. map.put("po", dst.port);
  51. map.put("pa", dst.path);
  52. }
  53. public UploadData(){
  54. init();
  55. }
  56. }
  57. public class TestMap {
  58. public static void main(String argv[]){
  59.  
  60. }
  61. }
Add Comment
Please, Sign In to add comment