Java Code Examples for java.util.Hashtable#keys()

The following examples show how to use java.util.Hashtable#keys() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ArrayTable.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public Object clone() {
    ArrayTable newArrayTable = new ArrayTable();
    if (isArray()) {
        Object[] array = (Object[])table;
        for (int i = 0 ;i < array.length-1 ; i+=2) {
            newArrayTable.put(array[i], array[i+1]);
        }
    } else {
        Hashtable<?,?> tmp = (Hashtable)table;
        Enumeration<?> keys = tmp.keys();
        while (keys.hasMoreElements()) {
            Object o = keys.nextElement();
            newArrayTable.put(o,tmp.get(o));
        }
    }
    return newArrayTable;
}
 
Example 2
Source File: ColumnTypeDialog.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
private String[] getUserLangs() {
	Hashtable<String, String> langTable = new Hashtable<String, String>();
	for (int c = 0; c < size; c++) {
		String propLevel1 = arrCmbPropsLevel[c].getText();
		if (propLevel1.equals(ColProperties.langLevel)) {
			langTable.put(LocaleService.getLanguageCodeByLanguage(arrCmbLangs[c].getText()),
					LocaleService.getLanguageCodeByLanguage(arrCmbLangs[c].getText()));
		}
	}

	String[] result = new String[langTable.size()];
	Enumeration<String> keys = langTable.keys();
	int index = 0;
	while (keys.hasMoreElements()) {
		result[index++] = keys.nextElement();
	}
	return result;
}
 
Example 3
Source File: classlister.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
protected void showAllItemsOneLevel() {
    pwOut.println("Showing all dependencies");
    pwOut.println("One level only");
    pwOut.println("-----------------------------------");

    Enumeration e = masterClassList.keys();
    while (e.hasMoreElements()) {
        String key = (String) e.nextElement();
        pwOut.println(key);
        Hashtable h = (Hashtable) masterClassList.get(key);
        Enumeration e2 = h.keys();
        Hashtable h2 = new Hashtable();
        while (e2.hasMoreElements()) {
            String key2 = (String) e2.nextElement();
            pwOut.println("\t" + key2);
        }
    }
}
 
Example 4
Source File: GeneradorTexto.java    From chuidiang-ejemplos with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Se le pasa un Hashtable de letras obtenido con 
 * calculaPosiblesLetrasQueSiguenAUnaPareja() y elige una que devuelve.
 * En el Hashtable cada letra es una clave y tiene un número que es el número de veces
 * que en el texto original esa letra seguía a una pareja concreta.
 * La letra se selecciona al azar, pero de forma que la letra con el número más alto
 * asociado tiene más probabilidades de salir.
 *
 * @param letras Hashtable con claves letras y valores Integer que representan el
 * número de veces que sale dicha letra detrás de una pareja de letras concreta.
 * @param contador Numero total de letras que siguen a una pareja.
 *
 * @return La letra seleccionada.
 */
private char seleccionaLetraEntreLasPosibles(
    Hashtable<Character, Integer> letras, int contador)
{
    int valor = (int) (Math.random() * contador);
    Enumeration<Character> claves = letras.keys();
    int parcial = 0;
    Character letra = null;

    while (claves.hasMoreElements())
    {
        letra = claves.nextElement();
        parcial = parcial + letras.get(letra);

        if (parcial > valor)
        {
            return letra;
        }
    }

    return letra;
}
 
Example 5
Source File: ArrayTable.java    From Java8CN with Apache License 2.0 6 votes vote down vote up
public Object clone() {
    ArrayTable newArrayTable = new ArrayTable();
    if (isArray()) {
        Object[] array = (Object[])table;
        for (int i = 0 ;i < array.length-1 ; i+=2) {
            newArrayTable.put(array[i], array[i+1]);
        }
    } else {
        Hashtable<?,?> tmp = (Hashtable)table;
        Enumeration<?> keys = tmp.keys();
        while (keys.hasMoreElements()) {
            Object o = keys.nextElement();
            newArrayTable.put(o,tmp.get(o));
        }
    }
    return newArrayTable;
}
 
