All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.harium.suneidesis.knowledge.material.Molecule Maven / Gradle / Ivy

There is a newer version: 1.6.8
Show newest version
package com.harium.suneidesis.knowledge.material;

import com.harium.suneidesis.knowledge.concept.Concept;

import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;

public class Molecule extends Concept {
    protected Map> bonds;

    public Molecule() {
    }

    public Molecule(String name) {
        super(name);
    }

    public void add(Atom atom) {
        init();
        bonds.put(atom, new HashSet());
    }

    private void init() {
        if (bonds == null) {
            bonds = new LinkedHashMap<>();
        }
    }

    public void add(Atom... atoms) {
        for (Atom atom : atoms) {
            add(atom);
        }
    }

    public void bond(Atom atom, Atom otherAtom) {
        init();
        if (!this.bonds.containsKey(atom)) {
            throw new RuntimeException("Atom is Missing: " + atom);
        } else if (!this.bonds.containsKey(otherAtom)) {
            throw new RuntimeException("Atom is Missing: " + otherAtom);
        }

        Set originBonds = this.bonds(atom);
        originBonds.add(otherAtom);

        Set destinationBonds = this.bonds(otherAtom);
        destinationBonds.add(atom);
    }

    public int size() {
        return bonds.size();
    }

    public Set bonds(Atom atom) {
        return this.bonds.get(atom);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy