Java BufferedReader Read loadTrustDistrustSets(String trust_data_set)

Here you can find the source of loadTrustDistrustSets(String trust_data_set)

Description

Read Trust Set and Distrust Set from trust.txt

License

Open Source License

Parameter

Parameter Description
trust_data_set a parameter

Exception

Parameter Description
Exception an exception

Return

Map[]{TrustSet, DistrustSet}

Declaration

@SuppressWarnings("rawtypes")
public static Map[] loadTrustDistrustSets(String trust_data_set) throws Exception 

Method Source Code


//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 };
    }
}

Related

  1. loadTemplate(String templateUrl)
  2. loadTemplateParametersFile(File f)
  3. loadTestFixture(String path)
  4. loadTestUserEventRelation(String eventFilePath, HashMap> TestUser2EventIndexSetMap)
  5. loadToStringListFromFile(String fullFileName)
  6. loadTrustSet(String trustSet)
  7. loadTwoColumnResource(InputStream resource)
  8. loadTxnDescriptions(String filename)
  9. loadTXTList(String listFile, int size)