class OwnLocalResources {

  public Map<Path,List<String>> filterLocalResources(Map<Path,List<String>> originLocalResources){

    Map<Path,Path> linkNameMap = new HashMap<>();
    Map<Path,List<String>> filteredLRs = new HashMap<>();
    Map<Path,Path> taggingLinkNameMap = new HashMap<>();
    Map<String,Path> ignores = new HashMap<>();

    if(thisNodeTag == null){
      return new HashMap<>(originLocalResources);
    }

    for(Map.Entry<Path,List<String>> entry: originLocalResources.entrySet()) {

      Path localCachePath = entry.getKey();
      List<String> links = entry.getValue();

      for (String item : links) {

        Path link = new Path(item);
        Pair<String, Path> pair = splitTagAndBasename(link);
        if(pair == null) {

          List<String> syms = filteredLRs.get(localCachePath);

          if(syms == null) {
            syms = new ArrayList<>();
            filteredLRs.put(localCachePath, syms);
          }

          syms.add(item);
          linkNameMap.put(link, localCachePath);

        } else {

          String tag = pair.getFirst();
          Path taggingLinkName = pair.getSecond();

          if(tag.equals(thisNodeTag)) {
            taggingLinkNameMap.put(taggingLinkName, localCachePath);
          } else {
            ignores.put(item, localCachePath);
          }
        }
      }
    }


    for(Map.Entry<Path, Path> entry: taggingLinkNameMap.entrySet()){

      Path linkName = entry.getKey();
      Path thisCachePath = entry.getValue();
      List<String> syms;

      Path thatCachePath = linkNameMap.get(linkName);
      if(thatCachePath != null){
        syms = filteredLRs.remove(thatCachePath);

        for(String sym:syms){
          ignores.put(sym, thatCachePath);
        }

      } else {
        syms = new ArrayList<>();
        for(String sym: originLocalResources.get(thisCachePath)){

          Pair<String,Path> pair = splitTagAndBasename(new Path(sym));
          if(pair == null){
            syms.add(sym);
          } else {

            String tag = pair.getFirst();
            Path taggingLinkName = pair.getSecond();

            if(tag.equals(thisNodeTag)) {
              syms.add(taggingLinkName.toString());
            } else {
              ignores.put(sym, thisCachePath);
            }
          }
        }
      }

      filteredLRs.put(thisCachePath, syms);
    }

    if(ignores.size() > 0 || taggingLinkNameMap.size() > 0) {
      LOG.info("Ignored LRs:" + ignores + " Node Own LRs:" + taggingLinkNameMap);
    }

    return filteredLRs;
  }

  public  OwnLocalResources(String thisNodeTag);
  public  OwnLocalResources();

}