Example 6
Source File: X509Name.java    From RipplePower with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor from a table of attributes with ordering.
 * <p>
 * it's is assumed the table contains OID/String pairs, and the contents
 * of the table are copied into an internal table as part of the
 * construction process. The ordering vector should contain the OIDs
 * in the order they are meant to be encoded or printed in toString.
 * <p>
 * The passed in converter will be used to convert the strings into their
 * ASN.1 counterparts.
 * @deprecated use X500Name, X500NameBuilder
 */
public X509Name(
    Vector                   ordering,
    Hashtable                attributes,
    X509NameEntryConverter   converter)
{
    this.converter = converter;

    if (ordering != null)
    {
        for (int i = 0; i != ordering.size(); i++)
        {
            this.ordering.addElement(ordering.elementAt(i));
            this.added.addElement(FALSE);
        }
    }
    else
    {
        Enumeration     e = attributes.keys();

        while (e.hasMoreElements())
        {
            this.ordering.addElement(e.nextElement());
            this.added.addElement(FALSE);
        }
    }

    for (int i = 0; i != this.ordering.size(); i++)
    {
        ASN1ObjectIdentifier     oid = (ASN1ObjectIdentifier)this.ordering.elementAt(i);

        if (attributes.get(oid) == null)
        {
            throw new IllegalArgumentException("No attribute for object id - " + oid.getId() + " - passed to distinguished name");
        }

        this.values.addElement(attributes.get(oid)); // copy the hash table
    }
}
 
Example 7
Source File: ArgArray.java    From gsn with GNU General Public License v3.0 5 votes vote down vote up
private void copy ( Hashtable from , Hashtable to ) {
   Enumeration ke = from.keys( );
   while ( ke.hasMoreElements( ) ) {
      Object key = ke.nextElement( );
      to.put( key , from.get( key ) );
   }
}
 
Example 8
Source File: GetSetViewOfKeysFromHashtableExample.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) {

        //create Hashtable object
        Hashtable ht = new Hashtable();

        //add key value pairs to Hashtable
        ht.put("1", "One");
        ht.put("2", "Two");
        ht.put("3", "Three");

    /*
      get Set of keys contained in Hashtable using
      Set keySet() method of Hashtable class
    */

        Set st = ht.keySet();

        System.out.println("Set created from Hashtable Keys contains :");
        //iterate through the Set of keys
        Iterator itr = st.iterator();
        while (itr.hasNext()) System.out.println(itr.next());

    /*
       Please note that resultant Set object is backed by the Hashtable.
       Any key that is removed from Set will also be removed from
       original Hashtable object. The same is not the case with the element
       addition.
    */

        //remove 2 from Set
        st.remove("2");

        //print keys of original Hashtable
        System.out.println("Hashtable keys after removal from Set are :");
        Enumeration e = ht.keys();
        while (e.hasMoreElements()) System.out.println(e.nextElement());
    }
 
Example 9
Source File: SwitchData.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a new enumeration from the hashtable.  Each key in the
 * hash table will be an Integer, with the value being a label.  The
 * enumeration returns the keys in sorted order.
 */
SwitchDataEnumeration(Hashtable<Integer,Label> tab) {
    table = new Integer[tab.size()];
    int i = 0;
    for (Enumeration<Integer> e = tab.keys() ; e.hasMoreElements() ; ) {
        table[i++] = e.nextElement();
    }
    Arrays.sort(table);
    current_index = 0;
}
 
Example 10
Source File: CoreDocumentImpl.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Call user data handlers when a node is deleted (finalized)
 * @param n The node this operation applies to.
 * @param c The copy node or null.
 * @param operation The operation - import, clone, or delete.
     * @param handlers Data associated with n.
    */
    void callUserDataHandlers(Node n, Node c, short operation,Hashtable userData) {
    if (userData == null || userData.isEmpty()) {
        return;
    }
    Enumeration keys = userData.keys();
    while (keys.hasMoreElements()) {
        String key = (String) keys.nextElement();
        UserDataRecord r = (UserDataRecord) userData.get(key);
        if (r.fHandler != null) {
            r.fHandler.handle(operation, key, r.fData, n, c);
        }
    }
}
 
Example 11
Source File: ManifestElement.java    From carbon-kernel with Apache License 2.0 5 votes vote down vote up
/**
 * Return an enumeration of table keys for the specified table.
 *
 * @param table Hashtable&lt;String, Object&gt;
 * @return Enumeration&lt;String&gt;
 */
private Enumeration<String> getTableKeys(Hashtable<String, Object> table) {
    if (table == null) {
        return null;
    }
    return table.keys();
}
 
