Here you can find the source of loadTrustDistrustSets(String trust_data_set)
Parameter | Description |
---|---|
trust_data_set | a parameter |
Parameter | Description |
---|---|
Exception | an exception |
@SuppressWarnings("rawtypes") public static Map[] loadTrustDistrustSets(String trust_data_set) throws Exception
//package com.java2s; //License from project: Open Source License import java.io.BufferedReader; import java.io.FileReader; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; public class Main { /**/*w w w. j a va 2s . c o m*/ * Read Trust Set and Distrust Set from trust.txt * * @param trust_data_set * @return Map[]{TrustSet, DistrustSet} * @throws Exception */ @SuppressWarnings("rawtypes") public static Map[] loadTrustDistrustSets(String trust_data_set) throws Exception { BufferedReader fr = new BufferedReader(new FileReader(trust_data_set)); /* Trust Set */ Map<String, List<String>> usersTNsMap = new HashMap<>(); /* Distrust Set */ Map<String, List<String>> usersDTNsMap = new HashMap<>(); String line = null; List<String> tns = null, dtns = null; while ((line = fr.readLine()) != null) { String[] data = line.split(" "); String trustor = data[0]; String trustee = data[1]; int value = Integer.parseInt(data[2]); if (trustee.equals(trustor)) continue; // to remove self-indicate entry if (value == 1) { if (usersTNsMap.containsKey(trustor)) { tns = usersTNsMap.get(trustor); tns.add(trustee); } else { tns = new ArrayList<>(); tns.add(trustee); } usersTNsMap.put(trustor, tns); } else if (value == -1) { if (usersDTNsMap.containsKey(trustor)) { dtns = usersDTNsMap.get(trustor); dtns.add(trustee); } else { dtns = new ArrayList<>(); dtns.add(trustee); } usersDTNsMap.put(trustor, dtns); } } fr.close(); return new Map[] { usersTNsMap, usersDTNsMap }; } }