下面列出了java.util.Hashtable#entrySet ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException {
this.map = new PropertyChangeListenerMap();
ObjectInputStream.GetField fields = s.readFields();
@SuppressWarnings("unchecked")
Hashtable<String, PropertyChangeSupport> children = (Hashtable<String, PropertyChangeSupport>) fields.get("children", null);
this.source = fields.get("source", null);
fields.get("propertyChangeSupportSerializedDataVersion", 2);
Object listenerOrNull;
while (null != (listenerOrNull = s.readObject())) {
this.map.add(null, (PropertyChangeListener)listenerOrNull);
}
if (children != null) {
for (Entry<String, PropertyChangeSupport> entry : children.entrySet()) {
for (PropertyChangeListener listener : entry.getValue().getPropertyChangeListeners()) {
this.map.add(entry.getKey(), listener);
}
}
}
}
public static AttributeValues
fromSerializableHashtable(Hashtable<Object, Object> ht)
{
AttributeValues result = new AttributeValues();
if (ht != null && !ht.isEmpty()) {
for (Map.Entry<Object, Object> e: ht.entrySet()) {
Object key = e.getKey();
Object val = e.getValue();
if (key.equals(DEFINED_KEY)) {
result.defineAll(((Integer)val).intValue());
} else {
try {
EAttribute ea =
EAttribute.forAttribute((Attribute)key);
if (ea != null) {
result.set(ea, val);
}
}
catch (ClassCastException ex) {
}
}
}
}
return result;
}
private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException {
this.map = new VetoableChangeListenerMap();
ObjectInputStream.GetField fields = s.readFields();
@SuppressWarnings("unchecked")
Hashtable<String, VetoableChangeSupport> children = (Hashtable<String, VetoableChangeSupport>)fields.get("children", null);
this.source = fields.get("source", null);
fields.get("vetoableChangeSupportSerializedDataVersion", 2);
Object listenerOrNull;
while (null != (listenerOrNull = s.readObject())) {
this.map.add(null, (VetoableChangeListener)listenerOrNull);
}
if (children != null) {
for (Entry<String, VetoableChangeSupport> entry : children.entrySet()) {
for (VetoableChangeListener listener : entry.getValue().getVetoableChangeListeners()) {
this.map.add(entry.getKey(), listener);
}
}
}
}
private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException {
this.map = new VetoableChangeListenerMap();
ObjectInputStream.GetField fields = s.readFields();
@SuppressWarnings("unchecked")
Hashtable<String, VetoableChangeSupport> children = (Hashtable<String, VetoableChangeSupport>)fields.get("children", null);
this.source = fields.get("source", null);
fields.get("vetoableChangeSupportSerializedDataVersion", 2);
Object listenerOrNull;
while (null != (listenerOrNull = s.readObject())) {
this.map.add(null, (VetoableChangeListener)listenerOrNull);
}
if (children != null) {
for (Entry<String, VetoableChangeSupport> entry : children.entrySet()) {
for (VetoableChangeListener listener : entry.getValue().getVetoableChangeListeners()) {
this.map.add(entry.getKey(), listener);
}
}
}
}
@Override
public Set<Occurrence> getOccurrences() {
try{
HashSet<Occurrence> ret=new HashSet<Occurrence>();
for(org.wandora.topicmap.Topic _type : t.getDataTypes()){
W2TTopic type=new W2TTopic(tm,_type);
Hashtable<org.wandora.topicmap.Topic,String> occs=t.getData(_type);
for(Map.Entry<org.wandora.topicmap.Topic,String> e : occs.entrySet()){
org.wandora.topicmap.Topic lang=e.getKey();
ret.add(new W2TOccurrence(this,type,lang!=null?new W2TTopic(tm,lang):null));
}
}
return ret;
}catch(TopicMapException tme){
throw new TMAPIRuntimeException(tme);
}
}
public static AttributeValues
fromSerializableHashtable(Hashtable<Object, Object> ht)
{
AttributeValues result = new AttributeValues();
if (ht != null && !ht.isEmpty()) {
for (Map.Entry<Object, Object> e: ht.entrySet()) {
Object key = e.getKey();
Object val = e.getValue();
if (key.equals(DEFINED_KEY)) {
result.defineAll(((Integer)val).intValue());
} else {
try {
EAttribute ea =
EAttribute.forAttribute((Attribute)key);
if (ea != null) {
result.set(ea, val);
}
}
catch (ClassCastException ex) {
}
}
}
}
return result;
}
private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException {
this.map = new PropertyChangeListenerMap();
ObjectInputStream.GetField fields = s.readFields();
@SuppressWarnings("unchecked")
Hashtable<String, PropertyChangeSupport> children = (Hashtable<String, PropertyChangeSupport>) fields.get("children", null);
this.source = fields.get("source", null);
fields.get("propertyChangeSupportSerializedDataVersion", 2);
Object listenerOrNull;
while (null != (listenerOrNull = s.readObject())) {
this.map.add(null, (PropertyChangeListener)listenerOrNull);
}
if (children != null) {
for (Entry<String, PropertyChangeSupport> entry : children.entrySet()) {
for (PropertyChangeListener listener : entry.getValue().getPropertyChangeListeners()) {
this.map.add(entry.getKey(), listener);
}
}
}
}
public static List sortByValueThenKeyLength(Hashtable hash) {
ArrayList alist = new ArrayList(hash.entrySet());
Collections.sort(alist, new Comparator() {
public int compare(Object o1, Object o2) {
Comparable c1 = (Comparable) ((Map.Entry) o1).getValue();
Comparable c2 = (Comparable) ((Map.Entry) o2).getValue();
int result = c2.compareTo(c1);
if (result == 0) {
String s1 = (String) ((Map.Entry) o1).getKey();
String s2 = (String) ((Map.Entry) o2).getKey();
return new Integer(s2.length()).compareTo(new Integer(s1.length()));
} else {
return result;
}
}
});
return alist;
}
/**
*
*/
@Override
public void run()
{
while (true)
{
Hashtable<String, CurrentSession> listOPSess = getListOPSess();
for (Map.Entry<String, CurrentSession> entry : listOPSess.entrySet())
{
if (HasExpired(entry.getValue()))
DelSession(entry.getKey());
}
try {
Thread.sleep(getTIMEOUT());
} catch (InterruptedException e)
{
}
}
}
private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException {
this.map = new PropertyChangeListenerMap();
ObjectInputStream.GetField fields = s.readFields();
@SuppressWarnings("unchecked")
Hashtable<String, PropertyChangeSupport> children = (Hashtable<String, PropertyChangeSupport>) fields.get("children", null);
this.source = fields.get("source", null);
fields.get("propertyChangeSupportSerializedDataVersion", 2);
Object listenerOrNull;
while (null != (listenerOrNull = s.readObject())) {
this.map.add(null, (PropertyChangeListener)listenerOrNull);
}
if (children != null) {
for (Entry<String, PropertyChangeSupport> entry : children.entrySet()) {
for (PropertyChangeListener listener : entry.getValue().getPropertyChangeListeners()) {
this.map.add(entry.getKey(), listener);
}
}
}
}
private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException {
this.map = new VetoableChangeListenerMap();
ObjectInputStream.GetField fields = s.readFields();
@SuppressWarnings("unchecked")
Hashtable<String, VetoableChangeSupport> children = (Hashtable<String, VetoableChangeSupport>)fields.get("children", null);
this.source = fields.get("source", null);
fields.get("vetoableChangeSupportSerializedDataVersion", 2);
Object listenerOrNull;
while (null != (listenerOrNull = s.readObject())) {
this.map.add(null, (VetoableChangeListener)listenerOrNull);
}
if (children != null) {
for (Entry<String, VetoableChangeSupport> entry : children.entrySet()) {
for (VetoableChangeListener listener : entry.getValue().getVetoableChangeListeners()) {
this.map.add(entry.getKey(), listener);
}
}
}
}
private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException {
this.map = new PropertyChangeListenerMap();
ObjectInputStream.GetField fields = s.readFields();
@SuppressWarnings("unchecked")
Hashtable<String, PropertyChangeSupport> children = (Hashtable<String, PropertyChangeSupport>) fields.get("children", null);
this.source = fields.get("source", null);
fields.get("propertyChangeSupportSerializedDataVersion", 2);
Object listenerOrNull;
while (null != (listenerOrNull = s.readObject())) {
this.map.add(null, (PropertyChangeListener)listenerOrNull);
}
if (children != null) {
for (Entry<String, PropertyChangeSupport> entry : children.entrySet()) {
for (PropertyChangeListener listener : entry.getValue().getPropertyChangeListeners()) {
this.map.add(entry.getKey(), listener);
}
}
}
}
/**
* Create filter from the bundle context adding class name and properties
*
* @param bundleContext BundleContext
* @param clazz The type of the OSGi service
* @param props attribute list that filter the service list
* @return Filter
* @throws InvalidSyntaxException
*/
protected Filter createFilter(BundleContext bundleContext, Class clazz, Hashtable<String, String> props)
throws InvalidSyntaxException {
StringBuilder buf = new StringBuilder();
buf.append("(objectClass=" + clazz.getName() + ")");
if (props != null && !props.isEmpty()) {
buf.insert(0, "(&");
for (Map.Entry<String, String> entry : props.entrySet()) {
buf.append("(" + entry.getKey() + "=" + entry.getValue() + ")");
}
buf.append(")");
}
return bundleContext.createFilter(buf.toString());
}
public static void main(final String[] args) throws Exception {
Hashtable<String, String> h1 = new Hashtable<>();
System.err.println("*** BEGIN TEST ***");
h1.put("key", "value");
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (ObjectOutputStream oos = new ObjectOutputStream(baos)) {
oos.writeObject(h1);
}
final byte[] data = baos.toByteArray();
final ByteArrayInputStream bais = new ByteArrayInputStream(data);
final Object deserializedObject;
try (ObjectInputStream ois = new ObjectInputStream(bais)) {
deserializedObject = ois.readObject();
}
if(!h1.getClass().isInstance(deserializedObject)) {
throw new RuntimeException("Result not assignable to type of h1");
}
if (false == h1.equals(deserializedObject)) {
Hashtable<String, String> d1 = (Hashtable<String, String>) h1;
for(Map.Entry entry: h1.entrySet()) {
System.err.println("h1.key::" + entry.getKey() + " d1.containsKey()::" + d1.containsKey((String) entry.getKey()));
System.err.println("h1.value::" + entry.getValue() + " d1.contains()::" + d1.contains(entry.getValue()));
System.err.println("h1.value == d1.value " + entry.getValue().equals(d1.get((String) entry.getKey())));
}
throw new RuntimeException(getFailureText(h1, deserializedObject));
}
}
private static void linkJobs(BuildingJobDataProvider provider, Hashtable<String, SimpleBuildingJob> converted) {
Set<Entry<String, SimpleBuildingJob>> items = converted.entrySet();
for (Entry<String, SimpleBuildingJob> item : items) {
String name = item.getKey();
SimpleBuildingJob job = item.getValue();
BuildingJobData definition = provider.getJobData(name);
job.failJob = converted.get(definition.getNextFailJob());
job.successJob = converted.get(definition.getNextSucessJob());
if (job.failJob == null || job.successJob == null) {
throw new IllegalArgumentException("Next jobs were not found.");
}
}
}
public static void main(final String[] args) throws Exception {
Hashtable<String, String> h1 = new Hashtable<>();
System.err.println("*** BEGIN TEST ***");
h1.put("key", "value");
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (ObjectOutputStream oos = new ObjectOutputStream(baos)) {
oos.writeObject(h1);
}
final byte[] data = baos.toByteArray();
final ByteArrayInputStream bais = new ByteArrayInputStream(data);
final Object deserializedObject;
try (ObjectInputStream ois = new ObjectInputStream(bais)) {
deserializedObject = ois.readObject();
}
if(!h1.getClass().isInstance(deserializedObject)) {
throw new RuntimeException("Result not assignable to type of h1");
}
if (false == h1.equals(deserializedObject)) {
Hashtable<String, String> d1 = (Hashtable<String, String>) h1;
for(Map.Entry entry: h1.entrySet()) {
System.err.println("h1.key::" + entry.getKey() + " d1.containsKey()::" + d1.containsKey((String) entry.getKey()));
System.err.println("h1.value::" + entry.getValue() + " d1.contains()::" + d1.contains(entry.getValue()));
System.err.println("h1.value == d1.value " + entry.getValue().equals(d1.get((String) entry.getKey())));
}
throw new RuntimeException(getFailureText(h1, deserializedObject));
}
}
@java.io.Serial
private void readObject(ObjectInputStream in) throws IOException,
ClassNotFoundException {
// Don't call defaultReadObject()
// Read in serialized fields
ObjectInputStream.GetField gfields = in.readFields();
// Get allPermission
allPermission = (PermissionCollection) gfields.get("allPermission", null);
// Get permissions
// writeObject writes a Hashtable<Class<?>, PermissionCollection> for
// the perms key, so this cast is safe, unless the data is corrupt.
@SuppressWarnings("unchecked")
Hashtable<Class<?>, PermissionCollection> perms =
(Hashtable<Class<?>, PermissionCollection>)gfields.get("perms", null);
permsMap = new ConcurrentHashMap<>(perms.size()*2);
permsMap.putAll(perms);
// Check that Class is mapped to PermissionCollection containing
// Permissions of the same class
for (Map.Entry<Class<?>, PermissionCollection> e : perms.entrySet()) {
Class<?> k = e.getKey();
PermissionCollection v = e.getValue();
Enumeration<Permission> en = v.elements();
while (en.hasMoreElements()) {
Permission p = en.nextElement();
if (!k.equals(p.getClass())) {
throw new InvalidObjectException("Permission with class " +
k + " incorrectly mapped to PermissionCollection " +
"containing Permission with " + p.getClass());
}
}
}
// Set hasUnresolved
UnresolvedPermissionCollection uc =
(UnresolvedPermissionCollection) permsMap.get(UnresolvedPermission.class);
hasUnresolved = (uc != null && uc.elements().hasMoreElements());
}
@SuppressWarnings("unchecked")
private void readObject(ObjectInputStream in)
throws IOException, ClassNotFoundException {
// We have to read serialized fields first.
ObjectInputStream.GetField gf = in.readFields();
docType = (DocumentTypeImpl)gf.get("docType", null);
docElement = (ElementImpl)gf.get("docElement", null);
fFreeNLCache = (NodeListCache)gf.get("fFreeNLCache", null);
encoding = (String)gf.get("encoding", null);
actualEncoding = (String)gf.get("actualEncoding", null);
version = (String)gf.get("version", null);
standalone = gf.get("standalone", false);
fDocumentURI = (String)gf.get("fDocumentURI", null);
//userData is the original name. It has been changed to nodeUserData, refer to the corrsponding @serialField
Hashtable<Node, Hashtable<String, UserDataRecord>> nud =
(Hashtable<Node, Hashtable<String, UserDataRecord>>)gf.get("userData", null);
Hashtable<String, Node> ids = (Hashtable<String, Node>)gf.get("identifiers", null);
changes = gf.get("changes", 0);
allowGrammarAccess = gf.get("allowGrammarAccess", false);
errorChecking = gf.get("errorChecking", true);
ancestorChecking = gf.get("ancestorChecking", true);
xmlVersionChanged = gf.get("xmlVersionChanged", false);
documentNumber = gf.get("documentNumber", 0);
nodeCounter = gf.get("nodeCounter", 0);
Hashtable<Node, Integer> nt = (Hashtable<Node, Integer>)gf.get("nodeTable", null);
xml11Version = gf.get("xml11Version", false);
//convert Hashtables back to HashMaps
if (nud != null) {
nodeUserData = new HashMap<>();
for (Map.Entry<Node, Hashtable<String, UserDataRecord>> e : nud.entrySet()) {
nodeUserData.put(e.getKey(), new HashMap<>(e.getValue()));
}
}
if (ids != null) identifiers = new HashMap<>(ids);
if (nt != null) nodeTable = new HashMap<>(nt);
}
public JenrlInfo(Solver solver, JenrlConstraint jc) {
super();
Assignment<Lecture, Placement> assignment = solver.currentSolution().getAssignment();
TimetableModel model = (TimetableModel)solver.currentSolution().getModel();
Lecture first = (Lecture)jc.first();
Placement firstPl = (Placement)assignment.getValue(first);
Lecture second = (Lecture)jc.second();
Placement secondPl = (Placement)assignment.getValue(second);
if (solver!=null) {
if (firstPl!=null)
iFirst = new ClassAssignmentDetails(solver,first,firstPl,false);
if (secondPl!=null)
iSecond = new ClassAssignmentDetails(solver,second,secondPl,false);
}
if (firstPl==null || secondPl==null) return;
setJenrl(jc.getJenrl());
setIsSatisfied(jc.isInConflict(assignment));
if (jc.isInConflict(assignment)) {
setIsHard(first.areStudentConflictsHard(second));
setIsFixed(first.nrTimeLocations()==1 && second.nrTimeLocations()==1);
setIsDistance(StudentConflict.distance(model.getDistanceMetric(), firstPl, secondPl));
setIsWorkDay(StudentConflict.workday(model.getStudentWorkDayLimit(), firstPl, secondPl));
setIsCommited(jc.areStudentConflictsCommitted());
if (isDistance())
setDistance(Placement.getDistanceInMeters(model.getDistanceMetric(),firstPl,secondPl));
StudentConflict imp = (StudentConflict)model.getCriterion(ImportantStudentConflict.class);
setIsImportant(imp != null && imp.isApplicable(first, second) && imp.inConflict(firstPl, secondPl));
setIsInstructor(jc.getNrInstructors() > 0);
}
Hashtable<String, Double> curriculum2nrStudents = new Hashtable<String, Double>();
for (Student student: jc.first().sameStudents(jc.second())) {
if (student.getCurriculum() == null || student.getCurriculum().isEmpty()) continue;
for (String c: student.getCurriculum().split("\\|")) {
Double nrStudents = curriculum2nrStudents.get(c);
curriculum2nrStudents.put(student.getCurriculum(), jc.getJenrlWeight(student) + (nrStudents == null ? 0.0 : nrStudents));
}
}
if (!curriculum2nrStudents.isEmpty()) {
iCurriculum2nrStudents = new TreeSet<CurriculumInfo>();
for (Map.Entry<String, Double> entry: curriculum2nrStudents.entrySet()) {
iCurriculum2nrStudents.add(new CurriculumInfo(entry.getKey(), entry.getValue()));
}
}
}
@SuppressWarnings("unchecked")
private void readObject(ObjectInputStream in)
throws IOException, ClassNotFoundException {
// We have to read serialized fields first.
ObjectInputStream.GetField gf = in.readFields();
docType = (DocumentTypeImpl)gf.get("docType", null);
docElement = (ElementImpl)gf.get("docElement", null);
fFreeNLCache = (NodeListCache)gf.get("fFreeNLCache", null);
encoding = (String)gf.get("encoding", null);
actualEncoding = (String)gf.get("actualEncoding", null);
version = (String)gf.get("version", null);
standalone = gf.get("standalone", false);
fDocumentURI = (String)gf.get("fDocumentURI", null);
//userData is the original name. It has been changed to nodeUserData, refer to the corrsponding @serialField
Hashtable<Node, Hashtable<String, UserDataRecord>> nud =
(Hashtable<Node, Hashtable<String, UserDataRecord>>)gf.get("userData", null);
Hashtable<String, Node> ids = (Hashtable<String, Node>)gf.get("identifiers", null);
changes = gf.get("changes", 0);
allowGrammarAccess = gf.get("allowGrammarAccess", false);
errorChecking = gf.get("errorChecking", true);
ancestorChecking = gf.get("ancestorChecking", true);
xmlVersionChanged = gf.get("xmlVersionChanged", false);
documentNumber = gf.get("documentNumber", 0);
nodeCounter = gf.get("nodeCounter", 0);
Hashtable<Node, Integer> nt = (Hashtable<Node, Integer>)gf.get("nodeTable", null);
xml11Version = gf.get("xml11Version", false);
//convert Hashtables back to HashMaps
if (nud != null) {
nodeUserData = new HashMap<>();
for (Map.Entry<Node, Hashtable<String, UserDataRecord>> e : nud.entrySet()) {
nodeUserData.put(e.getKey(), new HashMap<>(e.getValue()));
}
}
if (ids != null) identifiers = new HashMap<>(ids);
if (nt != null) nodeTable = new HashMap<>(nt);
}