Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package maptest;
- import java.util.HashMap;
- class WritableString{
- String field;
- public String toString(){
- return field;
- }
- public String write(final String str){
- field = str;
- return field;
- }
- }
- class UploadData{
- WritableString time; // t
- class Source{
- WritableString ip = new WritableString(); // i
- WritableString countryCode = new WritableString(); // c
- WritableString category = new WritableString(); // ra
- }
- class Destination{
- WritableString ip = new WritableString(); // di
- WritableString countryCode = new WritableString(); // dc
- WritableString hostName = new WritableString(); // ho
- WritableString port = new WritableString(); // po
- WritableString path = new WritableString(); // pa
- }
- Source src = new Source();
- Destination dst = new Destination();
- HashMap<String,Object> map = new HashMap<String,Object>();
- /**
- * write to the specified field,
- * return true if write successfully.
- */
- public boolean write(String fieldName,String val){
- WritableString toWrite = (WritableString)map.get(fieldName);
- if(toWrite == null) {
- return false;
- }
- toWrite.write(val);
- return true;
- }
- private void init(){
- map.put("t", time);
- map.put("i", src.ip);
- map.put("c", src.countryCode);
- map.put("ra", src.category);
- map.put("di", dst.ip);
- map.put("dc", dst.countryCode);
- map.put("ho", dst.hostName);
- map.put("po", dst.port);
- map.put("pa", dst.path);
- }
- public UploadData(){
- init();
- }
- }
- public class TestMap {
- public static void main(String argv[]){
- }
- }
Add Comment
Please, Sign In to add comment