<commit_before>package me.legrange.panstamp.gui.tree;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import me.legrange.panstamp.GatewayException;
import me.legrange.panstamp.PanStamp;
import me.legrange.panstamp.PanStampEvent;
import me.legrange.panstamp.PanStampListener;
import me.legrange.panstamp.Register;

/**
 *
 * @author gideon
 */
public class PanStampNode extends SWAPNode implements PanStampListener {

    public PanStampNode(PanStamp ps) {
        super(ps);
    }

    public PanStamp getPanStamp() {
        return (PanStamp) getUserObject();
    }

    @Override
    protected void start() {
        try {
            getPanStamp().addListener(this);
            List<Register> regs = getPanStamp().getRegisters();
            for (Register reg : regs) {
                addNode(reg);

            }
        } catch (GatewayException ex) {
            Logger.getLogger(PanStampNode.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    @Override
    Type getType() {
        return Type.PANSTAMP;
    }

    @Override
    public void deviceUpdated(PanStampEvent ev) {
        switch (ev.getType()) {
            case PRODUCT_CODE_UPDATE: {
                try {
                    for (Register reg : ev.getDevice().getRegisters()) {
                        RegisterNode rn = nodes.get(reg);
                        if (rn == null) {
                            addNode(reg);
                            reload();
                        } else {
                            rn.update(reg);
                            rn.reload();
                        }
                    }
                } catch (GatewayException ex) {
                    Logger.getLogger(PanStampNode.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            break;
            case SYNC_STATE_CHANGE : {
                System.out.printf("%s\n", ev.getDevice().getAddress());
            }
        }
    }

    private void addNode(Register reg) {
        RegisterNode rn = new RegisterNode(reg);
        addToTree(rn, this);
        rn.start();
        nodes.put(reg, rn);
    }

    private Map<Register, RegisterNode> nodes = new HashMap<>();

}<commit_msg>Added support for register detection<commit_after>package me.legrange.panstamp.gui.tree;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import me.legrange.panstamp.GatewayException;
import me.legrange.panstamp.PanStamp;
import me.legrange.panstamp.PanStampEvent;
import me.legrange.panstamp.PanStampListener;
import me.legrange.panstamp.Register;

/**
 *
 * @author gideon
 */
public class PanStampNode extends SWAPNode implements PanStampListener {

    public PanStampNode(PanStamp ps) {
        super(ps);
    }

    public PanStamp getPanStamp() {
        return (PanStamp) getUserObject();
    }

    @Override
    protected void start() {
        try {
            getPanStamp().addListener(this);
            List<Register> regs = getPanStamp().getRegisters();
            for (Register reg : regs) {
                addNode(reg);

            }
        } catch (GatewayException ex) {
            Logger.getLogger(PanStampNode.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    @Override
    Type getType() {
        return Type.PANSTAMP;
    }

    @Override
    public void deviceUpdated(PanStampEvent ev) {
        switch (ev.getType()) {
            case PRODUCT_CODE_UPDATE: {
                try {
                    for (Register reg : ev.getDevice().getRegisters()) {
                        RegisterNode rn = nodes.get(reg);
                        if (rn == null) {
                            addNode(reg);
                            reload();
                        } else {
                            rn.update(reg);
                            rn.reload();
                        }
                    }
                } catch (GatewayException ex) {
                    Logger.getLogger(PanStampNode.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            break;
            case SYNC_STATE_CHANGE: {
                System.out.printf("%s\n", ev.getDevice().getAddress());
            }
            break;
            case REGISTER_DETECTED:
                Register reg = ev.getRegister();
                if (nodes.get(reg) == null) {
                    addNode(reg);
                }
        }
    }

    private void addNode(Register reg) {
        RegisterNode rn = new RegisterNode(reg);
        addToTree(rn, this);
        rn.start();
        nodes.put(reg, rn);
    }

    private Map<Register, RegisterNode> nodes = new HashMap<>();

}
{'fraction_non_alphanumeric': 0.10752911813643927, 'fraction_numerical': 0.0, 'mean_word_length': 1.5994594594594596, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3107755', 'n_tokens_mistral': 1392, 'n_tokens_neox': 1347, 'n_words': 256}