com.harium.suneidesis.knowledge.material.Molecule Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of core Show documentation
Show all versions of core Show documentation
Project to represent knowledge
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