Package clips.delegate.doctor.profchekup

Source Code of clips.delegate.doctor.profchekup.SearchResult

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package clips.delegate.doctor.profchekup;

import beans.profcheckup.search.ProfcheckupContractChunk;
import cli_fmw.delegate.AuditListener;
import cli_fmw.main.ClipsException;
import clips.delegate.client.ClientLocal;
import clips.delegate.contract.ContractLocal;
import clips.delegate.contract.PolisData;
import clips.delegate.directory.complex.DirectoryDangerItem;
import clips.delegate.job.DangerExamChunk;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
*
* @author petr
*/
public class SearchResult {

    private Set<DelegateChunk> delegateChanks = new HashSet<DelegateChunk>();

    private class DelegateChunk{
        public ContractLocal contract;
        public DangerExamChunk danger;
        public PolisData polis;

        public int contractID;
        public int dangerID;
        public int polisID;

        public DelegateChunk(ContractLocal contract, DangerExamChunk danger, PolisData polis) {
            this.contract = contract;
            this.danger = danger;
            this.polis = polis;

            this.contractID = contract.getID();
            this.dangerID = danger.getDetails().dangerId;
            this.polisID = polis.getId();

        }

        @Override
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (getClass() != obj.getClass()) {
                return false;
            }
            final DelegateChunk other = (DelegateChunk) obj;
            if (this.contractID != other.contractID) {
                return false;
            }
            if (this.dangerID != other.dangerID) {
                return false;
            }
            if (this.polisID != other.polisID) {
                return false;
            }
            return true;
        }

        @Override
        public int hashCode() {
            int hash = 3;
            hash = 29 * hash + this.contractID;
            hash = 29 * hash + this.dangerID;
            hash = 29 * hash + this.polisID;
            return hash;
        }

    }

    public SearchResult(List<ProfcheckupContractChunk> chunks, AuditListener al) throws ClipsException {

        HashMap<Integer, ContractLocal> contracts = new HashMap<Integer, ContractLocal>();
        HashMap<Integer, ClientLocal> clients = new HashMap<Integer, ClientLocal>();
        HashMap<Integer, DangerExamChunk> dangers = new HashMap<Integer, DangerExamChunk>();
        HashMap<Integer, PolisData> polises = new HashMap<Integer, PolisData>();

        for (ProfcheckupContractChunk pcc : chunks) {
            if (contracts.get(pcc.contract.id) == null){
                contracts.put(pcc.contract.id, new ContractLocal(pcc.contract, al));
            }
            if (clients.get(pcc.client.id) == null){
                clients.put(pcc.client.id, new ClientLocal(pcc.client, al));
            }
            if (dangers.get(pcc.danger.dangerId) == null){
                dangers.put(pcc.danger.dangerId, new DangerExamChunk(pcc.danger));
            }
        }


        for (ProfcheckupContractChunk pcc : chunks) {
            PolisData pd  = polises.get(pcc.polis.id);
            if (pd == null){
                pd = new PolisData(contracts.get(pcc.contract.id), clients.get(pcc.client.id), pcc.polis);
                polises.put(pd.getId(), pd);
            }
            delegateChanks.add(new DelegateChunk(contracts.get(pcc.contract.id), dangers.get(pcc.danger.dangerId), pd));
        }

    }

    public HashSet<DirectoryDangerItem> getUsableDangers(ContractLocal contractLocal) throws ClipsException {
        HashSet<DirectoryDangerItem> list = new HashSet<DirectoryDangerItem>();
        for (DelegateChunk chank : delegateChanks) {
            if (chank.contractID == contractLocal.getID()){
                list.add(chank.danger.getDanger());
            }
        }
        return list;
    }

    public HashSet<PolisData> getUsablePolisList(ContractLocal contractLocal, DirectoryDangerItem danger) throws ClipsException {
        HashSet<PolisData> list = new HashSet<PolisData>();
        for (DelegateChunk chunk : delegateChanks) {
            if (chunk.contractID == contractLocal.getID() && chunk.dangerID == danger.getID()){
                list.add(chunk.polis);
            }
        }
        return list;
    }

    public Set<ContractLocal> getUsableContracts() throws ClipsException {
        HashSet<ContractLocal> list = new HashSet<ContractLocal>();
        for (DelegateChunk chunk : delegateChanks) {
            list.add(chunk.contract);
        }
        return list;
    }

    public HashSet<DangerExamChunk> getDangersByPolis(PolisData pd){
        HashSet<DangerExamChunk> list = new HashSet<DangerExamChunk>();
        for (DelegateChunk chunk : delegateChanks) {
            if (chunk.polisID == pd.getId()){
                list.add(chunk.danger);
            }
        }
        return list;
    }


}
TOP

Related Classes of clips.delegate.doctor.profchekup.SearchResult

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.