Generics for HashMap

Can sumone please tell me how to implement "Generics for Hashmap in java"
Please guide me in the required direction.

http://www.google.co.za/search?hl=en&q=%2Bjava+%2Bgenerics+%2Bhashmap&meta=

Similar Messages

  • " ID Generic for the flexfield segment Address Style does not exist"

    "ID Generic for the flexfield segment Address Style does not exist in the Value set $Flex$DF_contexts"
    Can some one help with this iRecruitment issue.

    Just enable the context for the other countries within the definition of the address flexfield. You should then get a drop down list of countries, select it and then the flexfield definition of the address will refresh according to your selection.
    Check that the original definition of the address flexfield on the personalisation page includes all the other contexts.
    Regards
    Tim

  • Can't build gcc-4.1.2; error: bad value (generic) for -mtune= switch

    I need this specific version of gcc, so I got the old PKDBUILD from svn, see below. However when gcc compiles I run into this compile error:
    TARGET_CPU_DEFAULT="" \
    HEADERS="auto-host.h ansidecl.h" DEFINES="USED_FOR_TARGET " \
    /bin/sh ../../gcc-4.1.2/gcc/mkconfig.sh tconfig.h
    ./xgcc -B./ -B/usr/i686-pc-linux-gnu/bin/ -isystem /usr/i686-pc-linux-gnu/include -isystem /usr/i686-pc-linux-gnu/sys-include -L/home/chelg/tmp/abs/gcc-4.1/src/gcc-build/gcc/../ld -O2 -O2 -march=i686 -mtune=generic -O2 -pipe -DIN_GCC -W -Wall -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -isystem ./include -I. -I. -I../../gcc-4.1.2/gcc -I../../gcc-4.1.2/gcc/. -I../../gcc-4.1.2/gcc/../include -I../../gcc-4.1.2/gcc/../libcpp/include -g0 -finhibit-size-directive -fno-inline-functions -fno-exceptions -fno-zero-initialized-in-bss -fno-unit-at-a-time -fno-omit-frame-pointer \
    -c ../../gcc-4.1.2/gcc/crtstuff.c -DCRT_BEGIN \
    -o crtbegin.o
    ../../gcc-4.1.2/gcc/crtstuff.c:1: error: bad value (generic) for -mtune= switch
    make[2]: *** [crtbegin.o] Error 1
    make[2]: Leaving directory `/home/chelg/tmp/abs/gcc-4.1/src/gcc-build/gcc'
    make[1]: *** [stage1_build] Error 2
    make[1]: Leaving directory `/home/chelg/tmp/abs/gcc-4.1/src/gcc-build/gcc'
    make: *** [bootstrap] Error 2
    ==> ERROR: Build Failed.
    Aborting...
    Here is the PKGBUILD I use:
    # $Id: PKGBUILD,v 1.60 2007/02/14 14:53:50 jgc Exp $
    # Maintainer: Jan de Groot <[email protected]>
    pkgname=gcc
    pkgver=4.1.2
    pkgrel=3
    pkgdesc="The GNU Compiler Collection"
    arch=(i686 x86_64)
    url="http://gcc.gnu.org"
    depends=('glibc' 'binutils>=2.17')
    options=('!libtool')
    source=(ftp://gcc.gnu.org/pub/gcc/releases/gcc-${pkgver}/gcc-{core,g++,objc}-${pkgver}.tar.bz2
    ftp://gcc.gnu.org/pub/gcc/libstdc++/doxygen/libstdc++-man-4.0.0.tar.bz2
    DW_CFA_val.patch
    gcc_pure64.patch)
    md5sums=('2af3fb599635219171c6ae1f3034888a' '75c6d5fa3415d614314caf0f509e8933'
    'abda05c0ab99059e8f9e7a625361fd87' '2be86d2117c8fa7f9ec2845cc0660ab1'
    '078680c207f7cd490044d4a53edf158d' '1ceaa49e3a1d9f984ecc2893c43f7425')
    build() {
    export MAKEFLAGS="-j1"
    cd ${startdir}/src/gcc-${pkgver}
    # Don't install libiberty
    sed -i 's/install_to_$(INSTALL_DEST) //' libiberty/Makefile.in
    if [ "${CARCH}" = "x86_64" ]; then
    patch -Np1 -i ../gcc_pure64.patch || return 1
    fi
    patch -Np0 -i ${startdir}/src/DW_CFA_val.patch || return 1
    # Don't run fixincludes
    sed -i -e 's@\./fixinc\.sh@-c true@' gcc/Makefile.in
    mkdir ../gcc-build
    cd ../gcc-build
    ../gcc-${pkgver}/configure --prefix=/usr --enable-shared \
    --enable-languages=c,c++,objc --enable-threads=posix \
    --enable-__cxa_atexit --disable-multilib --libdir=/usr/lib \
    --libexecdir=/usr/lib --enable-clocale=gnu
    make bootstrap || return 1
    make DESTDIR=${startdir}/pkg install || return 1
    mkdir -p ${startdir}/pkg/lib
    (cd ${startdir}/pkg/lib; ln -s ../usr/bin/cpp)
    (cd ${startdir}/pkg/usr/bin; ln -sf gcc cc; ln -sf g++ c++)
    # install the libstdc++ man pages
    mkdir -p ${startdir}/pkg/usr/man/man3
    install -m644 ${startdir}/src/man/man3/* ${startdir}/pkg/usr/man/man3/
    Last edited by Phlogiston (2009-02-27 20:08:37)

    or here you go:
    # $Id: PKGBUILD,v 1.60 2007/02/14 14:53:50 jgc Exp $
    # Maintainer: Jan de Groot <[email protected]>
    pkgname=gcc-4.1
    pkgver=4.1.2
    pkgrel=3
    pkgdesc="The GNU Compiler Collection"
    arch=(i686 x86_64)
    url="http://gcc.gnu.org"
    depends=('glibc' 'binutils>=2.17')
    options=('!libtool')
    source=(ftp://gcc.gnu.org/pub/gcc/releases/gcc-${pkgver}/gcc-{core,g++,objc}-${pkgver}.tar.bz2
    ftp://gcc.gnu.org/pub/gcc/libstdc++/doxygen/libstdc++-man-4.0.0.tar.bz2
    DW_CFA_val.patch
    gcc_pure64.patch)
    md5sums=('2af3fb599635219171c6ae1f3034888a' '75c6d5fa3415d614314caf0f509e8933'
    'abda05c0ab99059e8f9e7a625361fd87' '2be86d2117c8fa7f9ec2845cc0660ab1'
    '078680c207f7cd490044d4a53edf158d' '1ceaa49e3a1d9f984ecc2893c43f7425')
    build() {
    export MAKEFLAGS="-j1"
    cd ${startdir}/src/gcc-${pkgver}
    # Don't install libiberty
    sed -i 's/install_to_$(INSTALL_DEST) //' libiberty/Makefile.in
    if [ "${CARCH}" = "x86_64" ]; then
    patch -Np1 -i ../gcc_pure64.patch || return 1
    fi
    patch -Np0 -i ${startdir}/src/DW_CFA_val.patch || return 1
    # Don't run fixincludes
    sed -i -e 's@\./fixinc\.sh@-c true@' gcc/Makefile.in
    mkdir ../gcc-build
    cd ../gcc-build
    ../gcc-${pkgver}/configure --prefix=/opt/gcc-4.1 --enable-shared \
    --enable-languages=c,c++,objc --enable-threads=posix \
    --enable-__cxa_atexit --disable-multilib \
    --enable-clocale=gnu
    make bootstrap || return 1
    make DESTDIR=${startdir}/pkg install || return 1
    mkdir -p ${startdir}/pkg/lib
    # (cd ${startdir}/pkg/lib; ln -s ../usr/bin/cpp)
    # (cd ${startdir}/pkg/usr/bin; ln -sf gcc cc; ln -sf g++ c++)
    # install the libstdc++ man pages
    mkdir -p ${startdir}/pkg/usr/man/man3
    install -m644 ${startdir}/src/man/man3/* ${startdir}/pkg/usr/man/man3/

  • Wrapper class for HashMap

    Why people write Wrapper class for HashMap? Why not directly use the HashMap?

    I thought that the term wrapper class is generally
    used to signify one class having an instance of
    another class inside it. And not one class
    deriving from another.
    But thats just me.I think that is just you. :)
    I consider "wrapping" as having a subset of the functionality of another class. This could be containing or extending, in my opinion.
    Consider:
    // only partially functional vector for JButtons...
    // class containing Vector
    public class JButtonVector
      Vector vec = new Vector();
      public void add(JButton button)
        vec.add(button);
      public JButton get(int index)
        if(index >= vec.size() || index < 0)
          throw new IllegalArgumentException(...);
        return (JButton)vec.get(index);
    // class extending Vector
    class JButtonVector2 extends Vector
      public void add(JButton but)
        super.add(but);
      public JButton get(int index)
        return (JButton)(super.get(index));
    }Problem with the second class is that it also allows adding of regular Objects. That might not be desirable (in this case, it is definitely not).

  • Right way to use generics for cellular automatons?

    Hi,
    i've got a question about using generic types in combination with subclassing (which should be used in a cellular automaton),
    In fact there are only 3 classes that are necessary to understand my problem:
    - Cell (abstract)
    - CellularAutomaton
    - SubclassedCell (extends Cell)
    These classeses work as follows:
    A cellular automaton holds some cell's with respect to the order they were added. The cell itself holds some properties and the most important function in this small "framework". This function is "performCellAction(CellularAutomaton ca)". It retrieves the "neighbor" cells from the given parameter and calculates a new state using these neighbors.
    The way i implemented this using generics is:
    public class CellularAutomaton<T extends Cell>{
      private List<T> cells;
      public T getLeftNeighbor(T cell) { ... } // gets the left neighbor of the given cell
      public T getRightNeighbor(T cell) { ... } // gets the left neighbor of the given cell
    public abstract class Cell [
      public void performCellAction(CellularAutomaton<? extends Cell> ca) {}
    public class SubclassedCell extends Cell {
      private String str;
      public void performCellAction(CellularAutomaton<? extends Cell> ca) {
        Cell left = ca.getLeftNeighbor();
        // PROBLEM:
        // How to call left.getStr() here???
        // How can i be sure that ca contains objects of class subclassedCell (or objects of subclasses of subclassedCell) ... and not objects of class cell or another subclasses cell
      public String getStr() {}
    }In fact i found "something like a solution", which looks like this:
    public class CellularAutomaton<T extends Cell>{
      private List<T> cells;
      public T getLeftNeighbor(T cell) { ... } // gets the left neighbor of the given cell
      public T getRightNeighbor(T cell) { ... } // gets the left neighbor of the given cell
      public void computer() {
        for (T cell: cells) {
          // compiler warning here!!
          cell.performCellAction(this);
    public abstract class Cell<T extends Cell<?>> [
      public void performCellAction(CellularAutomaton<T> ca) {}
    public class SubclassedCell extends Cell<SubclassedCell> {
      private String str;
      performCellAction(CellularAutomaton<SubclassedCell> ca) {
        SubclassedCell left = ca.getLeftNeighbor();
        left.getStr(); // works here
      public String getStr() {}
    }However, even in this "working" solution i get a compiler warning at the method CellularAutomaton->computer():
    The warning is Type safety: The method performCellAction(CellularAutomaton) belongs to the raw type Cell. References to generic type Cell<T> should be parametrized and Cell<T extends Cell<?>> also looks very uncommon to me.
    Is there a betted way to achieve the goal to access left.getStr() in the performCellAction of the subclassed cell??
    Regards,
    Niko

    I thought of that myself, but if i do this, i get the following error:
    The method performCellAction(CellularAutomaton<capture#1-of ?>) in the type Cell<capture#1-of ?> is not applicable for the arguments (CellularAutomaton<T>)

  • What's wildcards in generics for?

    To be honest, wildcards make me sick all the time. I've read through related chapters in 'core java' but still don't understand the purpose of using it.Pls take a look at the below example:
    package generics;
    import java.util.ArrayList;
    import java.util.List;
    public class CovariantArrays {
      public static void main(String[] args) {
          List<? extends Fruit> list=new ArrayList<Fruit>();
          list.add(new Apple()); //wrong
    class Fruit {}
    class Orange extends Fruit {}
    class Apple extends Fruit {}
    class Jonathan extends Apple {}
      We can't even add a Apple instance to list,why,why? '? extends Fruit' represents any subtype of Fruit, doesn't it?
    Edited by: fxbird on 2011-2-3 上午6:37
    Edited by: fxbird on 2011-2-3 上午6:39

    fxbird wrote:
    Thank Walter and other dudes:
    'core java 8th' says '? super xxx' means you can use supertype of a class,'The compiler doesn’t know the exact type of the setFirst method---void setFirst(? super Manager) but can call it with any object of type Manager, Employee, or Object, but not a subtype such as Executive.' ,on page 634. But my test prove it surely can be added subtype . Is the writer wrong?
    List<? super Fruit> sList=new ArrayList<Fruit>();
    sList.add(new Apple());and another question is , what's the difference between in '? extend or super type' and just 'List<Fruit>' way, I don't find the difference, if you use '? extends Fruit' as method parameter, the right type would be Fruit,Apple,Jonathan,Orange, but,so does List<Fruit>
    Edited by: fxbird on 2011-2-5 下午7:19Let's create a very simplified List that is a concrete class:
    public class MyList<E> {
      public void add(E e) {}
      public E get() { return null; }
    }And our Fruit classes:
    class Fruit {}
    class Apple extends Fruit {}
    class Banana extends Fruit {}Here we declare a List where E will be replaced by Fruit:
        MyList<Fruit> list1 = new MyList<Fruit>();This gives us, effectively:
      public void add(Fruit e) {}
      public Fruit get() { return null; }So this is just fine:
        Fruit f1 = new Fruit();
        list1.add(f1);
        f1 = list1.get();The add() works, because Fruit fits the (Fruit e) signature of add(), and get() works because the Fruit it promises to return fits our Fruit f1.
    Now, if we have this:
        MyList<? extends Fruit> list2 = ...; // for example, new MyList<Apple>();This gives us, effectively:
      public void add(? e) {}
      public ? get() { return null; }where all the we, or the compiler, know about ? is that it will be either Fruit or some subtype of Fruit.
    Now, we try this:
    list2.add(new Fruit());
    list2.add(new Banana());
    list2.add(new Apple());But all of those are errors. We don't know if we have List<Fruit>, List<Apple>, or List<Banana>. All the add() method knows is that it expects some particular class that is Fruit or a Subtype. It doesn't know if it's add(Fruit) or add(Apple) or add(Banana). And it can't just assume that it's add(Fruit) and allow any old Fruit in, because if it does happen to be add(Apple) (such as when we do = new MyList<Apple>()), then we could end up putting Bananas into a List of Apples. Or, more precisely, we could end up passing a Banana where an Apple is expected.
    On the other hand, this:
    Fruit f2 = list2.get();is just fine. Even though get() doesn't know if it's public Fruit get() or public Apple get() or public Banana get(), it doesn't matter, because no matter what, whatever it returns IS-A Fruit. So anything expecting a Fruit back is satisfied.
    One final note: While I've used a mini mock-up collection for this example, the rules have nothing to do with collections or add methods or get methods. They have to do with how type safety works in the Java language in any context. In this example, what matters is that we cannot pass any old Fruit as a parameter where some specific class that might be a subclass of Fruit is expected, but we can accept any Fruit as a method return value, even if that method is actually effectively declared to return Apple.
    public void foo(Apple a) {}
    public Apple bar() {return null;}
    Fruit f = ...;
    foo(f); // NOT ok
    f = bar(); // ok

  • Help with generics - extending hashmap

    I'm trying to extend the HashMap class to accept multiple values per key. I'd like .put(key,value) to put a single key/value pair. I'd like .get(key) to return a Vector<V> of all the values associated with key, and .get(key, index) to return a single value of type V for that key. I am using Eclipse 3.2 and Java 1.5.
    The problem I am having is my .put(K key,V value) method won't compile, I get the error:
    Name clash: The method put(K,V) of type OneToManyHashMap<K,V> has the same erasure as put(K,V> of type HashMap<K,V> but does not override it
    My code (roughly):
    public class OneToManyHashMap<K,V> extends HashMap<K, Vector<V>> {
        public V get(Object key, int index) { return get(key).get(index); }
        public V put(K key, V value) { ... }
        public V remove(Object key, int index) { return get(key)
    }Yes, I know there is an extra > in the code. It's wasn't there when I typed the message and it's not there when I try and edit the message to remove it :(
    Message was edited by:
    jiggersplat

    This is what was meant by a "has-a" relation:
    public class OneToManyHashMap&#60;K, V extends List&#60;V>> {
        public Map&#60;K, List&#60;V>> map;
        public OneToManyHashMap() { map = new HashMap&#60;K, List&#60;V>>(); }
        public V get(K key, int index) { return map.get(key).get(index); }
        public void put(K key, V value) { map.get(key).add(value); }
        public void remove(K key, int index) { map.get(key).remove(index); }
    }Needless to say, you will have to perform some checks to handle eventual NPE's.

  • Generics for Higher Order Function Support

    Perhaps I'm not looking hard enough, but it seems that all arguments for generics relate to containers. Has anyone considered the impact of generics and at least rudimentary type inference on higher order function support.
    Consider the case in which you want to execute a particular operation under time constraints, or with specified cleanup operations to occur afterwards, for example:
    interface DBOperation
      void doOperation(Connection con);
    void DoDBOperation(DBOperation op)
      Connection c = acquireConnection()
      try
        op.doOperation(con);
      finally
        c.release();
    }One would then call:
    DoDBOperation(new DBOperation() ...);Now what happens if I want to make a DBOperation that returns an integer and throws a specific checked exception. I would need to define an alternative DBOperation2 class, and rewrite DoDBOperation for each possible permutation of checked exceptions, and for each return type.
    Or one would just have:
    interface DBOperation
      Object doOperation(Connection inCon) throws Exception
    }But now when I call it, I need to catch Exception, not just the ones I specifically throw, and I have to cast the return type.
    Clearly, a generics mechanism with type inference could infer the appropriate throws and return type for the DoDBOperation call, given the compile-time type of the parameter.

    Ahh, i think I'm starting to see. My guess is that to achieve that in the current generic Java proposal, it would need to look something like:
    public interface OperationInterface<T extends Object, X extends Exception>
       <T> doOperation() throws <X>
    public class LoggedOperation<T extends Object, X extends Exception> implements OperationInterface<T, X>
      OperationInterface<T, X> delegatee;
      public LoggedOperation<T extends Object, X extends Exception>(OperationInterface<T, X> d)
        delegatee = d;
      <T> doOperation() throws <X>
        logStart();
        try {
          return delegatee.doOperation();
        finally {
          logEnd();
    Or somesuch.  The important thing to note is that the genericity is on the objects, not on their methods. So it can behave a little like you suggest, provided the class is created properly in the first place.
    Note: I haven't tried the demo version of the generic compiler, so I'm sure every line of that code is wrong.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Duplicate keys for HashMap

    Hi,
    I have a class I created, call it MyClass. It looks like this:
    public String myString;
    public final String toString() {
        return myString;
    public boolean equals(MyClass mc) {
        return (mc != null && myString.equalsIgnoreCase(mc.toString()));
    }When I use objects of type MyClass as the keys to a HashMap when doing a put(), duplicate keys seem to be allowed. And when I query, knowing that I have an entry for a key, I get null. However, when I change my get() and put() to use MyClass.toString() as the key, everything works fine.
    It seems to me that the JVM must be assuming that different instances of objects of type MyClass are different and thus a new key+value is created when "putting" instead of the old value being overwritten. But MyClass has an equals() method, so when putting, why doesn't it tell the JVM that the key already exists?
    Thanks,
    Jeff

    True, I missed that.
    Were you thinking that the HashMap is going to use the equals you provide that takes MyClass as an arg? It won't. It uses the one that takes Object, which means you'll be using Object's equals, which compares references, so no MyClass can ever be equal to another.
    You need to override equals (with the Object argument) and override hashCode.

  • Requirement for object key for HashMap

    Hi,
    I would like to put the object to HashMap keyed by my own object. what is the requirement for the class to be key? I have a method boolean equals(Object o) defined in the key class, My key is composed by 2 ids, so in the equals method I compared the 2 ids. but it seems can't get the value out. Please help. Thanks

    How do I supposed to do the hashCode? If myKey1.equals(myKey2) returns true, then myKey1.hashCode() must return the same value as myKey2.hashCode(). One consequence of this is that if something is not used to compuate equals(), then it must not be used to compute hashCode(). (Note that the reverse is not true. That is, if two objects are not equal, they can still return the same value from hashCode(), and hence, if some data is used for equals() it may still be left out of hashCode().)
    You want hashCode to be 1) quick & easy to compute and 2) "well distributed" or "mostly unique. If you know how hashcodes are used (in the general sense, not just the Java hashCode() method) then you should understand why those properties are desirable. If not, just ask.
    The most common approach is to use some subset of the object's fields in computing the hashCode. If you have a Person object with lastName, firstName, birthdate, height, weight, address, phone number, you probably wouldn't use all those fields. You could just lastName, or maybe a combination of lastName and firstName.
    One generally combines multiple pieces by taking XORing (the "^") operator the individual pieces (for primitives) or their hashcodes (for objects). For example, in the Person example: public int hashCode() {
        return lastName.hashCode() ^ firstName.hashCode(); // but make sure to check for null first
    }

  • How is the performance for HashMap.get()

    hi all
    i just want to ask you guys how quick the hashmap.get() runs for a given key, if there are thousand of entries in the hashmap. thanks

    If you want to know how something is going to perform, write a tiny program and test it. Either put it on a profiler, or just put time markers around a big loop. Here's something that somebody (UJ, I think) came up with recently for comparing casting vs. toString after extracting from a Map. It should be easy to adapt to just the Map.get() timing. In fact, I think I added a chunk to do just that, as a control. Knock yourself out. import java.util.*;
    public class MapTiming {
        Random rnd = new Random(13L);
        public static void main(String[] args) {
            int numEntries = Integer.parseInt(args[0]);
            Integer key = Integer.valueOf(args[1]);
            new MapTiming().zillion2(numEntries, key);
        void zillion2(int numEntries, Integer key) {
            HashMap map = new HashMap();
            int ix;
            for (ix = 0; ix < numEntries; ix++) {
                int entry = rnd.nextInt();
                map.put(new Integer(entry), String.valueOf(ix));
            map.put(key, String.valueOf(ix));
            final int LOOPS = 10000000;
            final int TIMES = 5;
            long time;
            for (int j=0; j<TIMES; j++) {
                time = System.currentTimeMillis();
                for (int i=0;i<LOOPS; i++) {
                    String item = map.get(key).toString();
                System.out.println("toString= " + (System.currentTimeMillis()-time));
            for (int j=0; j<TIMES; j++) {
                time = System.currentTimeMillis();
                for (int i=0;i<LOOPS; i++) {
                    String item = (String)map.get(key);
                System.out.println("cast= " + (System.currentTimeMillis()-time));
            for (int j=0; j<TIMES; j++) {
                time = System.currentTimeMillis();
                for (int i=0;i<LOOPS; i++) {
                    Object obj = map.get(key);
                System.out.println("get= " + (System.currentTimeMillis()-time));
            for (int j=0; j<TIMES; j++) {
                time = System.currentTimeMillis();
                for (int i=0;i<LOOPS; i++) {
                    String item = map.get(key).toString();
                System.out.println("toString= " + (System.currentTimeMillis()-time));
            for (int j=0; j<TIMES; j++) {
                time = System.currentTimeMillis();
                for (int i=0;i<LOOPS; i++) {
                    String item = (String)map.get(key);
                System.out.println("cast= " + (System.currentTimeMillis()-time));
            for (int j=0; j<TIMES; j++) {
                time = System.currentTimeMillis();
                for (int i=0;i<LOOPS; i++) {
                    Object obj = map.get(key);
                System.out.println("get= " + (System.currentTimeMillis()-time));
    }

  • Programming Lgic Idea...? Thoughts for required/optional fields for HashMap

    hi all:
    Let me see if I can convey this thought clearly..
    I am having logic problems... not coding issues...
    My problem...
    I have a class called JobBuilder and another class called RegistrationFile. The idea is that RegistrationFile has a mehod to write a Registration File called writeRegistrationFile(HashMap regFileParams). Note that the registration file is constructed based on values in the RegistrationFile... However the registration file construction and hence required information is different depending upon the file type... Thus I have created another method called getRegFileParameters(String filetype) in class RegistrationFile which can be called before the write method which will construct a HashMap with the required parameters neccessary for the specified type and return it to the calling class (JobBuilder). The information in the returned HashMap will contain the required and optional fields needed to create a the specific registration file... My idea is that registration file class returns this HashMap to the calling class JobBuilder and it will use the information in the HashMap to construct the appropriatte HashMap which can be passed back to the RegistrationFile method writeRegistrationFile(HashMap params) method in order to construct the registration file...
    so for example say the calling class JobBuilder says ok I want to create a registration file that is of type 2d Drawing... so it will make the following call:
    RegistrationFile rf = new RegistrationFile();
    HashMap hm1 = rf.getRegFileParams("2d Drawing");
    the above will execute and a hashmap of optional and required values will be returned to JobBuilder and will look something like this...
    "GT_ATTRIB", "AFM_W,KEY;AFM_X,KEY;AFM_D,X;"
    "NTK", "X,X;"
    "FILE", "X,X,X;"
    etc...
    couple things to note...
    X = optional
    KEY = REQUIRED
    also there may be X number of required records for GT_ATTRIB, or NTK, etc... multi valued input is seperated by commas and varying value/parameter pairs by semicolons...
    Thus for GT_ATTRIB there may be some number of required fields like AFM_X, AFM_D, etc and each pair is seperated by a semicolon...
    thus AFM_X, AFM_D eventually will translate to seperate records
    i.e. in the registration file it might look like
    GT_ATTRIB|AFM_X|11
    GT_ATTRIB|AFM_D|Q.1
    NTK|3|6
    NTK|4|5
    FILE|/var/tmp|file1.txt|<optional comment>
    FILE|/var/tmp|file2.txt
    etc... all of this would have be turned into a HashMap that is constructed and returned to the RegistrationFile.writeRegistrationFile (HashMap hm) that was constructed like the following...
    HashMap hm2 = new HashMap();
    hm2.put("GT_ATTRIB", "AFM_X,11;AFM_D,Q.1;");
    hm2.put("NTK", "3,6;4,5;");
    hm2.put("FILE", "/var/tmp,file1.txt,<optional comment>;/var/tmp,file2.txt;");
    etc...
    rf.writeRegistrationFile(hm2); // send it to registrationFile class and use the write method...
    The logic problem i am having is that the they should be able to construct the previous by reading the HashMap that was returned earlier... specifying required and optional parameters... does anyone see how in the class JObBuilder I might accomplish this... somehow I need to read each "KEY", "VALUE" pair from the returned HashMap and then further break it down to distinguish the required attributes from the optional ones...
    it seems that they will have to get the KEY (i.e. "GT_ATTRIB", "NTK", etc... and tear apart the "VALUE" (multi valued key) and determine what is required vs. optional and then to reconstruct it so that I can read it in RegistrationFile class.... i.e.
    They may tear it apart as
    "GT_ATTRIB", "AFM_X", "11";
    "GT_ATTRIB", "AFM_D", "Q.1";
    "NTK", "3", "6";
    etc...
    but in the end needs to be reconstructed like...
    HashMap hm2 = new HashMap();
    hm2.put("GT_ATTRIB", "AFM_X,11;AFM_D,Q.1;");
    hm2.put("NTK", "3,6;4,5;");
    hm2.put("FILE", "/var/tmp,file1.txt,<optional comment>;/var/tmp,file2.txt;");
    etc...
    rf.writeRegistrationFile(hm2); // send it to registrationFile class and use the write method...
    does any of this make sense?
    I need a way to tell what is required and optional based on the returned hashmap so that I can construct the correct hashmap which will be used in generation of the registration file...
    I really do hope that makes sense and truly appreciate any time and help anyone can provide... pseudocode would be great.. to convey the idea if anyone has the time or desire...
    thanks again..
    echardrd

    Yeah, you want to learn XML for ways to do this.

  • Casting for HashMap

    Hi,
    I have a class called ThreadInfo:
    public class ThreadInfo{
              public ChatWindow threadID;
              public String ip;
              public String username;
              public boolean windowOpen;
              public boolean linkEstablished;
              ThreadInfo(){
                   windowOpen = false;
                   linkEstablished=false;
         }I also have a class:
    public class ServerStatus {
         private HashMap threadList;
         ServerStatus() {
              threadList = new HashMap();
    }now if I want to put a value in the HashMap, I would do:
    public void insertNewThread(String key, ThreadInfo info) {
              threadList.put(key,info);
         }right?
    and about retrieving a value, does this sound correct?
    public ThreadInfo getThread(String key){
              ThreadInfo requiredInfo = (ThreadInfo)threadList.get(key);
              return requiredInfo;
              }My query is really about this casting thing because in the API the get method returns an object, but since I know I am inserting a ThreadInfo class instance in the map, I thought that the casting here would give me the correct result.
    any insight to this is highly appreciated
    thanks,
    Talal

    Be careful doing this.
    HashMap can contain null as a value. null cannot be
    cast. Therefore you might want to test the value
    returned by get(key) for null before trying to cast it
    to your return type.
    matfudI do not believe the above is correct.
    Example:
    import java.util.*;
    public class Test68 {
        public static void main(String[] args) {
            HashMap hm = new HashMap();
            hm.put("aaa", null);
            String s = (String)hm.get("aaa");
            System.out.println(s);
            ArrayList al = (ArrayList)null;  // And just for the fun of it
    }C:\j2sdk1.4.0\Test>javac Test68.java
    C:\j2sdk1.4.0\Test>java Test68
    null
    C:\j2sdk1.4.0\Test>

  • Copy Finder Items - how to generic for multiple user home directories?

    I am creating an Automator workflow to allow my networked users to be able to copy certain files from a central location to their local home directory and overwriting their local copy. How to I make the destination of the Copy Finder Item to be generic home directory (something in the like of "~/Document/MegaSeg User Data/MegaSeg Database" instead of a fixed user home directory)?

    Hi
    It may be easier with an appleScript (which you could incorporate into an Automator action if you wanted).
    --start script
    set the_file to -- path to the file you want to copy goes here
    set docs_folder to path to documents folder from user domain
    tell application "Finder"
    set target_folder to folder "MegaSeg Database" of folder "MegaSeg User Data" of docs_folder
    duplicate the_file to target_folder with replacing
    end tell
    -- end script
    This will replace existing files of the same name in the target folder. Hope it helps.

  • Kodo doesn't create table for HashMap?

    Hi,
    here is the metadata
    <class name="ClassA" identity-type="datastore" >
    <field name="hashMapField">
    <map key-type="ClassB" value-type="ClassC"/>
    </field>
    </class>
    I found that Kodo use a BLOB to represent the HashMap field instead of
    using a new table. So we can't check the actually data in the db?
    Thank very much

    Kodo 2.x can't persist maps where the key type is a first class object.
    This feature will be in 3.0.

Maybe you are looking for