< prev index next >

src/java.desktop/unix/classes/sun/awt/X11/XAtomList.java

Print this page




  24  */
  25 
  26 package sun.awt.X11;
  27 
  28 import java.util.*;
  29 
  30 /**
  31  * Helper class to ease the work with the lists of atoms.
  32  */
  33 class XAtomList {
  34     Set<XAtom> atoms = new HashSet<XAtom>();
  35 
  36     /**
  37      * Creates empty list.
  38      */
  39     public XAtomList() {
  40     }
  41 
  42     /**
  43      * Creates instance of XAtomList and initializes it with
  44      * the contents pointer by <code>data</code>.
  45      * Uses default display to initialize atoms.
  46      */
  47     public XAtomList(long data, int count) {
  48         init(data, count);
  49     }
  50     private void init(long data, int count) {
  51         for (int i = 0; i < count; i++) {
  52             add(new XAtom(XToolkit.getDisplay(), XAtom.getAtom(data+count*XAtom.getAtomSize())));
  53         }
  54     }
  55 
  56     /**
  57      * Creates instance of XAtomList and initializes it with
  58      * the arrays of atoms. Array can contain null atoms.
  59      */
  60     public XAtomList(XAtom[] atoms) {
  61         init(atoms);
  62     }
  63     private void init(XAtom[] atoms) {
  64         for (int i = 0; i < atoms.length; i++) {


  73         XAtom[] res = new XAtom[size()];
  74         Iterator<XAtom> iter = atoms.iterator();
  75         int i = 0;
  76         while (iter.hasNext()) {
  77             res[i++] = iter.next();
  78         }
  79         return res;
  80     }
  81 
  82     /**
  83      * Returns contents of the list as pointer to native data
  84      * The size of the native data is size of the list multiplied by
  85      * size of the Atom type on the platform. Caller is responsible for
  86      * freeing the data by Unsafe.freeMemory when it is no longer needed.
  87      */
  88     public long getAtomsData() {
  89         return XAtom.toData(getAtoms());
  90     }
  91 
  92     /**
  93      * Returns true if this list contains the atom <code>atom</code>
  94      */
  95     public boolean contains(XAtom atom) {
  96         return atoms.contains(atom);
  97     }
  98 
  99     /**
 100      * Add atom to the list. Does nothing if list already contains this atom.
 101      */
 102     public void add(XAtom atom) {
 103         atoms.add(atom);
 104     }
 105 
 106     /**
 107      * Removes atom from the list. Does nothing if arrays doesn't conaint this atom.
 108      */
 109     public void remove(XAtom atom) {
 110         atoms.remove(atom);
 111     }
 112 
 113 
 114     /**
 115      * Returns size of the list
 116      */
 117     public int size() {
 118         return atoms.size();
 119     }
 120 
 121     /**
 122      * Returns a subset of a list which is intersection of this set and set build by mapping <code>mask</code> in
 123      * <code>mapping</code>.
 124      */
 125     public XAtomList subset(int mask, Map<Integer, XAtom> mapping) {
 126         XAtomList res = new XAtomList();
 127         Iterator<Integer> iter = mapping.keySet().iterator();
 128         while (iter.hasNext()) {
 129             Integer bits = iter.next();
 130             if ( (mask & bits.intValue()) == bits.intValue() ) {
 131                 XAtom atom = mapping.get(bits);
 132                 if (contains(atom)) {
 133                     res.add(atom);
 134                 }
 135             }
 136         }
 137         return res;
 138     }
 139 
 140     /**
 141      * Returns iterator for items.
 142      */
 143     public Iterator<XAtom> iterator() {




  24  */
  25 
  26 package sun.awt.X11;
  27 
  28 import java.util.*;
  29 
  30 /**
  31  * Helper class to ease the work with the lists of atoms.
  32  */
  33 class XAtomList {
  34     Set<XAtom> atoms = new HashSet<XAtom>();
  35 
  36     /**
  37      * Creates empty list.
  38      */
  39     public XAtomList() {
  40     }
  41 
  42     /**
  43      * Creates instance of XAtomList and initializes it with
  44      * the contents pointer by {@code data}.
  45      * Uses default display to initialize atoms.
  46      */
  47     public XAtomList(long data, int count) {
  48         init(data, count);
  49     }
  50     private void init(long data, int count) {
  51         for (int i = 0; i < count; i++) {
  52             add(new XAtom(XToolkit.getDisplay(), XAtom.getAtom(data+count*XAtom.getAtomSize())));
  53         }
  54     }
  55 
  56     /**
  57      * Creates instance of XAtomList and initializes it with
  58      * the arrays of atoms. Array can contain null atoms.
  59      */
  60     public XAtomList(XAtom[] atoms) {
  61         init(atoms);
  62     }
  63     private void init(XAtom[] atoms) {
  64         for (int i = 0; i < atoms.length; i++) {


  73         XAtom[] res = new XAtom[size()];
  74         Iterator<XAtom> iter = atoms.iterator();
  75         int i = 0;
  76         while (iter.hasNext()) {
  77             res[i++] = iter.next();
  78         }
  79         return res;
  80     }
  81 
  82     /**
  83      * Returns contents of the list as pointer to native data
  84      * The size of the native data is size of the list multiplied by
  85      * size of the Atom type on the platform. Caller is responsible for
  86      * freeing the data by Unsafe.freeMemory when it is no longer needed.
  87      */
  88     public long getAtomsData() {
  89         return XAtom.toData(getAtoms());
  90     }
  91 
  92     /**
  93      * Returns true if this list contains the atom {@code atom}
  94      */
  95     public boolean contains(XAtom atom) {
  96         return atoms.contains(atom);
  97     }
  98 
  99     /**
 100      * Add atom to the list. Does nothing if list already contains this atom.
 101      */
 102     public void add(XAtom atom) {
 103         atoms.add(atom);
 104     }
 105 
 106     /**
 107      * Removes atom from the list. Does nothing if arrays doesn't conaint this atom.
 108      */
 109     public void remove(XAtom atom) {
 110         atoms.remove(atom);
 111     }
 112 
 113 
 114     /**
 115      * Returns size of the list
 116      */
 117     public int size() {
 118         return atoms.size();
 119     }
 120 
 121     /**
 122      * Returns a subset of a list which is intersection of this set and set build by mapping {@code mask} in
 123      * {@code mapping}.
 124      */
 125     public XAtomList subset(int mask, Map<Integer, XAtom> mapping) {
 126         XAtomList res = new XAtomList();
 127         Iterator<Integer> iter = mapping.keySet().iterator();
 128         while (iter.hasNext()) {
 129             Integer bits = iter.next();
 130             if ( (mask & bits.intValue()) == bits.intValue() ) {
 131                 XAtom atom = mapping.get(bits);
 132                 if (contains(atom)) {
 133                     res.add(atom);
 134                 }
 135             }
 136         }
 137         return res;
 138     }
 139 
 140     /**
 141      * Returns iterator for items.
 142      */
 143     public Iterator<XAtom> iterator() {


< prev index next >