package skills;
import AXJava.AXCmdBreaker;
import LivinGrimoire.Chobits;
import LivinGrimoire.DiSkillV2;
import java.util.Hashtable;
public class TheShell extends DiSkillV2 {
private Chobits chobit;
private Hashtable<String,DiSkillV2> allSkills = new Hashtable<>();
private AXCmdBreaker installer = new AXCmdBreaker("install");
private AXCmdBreaker uninstaller = new AXCmdBreaker("abolish");
private String temp = "";
public TheShell(Chobits chobit) {
this.chobit = chobit;
}
public void addSkill(String skillName, DiSkillV2 skill){
allSkills.put(skillName,skill);
}
// shell methods
private int sh_addSkill(String skillKey){
if (!allSkills.containsKey(skillKey)){
return 0; // skill does not exist
}
if (chobit.containsSkill(allSkills.get(skillKey))){
return 1; // skill already installed
}
chobit.addSkill(allSkills.get(skillKey));
return 2; // skill installed
}
private int sh_removeSkill(String skillKey){
if (!allSkills.containsKey(skillKey)){
return 0; // skill does not exist
}
if (chobit.containsSkill(allSkills.get(skillKey))){
chobit.removeSkill(allSkills.get(skillKey));
return 1; // skill uninstalled
}
return 2; // skill is not installed
}
private void sh_removeAllSkills(){chobit.clearSkills();}
@Override
public void input(String ear, String skin, String eye) {
if (ear.equals("remove all skills")){
sh_removeAllSkills();
setVerbatimAlg(4, "all skills removed");
return;
}
temp = installer.extractCmdParam(ear);
if (!temp.isEmpty()){
switch (sh_addSkill(temp)){
case 0:
setVerbatimAlg(4, "skill does not exist");
break;
case 1:
setVerbatimAlg(4, "skill already installed");
break;
case 2:
setVerbatimAlg(4, "skill installed");
break;
}
temp = "";
return;
}
temp = uninstaller.extractCmdParam(ear);
if (!temp.isEmpty()){
switch (sh_removeSkill(temp)){
case 0:
setVerbatimAlg(4, "skill does not exist");
break;
case 1:
setVerbatimAlg(4, "skill uninstalled");
break;
case 2:
setVerbatimAlg(4, "skill is not installed");
break;
}
temp = "";
}
}
}
Brain b1 = new Brain();
TheShell shell = new TheShell(b1.logicChobit); // shell skill
// adding all skills:
shell.addSkill("hello world", new DiHelloWorld());
// ^ shell filled with skills
b1.hardwareChobit.addSkill(new DiSysOut()); // this skill prints output
System.out.println("no output:");
b1.doIt("hello", "",""); // nothing happens
System.out.println("adding skill using the shell:");
System.out.println(shell.engine.think("install hello world", "",""));
b1.doIt("install hello world", "","");
b1.doIt("hello", "","");
System.out.println("skill uninstall:");
System.out.println(shell.engine.think("abolish hello world", "",""));
b1.doIt("abolish hello world", "","");
b1.doIt("hello", "","");
package LivinGrimoire;
import skills.TheShell;
public class Sh_Brain extends Brain{
public TheShell shell = new TheShell(this.logicChobit);
String temp = "";
@Override
public void doIt(String ear, String skin, String eye) {
temp = shell.engine.think(ear, skin, eye);
if(temp.isEmpty()){
super.doIt(ear, skin, eye);
}
hardwareChobit.think(temp,skin,eye);
}
}
package skills;
import AXJava.AXCmdBreaker;
import LivinGrimoire.Chobits;
import LivinGrimoire.DiSkillV2;
import java.util.Hashtable;
public class TheShell extends DiSkillV2 {
public Chobits shellChobit = new Chobits();
private Chobits logicChobit;
private Chobits hardwareChobit;
private Hashtable<String,DiSkillV2> logicSkills = new Hashtable<>(); // all logic skills
private Hashtable<String,DiSkillV2> hardwareSkills = new Hashtable<>(); // all hardware skills
private AXCmdBreaker installer = new AXCmdBreaker("install");
private AXCmdBreaker uninstaller = new AXCmdBreaker("abolish");
private String temp = "";
public TheShell(Chobits logicChobit, Chobits hardwareChobit) {
this.logicChobit = logicChobit;
this.hardwareChobit = hardwareChobit;
shellChobit.addSkill(this);
}
public void addLogicSkill(String skillName, DiSkillV2 skill){
logicSkills.put(skillName,skill);
}
public void addHardwareSkill(String skillName, DiSkillV2 skill){
hardwareSkills.put(skillName,skill);
}
// shell methods
private int sh_addSkill(String skillKey){
if (!(logicSkills.containsKey(skillKey)||hardwareSkills.containsKey(skillKey))){
return 0; // skill does not exist
}
// find the skill:
if(logicSkills.containsKey(skillKey)){
DiSkillV2 ref = logicSkills.get(skillKey);
if(logicChobit.containsSkill(ref)){
return 1; // logic skill already installed
}
logicChobit.addSkill(ref);
return 2; // logic skill has been installed
}
DiSkillV2 ref = hardwareSkills.get(skillKey);
if(hardwareChobit.containsSkill(ref)){
return 3; // hardware skill already installed
}
hardwareChobit.addSkill(ref);
return 4; // hardware skill has been installed
}
private int sh_removeSkill(String skillKey){
if (!(logicSkills.containsKey(skillKey)||hardwareSkills.containsKey(skillKey))){
return 0; // skill does not exist
}
if(logicSkills.containsKey(skillKey)){
DiSkillV2 ref = logicSkills.get(skillKey);
if(logicChobit.containsSkill(ref)){
logicChobit.removeSkill(ref);
return 1; // logic skill has been uninstalled
}
return 2; // logic skill is not installed
}
DiSkillV2 ref = hardwareSkills.get(skillKey);
if(hardwareChobit.containsSkill(ref)){
hardwareChobit.removeSkill(ref);
return 3; // hardware skill has been uninstalled
}
return 4; // hardware skill is not installed
}
private void sh_removeAllSkills(){logicChobit.clearSkills();hardwareChobit.clearSkills();}
@Override
public void input(String ear, String skin, String eye) {
if (ear.equals("remove all skills")){
sh_removeAllSkills();
return;
}
temp = installer.extractCmdParam(ear);
if (!temp.isEmpty()){
switch (sh_addSkill(temp)){
case 0:
setVerbatimAlg(4, "skill does not exist");
break;
case 1:
setVerbatimAlg(4, "logic skill already installed");
break;
case 2:
setVerbatimAlg(4, "logic skill has been installed");
break;
case 3:
setVerbatimAlg(4, "hardware skill already installed");
break;
case 4:
setVerbatimAlg(4, "hardware skill has been installed");
break;
}
temp = "";
return;
}
temp = uninstaller.extractCmdParam(ear);
if (!temp.isEmpty()){
switch (sh_removeSkill(temp)){
case 0:
setVerbatimAlg(4, "skill does not exist");
break;
case 1:
setVerbatimAlg(4, "logic skill has been uninstalled");
break;
case 2:
setVerbatimAlg(4, "logic skill is not installed");
break;
case 3:
setVerbatimAlg(4, "hardware skill has been uninstalled");
break;
case 4:
setVerbatimAlg(4, "hardware skill is not installed");
break;
}
temp = "";
}
}
}
package LivinGrimoire;
import skills.TheShell;
public class Sh_Brain extends Brain{
private TheShell shell = new TheShell(logicChobit,hardwareChobit);
private String temp = "";
public void addLogicSkill(String skillName, DiSkillV2 skill){
shell.addLogicSkill(skillName, skill);
}
public void addHardwareSkill(String skillName, DiSkillV2 skill){
shell.addHardwareSkill(skillName, skill);
}
@Override
public void doIt(String ear, String skin, String eye) {
temp = shell.shellChobit.think(ear, skin, eye);
if(temp.isEmpty()){
super.doIt(ear, skin, eye);
}
hardwareChobit.think(temp,skin,eye);
}
}
package LivinGrimoire;
public class Sh_Brain extends Brain{
private TheShell shell = new TheShell(logicChobit,hardwareChobit);
private String temp = "";
public void addLogicSkill(String skillName, DiSkillV2 skill){
shell.addLogicSkill(skillName, skill);
}
public void addHardwareSkill(String skillName, DiSkillV2 skill){
shell.addHardwareSkill(skillName, skill);
}
@Override
public void doIt(String ear, String skin, String eye) {
temp = shell.shellChobit.think(ear, skin, eye);
if(temp.isEmpty()){
super.doIt(ear, skin, eye);
}
hardwareChobit.think(temp,skin,eye);
}
}
package LivinGrimoire;
import AXJava.AXCmdBreaker;
import LivinGrimoire.Chobits;
import LivinGrimoire.DiSkillV2;
import java.util.Hashtable;
public class TheShell extends DiSkillV2 {
public Chobits shellChobit = new Chobits();
private Chobits logicChobit;
private Chobits hardwareChobit;
private Hashtable<String,DiSkillV2> logicSkills = new Hashtable<>(); // all logic skills
private Hashtable<String,DiSkillV2> hardwareSkills = new Hashtable<>(); // all hardware skills
private AXCmdBreaker installer = new AXCmdBreaker("install");
private AXCmdBreaker uninstaller = new AXCmdBreaker("abolish");
private String temp = "";
public TheShell(Chobits logicChobit, Chobits hardwareChobit) {
this.logicChobit = logicChobit;
this.hardwareChobit = hardwareChobit;
shellChobit.addSkill(this);
}
public void addLogicSkill(String skillName, DiSkillV2 skill){
logicSkills.put(skillName,skill);
}
public void addHardwareSkill(String skillName, DiSkillV2 skill){
hardwareSkills.put(skillName,skill);
}
// shell methods
private int sh_addSkill(String skillKey){
if (!(logicSkills.containsKey(skillKey)||hardwareSkills.containsKey(skillKey))){
return 0; // skill does not exist
}
// find the skill:
if(logicSkills.containsKey(skillKey)){
DiSkillV2 ref = logicSkills.get(skillKey);
if(logicChobit.containsSkill(ref)){
return 1; // logic skill already installed
}
logicChobit.addSkill(ref);
return 2; // logic skill has been installed
}
DiSkillV2 ref = hardwareSkills.get(skillKey);
if(hardwareChobit.containsSkill(ref)){
return 3; // hardware skill already installed
}
hardwareChobit.addSkill(ref);
return 4; // hardware skill has been installed
}
private int sh_removeSkill(String skillKey){
if (!(logicSkills.containsKey(skillKey)||hardwareSkills.containsKey(skillKey))){
return 0; // skill does not exist
}
if(logicSkills.containsKey(skillKey)){
DiSkillV2 ref = logicSkills.get(skillKey);
if(logicChobit.containsSkill(ref)){
logicChobit.removeSkill(ref);
return 1; // logic skill has been uninstalled
}
return 2; // logic skill is not installed
}
DiSkillV2 ref = hardwareSkills.get(skillKey);
if(hardwareChobit.containsSkill(ref)){
hardwareChobit.removeSkill(ref);
return 3; // hardware skill has been uninstalled
}
return 4; // hardware skill is not installed
}
private void sh_removeAllSkills(){logicChobit.clearSkills();hardwareChobit.clearSkills();}
@Override
public void input(String ear, String skin, String eye) {
if (ear.equals("remove all skills")){
sh_removeAllSkills();
return;
}
temp = installer.extractCmdParam(ear);
if (!temp.isEmpty()){
switch (sh_addSkill(temp)){
case 0:
setVerbatimAlg(4, "skill does not exist");
break;
case 1:
setVerbatimAlg(4, "logic skill already installed");
break;
case 2:
setVerbatimAlg(4, "logic skill has been installed");
break;
case 3:
setVerbatimAlg(4, "hardware skill already installed");
break;
case 4:
setVerbatimAlg(4, "hardware skill has been installed");
break;
}
temp = "";
return;
}
temp = uninstaller.extractCmdParam(ear);
if (!temp.isEmpty()){
switch (sh_removeSkill(temp)){
case 0:
setVerbatimAlg(4, "skill does not exist");
break;
case 1:
setVerbatimAlg(4, "logic skill has been uninstalled");
break;
case 2:
setVerbatimAlg(4, "logic skill is not installed");
break;
case 3:
setVerbatimAlg(4, "hardware skill has been uninstalled");
break;
case 4:
setVerbatimAlg(4, "hardware skill is not installed");
break;
}
temp = "";
}
}
}
Sh_Brain b1 = new Sh_Brain();
// adding all skills:
b1.addLogicSkill("hello world", new DiHelloWorld());
b1.addHardwareSkill("output",new DiSysOut()); // this skill prints output
// ^ shell filled with skills
b1.doIt("install output", "","");
b1.doIt("install hello world", "","");
b1.doIt("hello", "","");
b1.doIt("abolish hello world", "","");
b1.doIt("hello", "","");
System.out.println("skill reinstall:");
b1.doIt("install hello world", "","");
b1.doIt("hello", "","");
package skills;
import AXJava.AXCmdBreaker;
import LivinGrimoire.Chobits;
import LivinGrimoire.DiSkillV2;
import java.util.Hashtable;
public class TheShell extends DiSkillV2 {
public Chobits shellChobit = new Chobits();
private Chobits logicChobit;
private Chobits hardwareChobit;
private Hashtable<String,DiSkillV2> logicSkills = new Hashtable<>(); // all logic skills
private Hashtable<String,DiSkillV2> hardwareSkills = new Hashtable<>(); // all hardware skills
private AXCmdBreaker installer = new AXCmdBreaker("install");
private AXCmdBreaker uninstaller = new AXCmdBreaker("abolish");
private String temp = "";
public TheShell(Sh_Brain b1) {
this.logicChobit = b1.logicChobit;
this.hardwareChobit = b1.hardwareChobit;
shellChobit.addSkill(this);
}
public void addLogicSkill(String skillName, DiSkillV2 skill){
logicSkills.put(skillName,skill);
}
public void addHardwareSkill(String skillName, DiSkillV2 skill){
hardwareSkills.put(skillName,skill);
}
// shell methods
private int sh_addSkill(String skillKey){
if (!(logicSkills.containsKey(skillKey)||hardwareSkills.containsKey(skillKey))){
return 0; // skill does not exist
}
// find the skill:
if(logicSkills.containsKey(skillKey)){
DiSkillV2 ref = logicSkills.get(skillKey);
if(logicChobit.containsSkill(ref)){
return 1; // logic skill already installed
}
logicChobit.addSkill(ref);
return 2; // logic skill has been installed
}
DiSkillV2 ref = hardwareSkills.get(skillKey);
if(hardwareChobit.containsSkill(ref)){
return 3; // hardware skill already installed
}
hardwareChobit.addSkill(ref);
return 4; // hardware skill has been installed
}
private int sh_removeSkill(String skillKey){
if (!(logicSkills.containsKey(skillKey)||hardwareSkills.containsKey(skillKey))){
return 0; // skill does not exist
}
if(logicSkills.containsKey(skillKey)){
DiSkillV2 ref = logicSkills.get(skillKey);
if(logicChobit.containsSkill(ref)){
logicChobit.removeSkill(ref);
return 1; // logic skill has been uninstalled
}
return 2; // logic skill is not installed
}
DiSkillV2 ref = hardwareSkills.get(skillKey);
if(hardwareChobit.containsSkill(ref)){
hardwareChobit.removeSkill(ref);
return 3; // hardware skill has been uninstalled
}
return 4; // hardware skill is not installed
}
private void sh_removeAllSkills(){logicChobit.clearSkills();hardwareChobit.clearSkills();}
@Override
public void input(String ear, String skin, String eye) {
if (ear.equals("remove all skills")){
sh_removeAllSkills();
return;
}
temp = installer.extractCmdParam(ear);
if (!temp.isEmpty()){
switch (sh_addSkill(temp)){
case 0:
setVerbatimAlg(4, "skill does not exist");
break;
case 1:
setVerbatimAlg(4, "logic skill already installed");
break;
case 2:
setVerbatimAlg(4, "logic skill has been installed");
break;
case 3:
setVerbatimAlg(4, "hardware skill already installed");
break;
case 4:
setVerbatimAlg(4, "hardware skill has been installed");
break;
}
temp = "";
return;
}
temp = uninstaller.extractCmdParam(ear);
if (!temp.isEmpty()){
switch (sh_removeSkill(temp)){
case 0:
setVerbatimAlg(4, "skill does not exist");
break;
case 1:
setVerbatimAlg(4, "logic skill has been uninstalled");
break;
case 2:
setVerbatimAlg(4, "logic skill is not installed");
break;
case 3:
setVerbatimAlg(4, "hardware skill has been uninstalled");
break;
case 4:
setVerbatimAlg(4, "hardware skill is not installed");
break;
}
temp = "";
}
}
}
package skills;
import LivinGrimoire.Brain;
import LivinGrimoire.DiSkillV2;
public class Sh_Brain extends Brain {
private TheShell shell = new TheShell(this);
private String temp = "";
public void addLogicSkill(String skillName, DiSkillV2 skill){
shell.addLogicSkill(skillName, skill);
}
public void addHardwareSkill(String skillName, DiSkillV2 skill){
shell.addHardwareSkill(skillName, skill);
}
public void setShell(TheShell shell) {
// for using TheShell skill sub class objects with different input
// method logic
this.shell = shell;
}
@Override
public void doIt(String ear, String skin, String eye) {
temp = shell.shellChobit.think(ear, skin, eye);
if(temp.isEmpty()){
super.doIt(ear, skin, eye);
}
hardwareChobit.think(temp,skin,eye);
}
}