Example 12
Source File: BuildConfig.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
void collectRelevantHashes(Hashtable rv, String field) {
    for (String ctx : context) {
        Hashtable v = (Hashtable)getField(ctx, field);
        if (v != null) {
            for (Enumeration e=v.keys(); e.hasMoreElements(); ) {
                String key = (String)e.nextElement();
                String val =  (String)v.get(key);
                addTo(rv, key, val);
            }
        }
    }
}
 
Example 13
Source File: SwitchData.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a new enumeration from the hashtable.  Each key in the
 * hash table will be an Integer, with the value being a label.  The
 * enumeration returns the keys in sorted order.
 */
SwitchDataEnumeration(Hashtable<Integer,Label> tab) {
    table = new Integer[tab.size()];
    int i = 0;
    for (Enumeration<Integer> e = tab.keys() ; e.hasMoreElements() ; ) {
        table[i++] = e.nextElement();
    }
    Arrays.sort(table);
    current_index = 0;
}
 
Example 14
Source File: MyResource.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Enumeration<String> getKeys() {
    final Hashtable<String, Object> h = new Hashtable<>(bundle);
    return h.keys();
}
 
Example 15
Source File: MyResource.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Enumeration<String> getKeys() {
    final Hashtable<String, Object> h = new Hashtable<>(bundle);
    return h.keys();
}
 
Example 16
Source File: RegisteredFormatsTest.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {
    fmts = new Hashtable();

    fmts.put("javax_imageio_jpeg_stream_1.0", Boolean.FALSE);
    fmts.put("javax_imageio_jpeg_image_1.0",  Boolean.FALSE);
    fmts.put("javax_imageio_png_1.0",         Boolean.FALSE);
    fmts.put("javax_imageio_bmp_1.0",         Boolean.FALSE);
    fmts.put("javax_imageio_wbmp_1.0",        Boolean.FALSE);
    fmts.put("javax_imageio_gif_stream_1.0",  Boolean.FALSE);
    fmts.put("javax_imageio_gif_image_1.0",   Boolean.FALSE);

    IIORegistry registry = IIORegistry.getDefaultInstance();
    Iterator iter = registry.getServiceProviders(ImageReaderSpi.class,
                                                 false);
    while(iter.hasNext()) {
        ImageReaderSpi spi = (ImageReaderSpi)iter.next();
        String fmt_name;
        fmt_name = spi.getNativeStreamMetadataFormatName();
        testStreamMetadataFormat(spi, fmt_name);

        fmt_name = spi.getNativeImageMetadataFormatName();
        testImageMetadataFormat(spi, fmt_name);

        String[] fmt_names;
        fmt_names = spi.getExtraStreamMetadataFormatNames();
        for (int i=0; fmt_names != null && i < fmt_names.length; i++) {
            testStreamMetadataFormat(spi, fmt_names[i]);
        }

        fmt_names = spi.getExtraImageMetadataFormatNames();
        for (int i=0; fmt_names != null && i < fmt_names.length; i++) {
            testImageMetadataFormat(spi, fmt_names[i]);
        }
    }
    Enumeration keys = fmts.keys();
    while (keys.hasMoreElements()) {
        String key = (String)keys.nextElement();
        boolean val = ((Boolean)fmts.get(key)).booleanValue();
        if (!val) {
            throw new RuntimeException("Test failed: format " +
                                       key + "is not registered.");
        }
    }
}
 
Example 17
Source File: MicroBurlapOutput.java    From sofa-hessian with Apache License 2.0 4 votes vote down vote up
/**
 * Writes a generic object.  writeObject understands the following types:
 *
 * <ul>
 * <li>null
 * <li>java.lang.String
 * <li>java.lang.Boolean
 * <li>java.lang.Integer
 * <li>java.lang.Long
 * <li>java.util.Date
 * <li>byte[]
 * <li>java.util.Vector
 * <li>java.util.Hashtable
 * </ul>
 *
 * Unknown objects will call <code>writeCustomObject</code>.
 */
