Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package benedict.zhang.addon.roleplaying.model; import benedict.zhang.addon.roleplaying.core.factory.RolePlayingConfigurationFactory; import java.lang.reflect.InvocationTargetException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; import javafx.beans.property.SimpleStringProperty; import javafx.collections.FXCollections; import javafx.collections.ListChangeListener; import javafx.collections.ObservableList; import org.apache.commons.beanutils.BeanUtils; /** * * @author bzhang097 */ public final class RolePlayingConfiguration { private SimpleStringProperty addonName; private SimpleStringProperty spellCastInQueueMax; private SimpleStringProperty spellLockGlobal; private SimpleStringProperty dateGeneration; private SimpleStringProperty addonDigest; private Date generateDate; private List spells; private String id; private ObservableList<SpellConfiguration> spellList; public ObservableList<SpellConfiguration> getSpellList() { return spellList; } public void setSpellList(ObservableList<SpellConfiguration> spellList) { this.spellList = spellList; } public void setSpells(List<SpellConfiguration> spells) { List<SpellConfiguration> temp = new ArrayList<>(); temp.clear(); temp.addAll(spells); this.spellList.clear(); this.spellList.addAll(temp); } public List<SpellConfiguration> getSpells() { return this.spells; } public RolePlayingConfiguration() { this.addonName = new SimpleStringProperty(""); this.spellCastInQueueMax = new SimpleStringProperty(""); this.spellLockGlobal = new SimpleStringProperty(""); this.spellList = FXCollections.observableArrayList(); this.spells = new ArrayList<>(); this.dateGeneration = new SimpleStringProperty(""); this.addonDigest = new SimpleStringProperty(""); this.generateDate = new Date(); spellList.addListener((ListChangeListener.Change<? extends SpellConfiguration> c) -> { c.next(); StringBuilder sb = new StringBuilder(); if (spellList.size() > 0) { sb.append(this.getAddonName()).append(" : "); sb.append("[").append(this.spellList.get(0).getSpellName()); for (int i = 1; i < spellList.size(); i++) { sb.append(",").append(spellList.get(i).getSpellName()); } ; sb.append("]"); } this.setAddonDigest(sb.toString()); sb.delete(0, sb.length()); this.spells.clear(); for (SpellConfiguration spell : this.spellList) { this.spells.add(spell); } }); } public String getId() { return id; } public void setId(String id) { this.id = id; } public String getAddonName() { return addonName.get(); } public void setAddonName(String addonName) { this.addonName.set(addonName); } public String getSpellCastInQueueMax() { return spellCastInQueueMax.get(); } public void setSpellCastInQueueMax(String spellCastInQueueMax) { this.spellCastInQueueMax.set(spellCastInQueueMax); } public String getSpellLockGlobal() { return spellLockGlobal.get(); } public void setSpellLockGlobal(String spellLockGlobal) { this.spellLockGlobal.set(spellLockGlobal); } public SimpleStringProperty addonName() { return addonName; } public SimpleStringProperty spellCastInQueueMax() { return spellCastInQueueMax; } public SimpleStringProperty spellLockGlobal() { return spellLockGlobal; } public String getAddonDigest() { return this.addonDigest.get(); } public void setAddonDigest(String addDigest) { this.addonDigest.set(addDigest); } public Date getGenerateDate() { return new Date(); } public void setGenerateDate(Date generateDate) { this.generateDate = new Date(); } public String getDateGeneration() { SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd"); format.format(this.getGenerateDate()); return format.format(this.getGenerateDate()); } public void setDateGeneration(String dateGeneration) { SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd"); String date = format.format(this.getGenerateDate()); this.dateGeneration.set(date); } public SimpleStringProperty DateGeneration() { return this.dateGeneration; } public benedict.zhang.addon.roleplaying.core.datatype.RolePlayingConfiguration toRolePlayingConfiguration() { benedict.zhang.addon.roleplaying.core.datatype.RolePlayingConfiguration roleplayingConfiguration = RolePlayingConfigurationFactory .getInstance().getRolePlayingConfiguration(); roleplayingConfiguration.setSpellConfiguration(toSpellConfigurationList()); roleplayingConfiguration.setAddonName(this.getAddonName()); roleplayingConfiguration.setSpellCastInQueueMax(this.getSpellCastInQueueMax()); roleplayingConfiguration.setSpellLockGlobal(this.getSpellLockGlobal()); return roleplayingConfiguration; } public List<benedict.zhang.addon.roleplaying.core.datatype.SpellConfiguration> toSpellConfigurationList() { List<benedict.zhang.addon.roleplaying.core.datatype.SpellConfiguration> spellConfigList; spellConfigList = new ArrayList<>(); for (SpellConfiguration spellConfiguration : spellList) { spellConfigList.add(spellConfiguration.toSpellConfiguration()); } return spellConfigList; } public void copyRoleplayingConfiguration(RolePlayingConfiguration roleplayingConfig) { try { //this.setId(roleplayingConfig.getId()); this.setAddonDigest(roleplayingConfig.getAddonDigest()); this.setAddonName(roleplayingConfig.getAddonName()); this.setDateGeneration(roleplayingConfig.getDateGeneration()); this.setId(roleplayingConfig.getId()); this.setSpellCastInQueueMax(roleplayingConfig.getSpellCastInQueueMax()); this.setSpellLockGlobal(roleplayingConfig.getSpellLockGlobal()); this.setGenerateDate(new Date()); this.setSpells(roleplayingConfig.getSpells()); } catch (Exception ex) { return; } } }