예제 #1
0
  public static Entry fromMap(Map<?, ?> map) {
    entry e = new entry(entry.data_type.dictionary_t);

    string_entry_map d = e.dict();
    for (Map.Entry<?, ?> kv : map.entrySet()) {
      String k = kv.getKey().toString();
      Object v = kv.getValue();

      if (v instanceof String) {
        d.set(k, new entry((String) v));
      } else if (v instanceof Integer) {
        d.set(k, new entry((Integer) v));
      } else if (v instanceof Entry) {
        d.set(k, ((Entry) v).getSwig());
      } else if (v instanceof entry) {
        d.set(k, (entry) v);
      } else if (v instanceof List) {
        d.set(k, fromList((List<?>) v).getSwig());
      } else if (v instanceof Map) {
        d.set(k, fromMap((Map<?, ?>) v).getSwig());
      } else {
        d.set(k, new entry(v.toString()));
      }
    }

    return new Entry(e);
  }
예제 #2
0
  public ArrayList<Entry> list() {
    entry_vector v = e.list().to_vector();
    int size = (int) v.size();

    ArrayList<Entry> list = new ArrayList<Entry>(size);

    for (int i = 0; i < size; i++) {
      list.add(new Entry(v.get(i)));
    }

    return list;
  }
예제 #3
0
  public static Entry fromList(List<?> list) {
    entry e = new entry(entry.data_type.list_t);

    entry_list d = e.list();
    for (Object v : list) {
      if (v instanceof String) {
        d.push_back(new entry((String) v));
      } else if (v instanceof Integer) {
        d.push_back(new entry((Integer) v));
      } else if (v instanceof Entry) {
        d.push_back(((Entry) v).getSwig());
      } else if (v instanceof entry) {
        d.push_back((entry) v);
      } else if (v instanceof List) {
        d.push_back(fromList((List<?>) v).getSwig());
      } else if (v instanceof Map) {
        d.push_back(fromMap((Map<?, ?>) v).getSwig());
      } else {
        d.push_back(new entry(v.toString()));
      }
    }

    return new Entry(e);
  }
예제 #4
0
  public Map<String, Entry> dictionary() {
    string_entry_map dict = e.dict();
    string_vector keys = dict.keys();
    int size = (int) keys.size();

    Map<String, Entry> map = new HashMap<String, Entry>(size);

    for (int i = 0; i < size; i++) {
      String key = keys.get(i);
      Entry value = new Entry(dict.get(key));
      map.put(key, value);
    }

    return map;
  }
예제 #5
0
 @Override
 public String toString() {
   return e.to_string();
 }
예제 #6
0
 public long integer() {
   return e.integer();
 }
예제 #7
0
 public String string() {
   return e.string();
 }
예제 #8
0
 public byte[] bencode() {
   return Vectors.char_vector2bytes(e.bencode());
 }