public void writeObject(Object object)
    throws IOException
{
    if (object == null)
        writeNull();
    else if (object instanceof String)
        writeString((String) object);
    else if (object instanceof Boolean)
        writeBoolean(((Boolean) object).booleanValue());
    else if (object instanceof Integer)
        writeInt(((Integer) object).intValue());
    else if (object instanceof Long)
        writeLong(((Long) object).longValue());
    else if (object instanceof Date)
        writeUTCDate(((Date) object).getTime());
    else if (object instanceof byte[]) {
        byte[] data = (byte[]) object;
        writeBytes(data, 0, data.length);
    }
    else if (object instanceof Vector) {
        Vector vector = (Vector) object;

        int size = vector.size();
        writeListBegin(size, null);
        for (int i = 0; i < size; i++)
            writeObject(vector.elementAt(i));

        writeListEnd();
    }
    else if (object instanceof Hashtable) {
        Hashtable hashtable = (Hashtable) object;

        writeMapBegin(null);
        Enumeration e = hashtable.keys();
        while (e.hasMoreElements()) {
            Object key = e.nextElement();
            Object value = hashtable.get(key);

            writeObject(key);
            writeObject(value);
        }
        writeMapEnd();
    }
    else
        writeCustomObject(object);
}
 
Example 18
Source File: MyResource.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Enumeration<String> getKeys() {
    final Hashtable<String, Object> h = new Hashtable<>(bundle);
    return h.keys();
}
 
Example 19
Source File: BaseToolConfiguration.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
/**
 * Construct as a copy of another.
 * 
 * @param other
 *        The other to copy.
 * @param page
 *        The page in which this tool lives.
 * @param exact
 *        If true, we copy ids - else we generate a new one.
 */
protected BaseToolConfiguration(BaseSiteService siteService, ToolConfiguration other, SitePage page, boolean exact)
{
	this.siteService = siteService;
	m_page = page;
	BaseToolConfiguration bOther = (BaseToolConfiguration) other;

	if (exact)
	{
		m_id = other.getId();
	}
	else
	{
		m_id = siteService.idManager().createUuid();
	}
	m_toolId = other.getToolId();
	m_tool = other.getTool();
	m_title = other.getTitle();
	m_layoutHints = other.getLayoutHints();
	m_pageId = bOther.m_pageId;
	m_pageOrder = bOther.m_pageOrder;
	m_custom_title = getTitleCustom(page);

	m_siteId = getContainingPage().getContainingSite().getId();
	m_skin = bOther.m_skin;

	Hashtable h = other.getPlacementConfig();
	// exact copying of ToolConfiguration items vs replacing occurence of
	// site id within item value, depending on "exact" setting -zqian
	if (exact)
	{
		m_config.putAll(other.getPlacementConfig());
	}
	else
	{
		for (Enumeration e = h.keys(); e.hasMoreElements();)
		{
			// replace site id string inside configuration
			String pOtherConfig = (String) e.nextElement();
			String pOtherConfigValue = (String) h.get(pOtherConfig);
			m_config.put(pOtherConfig, pOtherConfigValue.replaceAll(bOther
					.getSiteId(), m_siteId));
		}
	}
	m_configLazy = bOther.m_configLazy;
	setPageCategory();
}
 
Example 20
Source File: EnvironmentCheck.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Print out report of .jars found in a classpath.
 *
 * Takes the information encoded from a checkPathForJars()
 * call and dumps it out to our PrintWriter.
 *
 * @param v Vector of Hashtables of .jar file info
 * @param desc description to print out in header
 *
 * @return false if OK, true if any .jars were reported
 * as having errors
 * @see #checkPathForJars(String, String[])
 */
protected boolean logFoundJars(Vector v, String desc)
{

  if ((null == v) || (v.size() < 1))
    return false;

  boolean errors = false;

  logMsg("#---- BEGIN Listing XML-related jars in: " + desc + " ----");

  for (int i = 0; i < v.size(); i++)
  {
    Hashtable subhash = (Hashtable) v.elementAt(i);

    for (Enumeration keys = subhash.keys();
         keys.hasMoreElements();
         /* no increment portion */
        )
    {
      Object key = keys.nextElement();
      String keyStr = (String) key;
      try
      {
        if (keyStr.startsWith(ERROR))
        {
          errors = true;
        }
        logMsg(keyStr + "=" + subhash.get(keyStr));

      }
      catch (Exception e)
      {
        errors = true;
        logMsg("Reading-" + key + "= threw: " + e.toString());
      }
    }
  }

  logMsg("#----- END Listing XML-related jars in: " + desc + " -----");

  return errors;
}