下面列出了java.util.Hashtable#keys ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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;
}
/**
* 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;
}
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;
}
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);
}
}
}
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;
}
private void copy ( Hashtable from , Hashtable to ) {
Enumeration ke = from.keys( );
while ( ke.hasMoreElements( ) ) {
Object key = ke.nextElement( );
to.put( key , from.get( key ) );
}
}
/**
* 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;
}
/**
* 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
}
}
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());
}
/**
* 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;
}
/**
* 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);
}
}
}
/**
* Return an enumeration of table keys for the specified table.
*
* @param table Hashtable<String, Object>
* @return Enumeration<String>
*/
private Enumeration<String> getTableKeys(Hashtable<String, Object> table) {
if (table == null) {
return null;
}
return table.keys();
}
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);
}
}
}
}
/**
* 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;
}
@Override
public Enumeration<String> getKeys() {
final Hashtable<String, Object> h = new Hashtable<>(bundle);
return h.keys();
}
@Override
public Enumeration<String> getKeys() {
final Hashtable<String, Object> h = new Hashtable<>(bundle);
return h.keys();
}
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.");
}
}
}
/**
* 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);
}
@Override
public Enumeration<String> getKeys() {
final Hashtable<String, Object> h = new Hashtable<>(bundle);
return h.keys();
}
/**
* 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();
}