代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
Java
】
Java实现同时具有堆和哈希功能的类
作者:
/ 发布于
2011/1/3
/
605
import java.util.*; /** * @author Macosxnerd101 * @version 1.0 * @date 11/02/2010 * * This class is a combination of a Stack * and a HashTable, allowing for LIFO ordering * of elements. Like a Stack, elements are not required * to be unique. Unlike a HashTable, this applies to both the * Key and Value elements. The benefit of using a StackMap * is that it allows for associating a Value with the pushed * Key, which is helpful in instances where place-holding is * a must. * * @param K: Key * @param V: Value * */ public class StackMap<K,V>{ //I use an ArrayList rather than the java.util.Stack //because the Stack class extends java.util.Vector, //which is synchronized. As ArrayList is not synchronized //it will be more efficient as serving as the Stack private ArrayList<EntryClass<K,V>> stack; public StackMap(){ stack = new ArrayList<EntryClass<K,V>>(); } //The EntryClass class which couples the Key-Value pairs //It implements the Map.Entry<K,V> interface, which basically //defines getter/setter methods for the Key and Value. //No additional functionality is provided beyond the getter/setter //methods except for an equals() method. public class EntryClass<K,V> implements Map.Entry<K,V>{ private K key; private V value; public EntryClass(K key, V value){ this.key = key; this.value = value; } public K getKey() {return key;} public V getValue() {return value;} public V setValue(V value) { this.value = value; return this.value; } public boolean equals(EntryClass<K,V> c){ return key.equals(c.key) && value.equals(c.value); } } //The number of entries in the Stack public int size() {return stack.size();} //Whether or not there are any entries in the Stack public boolean isEmpty() {return stack.size() == 0;} //Removes all elements from the Stack public void clear() {stack.clear();} /** * @param key: The key or identifying element in the Map * @param value: The associated information with the key * This function pushes onto the Stack a new instance of the EntryClass * relating the Key and Value parameters. This new element is the top * element on the Stack, and will be returned by peek() and pop() calls. * */ public void push(K key, V value){stack.add(new EntryClass(key,value));} /** * @return EntryClass<K,V>: The top instance of EntryClass on the Stack * This method does not remove the top element from the Stack * */ public EntryClass<K,V> peek(){return stack.get(stack.size()-1);} /** * @return EntryClass<K,V>: The top instance of EntryClass on the Stack * This method removes the top element from the Stack * */ public EntryClass<K,V> pop(){return stack.remove(stack.size()-1);} /** * @param key: The key to search for in the Stack. * @return: true if the key is found, false otherwise * */ public boolean containsKey(K key){ for(EntryClass x:stack) if(x.getKey().equals(key)) return true; return false; } /** * @param key: The key in the relationship * @paraam value: The value associated with the given key * @return: true if the relationship is found in the Stack, false otherwise * */ public boolean containsPairing(K key, V value){ EntryClass<K,V> temp = new EntryClass<K,V>(key,value); for(EntryClass x:stack) if(x.equals(temp)) return true; return false; } /** * @param value: The value to search for in the Stack * @return: true if the value is found in the Stack, false otherwise * */ public boolean containsValue(V value){ for(EntryClass x:stack) if(x.getValue().equals(value)) return true; return false; } }
试试其它关键字
哈希
同语言下
.
List 切割成几份 工具类
.
一行一行读取txt的内容
.
Java PDF转换成图片并输出给前台展示
.
java 多线程框架
.
double类型如果小数点后为零则显示整数否则保留两位小
.
将图片转换为Base64字符串公共类抽取
.
sqlParser 处理SQL(增删改查) 替换schema 用于多租户
.
JAVA 月份中的第几周处理 1-7属于第一周 依次类推 29-
.
java计算两个经纬度之间的距离
.
输入时间参数计算年龄
可能有用的
.
实现测量程序运行时间及cpu使用时间
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
贡献的其它代码
Label
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3