[Lutinutil-commits] r793 - in branches/lutinutil-sans-vcs/lutinutil/src/java/org/codelutin/util: . config
Author: tchemit Date: 2008-04-27 12:00:51 +0000 (Sun, 27 Apr 2008) New Revision: 793 Added: branches/lutinutil-sans-vcs/lutinutil/src/java/org/codelutin/util/config/ branches/lutinutil-sans-vcs/lutinutil/src/java/org/codelutin/util/config/Config.java branches/lutinutil-sans-vcs/lutinutil/src/java/org/codelutin/util/config/IdentityConfig.java branches/lutinutil-sans-vcs/lutinutil/src/java/org/codelutin/util/config/IdentityConfigProperty.java branches/lutinutil-sans-vcs/lutinutil/src/java/org/codelutin/util/config/SimpleConfig.java branches/lutinutil-sans-vcs/lutinutil/src/java/org/codelutin/util/config/SimpleIdentityConfig.java Log: add config based on an Enum of properties add identity config and his implentation Added: branches/lutinutil-sans-vcs/lutinutil/src/java/org/codelutin/util/config/Config.java =================================================================== --- branches/lutinutil-sans-vcs/lutinutil/src/java/org/codelutin/util/config/Config.java (rev 0) +++ branches/lutinutil-sans-vcs/lutinutil/src/java/org/codelutin/util/config/Config.java 2008-04-27 12:00:51 UTC (rev 793) @@ -0,0 +1,32 @@ +/** + * # #% Copyright (C) 2008 Code Lutin, Tony Chemit + * This program is free software; you + * can redistribute it and/or modify it under the terms of the GNU General + * Public License as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. This program is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU General Public License for more details. You + * should have received a copy of the GNU General Public License along with this + * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place + * - Suite 330, Boston, MA 02111-1307, USA. + * # #% + */ +package org.codelutin.util.config; + +import java.util.EnumMap; + +/** + * config contract based on a Enum to obtain properties + * + * @author chemit + */ +public interface Config<E extends Enum<E>> { + + EnumMap<E, Object> getProperties(); + + void setProperties(EnumMap<E, Object> properties); + + void setProperty(E key, Object value); + +} \ No newline at end of file Added: branches/lutinutil-sans-vcs/lutinutil/src/java/org/codelutin/util/config/IdentityConfig.java =================================================================== --- branches/lutinutil-sans-vcs/lutinutil/src/java/org/codelutin/util/config/IdentityConfig.java (rev 0) +++ branches/lutinutil-sans-vcs/lutinutil/src/java/org/codelutin/util/config/IdentityConfig.java 2008-04-27 12:00:51 UTC (rev 793) @@ -0,0 +1,37 @@ +/** + * # #% Copyright (C) 2008 Code Lutin, Tony Chemit + * This program is free software; you + * can redistribute it and/or modify it under the terms of the GNU General + * Public License as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. This program is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU General Public License for more details. You + * should have received a copy of the GNU General Public License along with this + * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place + * - Suite 330, Boston, MA 02111-1307, USA. + * # #% + */ +package org.codelutin.util.config; + + +/** + * Definition of an identity + * + * @author chemit + */ +public interface IdentityConfig extends Config<IdentityConfigProperty> { + + String getFirstName(); + + String getLastName(); + + String getEmail(); + + void setFirstName(String firstName); + + void setLastName(String lastName); + + void setEmail(String email); + +} \ No newline at end of file Added: branches/lutinutil-sans-vcs/lutinutil/src/java/org/codelutin/util/config/IdentityConfigProperty.java =================================================================== --- branches/lutinutil-sans-vcs/lutinutil/src/java/org/codelutin/util/config/IdentityConfigProperty.java (rev 0) +++ branches/lutinutil-sans-vcs/lutinutil/src/java/org/codelutin/util/config/IdentityConfigProperty.java 2008-04-27 12:00:51 UTC (rev 793) @@ -0,0 +1,35 @@ +/** + * ##% Copyright (C) 2008 Code Lutin, Tony Chemit + * This program is free software; you + * can redistribute it and/or modify it under the terms of the GNU General + * Public License as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. This program is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU General Public License for more details. You + * should have received a copy of the GNU General Public License along with this + * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place + * - Suite 330, Boston, MA 02111-1307, USA. + * ##% + */ +package org.codelutin.util.config; + +/** + * Enumaration of properties to be used in a {@link org.codelutin.util.config.IdentityConfig} + * + * @author chemit + * @see IdentityConfig + */ +public enum IdentityConfigProperty { + + /** property <code>name</code>, first name of user */ + firstName, + + /** property <code>type</code>, lastname of user */ + lastName, + + /** property <code>email</code>, email of user */ + email + + //TODO add locale + encoding +} \ No newline at end of file Added: branches/lutinutil-sans-vcs/lutinutil/src/java/org/codelutin/util/config/SimpleConfig.java =================================================================== --- branches/lutinutil-sans-vcs/lutinutil/src/java/org/codelutin/util/config/SimpleConfig.java (rev 0) +++ branches/lutinutil-sans-vcs/lutinutil/src/java/org/codelutin/util/config/SimpleConfig.java 2008-04-27 12:00:51 UTC (rev 793) @@ -0,0 +1,62 @@ +/** + * # #% Copyright (C) 2008 Code Lutin, Tony Chemit + * This program is free software; you + * can redistribute it and/or modify it under the terms of the GNU General + * Public License as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. This program is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU General Public License for more details. You + * should have received a copy of the GNU General Public License along with this + * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place + * - Suite 330, Boston, MA 02111-1307, USA. + * # #% + */ +package org.codelutin.util.config; + +import org.codelutin.util.config.Config; + +/** + * simple config implementation based on a Enum to obtain properties + * + * @author chemit + */ +public class SimpleConfig<E extends Enum<E>> implements Config<E> { + + protected java.util.EnumMap<E, Object> properties; + + public SimpleConfig(Class<E> klass) { + this.properties = new java.util.EnumMap<E, Object>(klass); + } + + public java.util.EnumMap<E, Object> getProperties() { + return properties.clone(); + } + + public void setProperties(java.util.EnumMap<E, Object> properties) { + for (java.util.Map.Entry<E, Object> entry : properties.entrySet()) { + setProperty(entry.getKey(), entry.getValue()); + } + } + + public void setProperty(E key, Object value) { + if (value == null && properties.containsKey(key)) { + properties.remove(key); + } else { + properties.put(key, value); + } + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + if (properties.isEmpty()) { + sb.append(" empty"); + } else { + for (java.util.Map.Entry<E, Object> entry : properties.entrySet()) { + sb.append(", ").append(entry.getKey()).append(':').append(entry.getValue()); + } + } + return super.toString() + '<' + sb.toString().substring(2) + '>'; + } +} Added: branches/lutinutil-sans-vcs/lutinutil/src/java/org/codelutin/util/config/SimpleIdentityConfig.java =================================================================== --- branches/lutinutil-sans-vcs/lutinutil/src/java/org/codelutin/util/config/SimpleIdentityConfig.java (rev 0) +++ branches/lutinutil-sans-vcs/lutinutil/src/java/org/codelutin/util/config/SimpleIdentityConfig.java 2008-04-27 12:00:51 UTC (rev 793) @@ -0,0 +1,59 @@ +/** + * # #% Copyright (C) 2008 Code Lutin, Tony Chemit + * This program is free software; you + * can redistribute it and/or modify it under the terms of the GNU General + * Public License as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. This program is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU General Public License for more details. You + * should have received a copy of the GNU General Public License along with this + * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place + * - Suite 330, Boston, MA 02111-1307, USA. + * # #% + */ +package org.codelutin.util.config; + +import static org.codelutin.util.config.IdentityConfigProperty.email; +import static org.codelutin.util.config.IdentityConfigProperty.firstName; +import static org.codelutin.util.config.IdentityConfigProperty.lastName; + +/** @author chemit */ +public class SimpleIdentityConfig extends SimpleConfig<IdentityConfigProperty> implements IdentityConfig { + + public SimpleIdentityConfig() { + super(IdentityConfigProperty.class); + } + + public SimpleIdentityConfig(String firstName, String lastName, String email) { + this(); + setFirstName(firstName); + setLastName(lastName); + setEmail(email); + } + + public String getFirstName() { + return (String) properties.get(firstName); + } + + public String getLastName() { + return (String) properties.get(lastName); + } + + public String getEmail() { + return (String) properties.get(email); + } + + public void setFirstName(String newFirstName) { + setProperty(firstName, newFirstName); + } + + public void setLastName(String newLastName) { + setProperty(lastName, newLastName); + } + + public void setEmail(String newEmail) { + setProperty(email, newEmail); + } + +}
participants (1)
-
tchemit@users.labs.libre-entreprise.org