Package dnb.analyze.nfo

Source Code of dnb.analyze.nfo.NfoLyzeResult

package dnb.analyze.nfo;

import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import dnb.analyze.MatchResult;
import dnb.data.filetree.Folder;

/**
* A large, temporary parse result object for interactive validation, 2b thrown away quickly.
*/
public class NfoLyzeResult {

  private final Folder path;
  private String content;
  private NfoType nfoType;
  private final Map<NfoField, MatchResult> matches = new EnumMap<NfoField, MatchResult>(NfoField.class);
 
 
  private static final NfoField[] OVERALL_STATUS_FIELDS
    = new NfoField[] {NfoField.ARTIST, NfoField.RECORD_LABEL, NfoField.LABEL_CODE}
 
  public NfoLyzeResult(Folder path) {     
    this.path = path;
   
  }

  public NfoType getNfoType() {
    return nfoType;
  }

  public Map<NfoField, MatchResult> getMatches() {
    return matches;
  }

  public String getContent() {
    return content;
  }
 
  // method for overall worst-status for Interaction impl 2 check whether 2 bother the user !
  public MatchResult.Status getWorstMatchResultStatus() {
    MatchResult.Status ret = MatchResult.Status.KNOWN; // assume known @ start & get worse ;-)
    MatchResult m;
    MatchResult.Status s;
    for (NfoField f : OVERALL_STATUS_FIELDS) {
      m = matches.get(f);
      if (m == null) { // elementary field not set => worst, worst case
        return MatchResult.Status.UNKNOWN; // => bail out with unknown
      }
      s = m.getStatus();     
      if (s.isWorseThan(ret)) {
        ret = s;
      }
    }
    return ret;
  }
 
  public List<Entry<NfoField, MatchResult> > getMatchResults(MatchResult.Source source) {
    List<Entry<NfoField, MatchResult> > ret = new ArrayList<Entry<NfoField, MatchResult>>();
    for (Entry<NfoField, MatchResult> e : matches.entrySet()) {       
      if (e.getValue().getSource() == source) {         
        ret.add(new AbstractMap.SimpleEntry<NfoField, MatchResult>(e.getKey(), e.getValue()));
      }
    }
    return ret;
  }

  public Folder getPath() {
    return path;
  }

  void setContent(String content) {
    this.content = content;
  }

  void setNfoType(NfoType nfoType) {
    this.nfoType = nfoType;
  }
}
TOP

Related Classes of dnb.analyze.nfo.NfoLyzeResult

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.