/*
 * $Id: PatentClassifyResultEntry.java,v 1.3 2004/12/21 10:29:17 koppy Exp $
 *
 * Copyright (c) Siemens AG 2008 
 *           (c) Universität Paderborn 2008 
 * Licensed under EUPL 1.1. 
 * 
 * Created on 09.10.2004
 *
 * $Log: PatentClassifyResultEntry.java,v $
 * Revision 1.3  2004/12/21 10:29:17  koppy
 * so einiges
 *
 * Revision 1.2  2004/11/10 15:02:53  koppy
 * Projektweite Überarbeitung von Error-Logs, Stacktraces,..
 *
 * Revision 1.1  2004/10/09 16:03:01  koppy
 * Initiale Version
 *
 */
package vkc.ws.axis.service.patent;

import java.util.ArrayList;

import vkc.util.VKCStringUtils;


/**
 * This class represents
 * @author Andreas Koop
 */
public class PatentClassifyResultEntry {

    private String categoryPath;
    private String categoryId;
    private String percentString;
    private float percent;
    
    public PatentClassifyResultEntry( String resultEntry ){
        ArrayList entries = VKCStringUtils.split( resultEntry, "|");
        
        categoryPath = entries.get(0).toString();
        categoryId = entries.get(1).toString();
        percentString = entries.get(2).toString();
        this.parsePercentString();
    }
    
    private void parsePercentString(){
        
        String s = percentString.substring(0, percentString.indexOf("%")).trim();
        s = s.replace(',','.');
        this.percent = Float.parseFloat(s);
    }
    
    public String getCategoryId() {
        return categoryId;
    }
    public void setCategoryId(String categoryId) {
        this.categoryId = categoryId;
    }
    public String getCategoryPath() {
        return categoryPath;
    }
    public void setCategoryPath(String categoryPath) {
        this.categoryPath = categoryPath;
    }
    
    public float getPercent(){
        return percent;
    }
    
    public void addPercent(float p){
        this.percent+=p;
    }
    
    public void setPercentString(String percent) {
        this.percentString = percent;
        this.parsePercentString();
    }

    /**
     * @param line
     * @return
     */
    public static boolean isValid(String line) {
        
        if(line == null || line.trim().startsWith("#")){
            return false;
        }
        
        ArrayList entries = VKCStringUtils.split( line, "|");
        return entries.size() > 2;
    }
}
