Skip to content

Commit

Permalink
Consistent use of LinkedHashMaps and independent getAttributeNames En…
Browse files Browse the repository at this point in the history
…umeration in Servlet/Portlet mocks

Issue: SPR-10224
  • Loading branch information
jhoeller committed Jan 30, 2013
1 parent 94a8806 commit 6a98b40
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.Enumeration;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -294,7 +295,7 @@ public Object getAttribute(String name) {

public Enumeration<String> getAttributeNames() {
checkActive();
return Collections.enumeration(this.attributes.keySet());
return Collections.enumeration(new LinkedHashSet<String>(this.attributes.keySet()));
}

public String getCharacterEncoding() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,6 +22,7 @@
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;
Expand Down Expand Up @@ -50,6 +51,7 @@ public class MockHttpSession implements HttpSession {

public static final String SESSION_COOKIE_NAME = "JSESSION";


private static int nextId = 1;

private final String id;
Expand Down Expand Up @@ -141,7 +143,7 @@ public Object getValue(String name) {
}

public Enumeration<String> getAttributeNames() {
return Collections.enumeration(this.attributes.keySet());
return Collections.enumeration(new LinkedHashSet<String>(this.attributes.keySet()));
}

public String[] getValueNames() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,6 +21,7 @@
import java.util.Collections;
import java.util.Enumeration;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import javax.el.ELContext;
import javax.servlet.Servlet;
Expand Down Expand Up @@ -249,7 +250,7 @@ else if (getAttribute(name, APPLICATION_SCOPE) != null) {
}

public Enumeration<String> getAttributeNames() {
return Collections.enumeration(this.attributes.keySet());
return Collections.enumeration(new LinkedHashSet<String>(this.attributes.keySet()));
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -29,7 +29,6 @@
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;

import javax.activation.FileTypeMap;
import javax.servlet.RequestDispatcher;
import javax.servlet.Servlet;
Expand Down Expand Up @@ -434,7 +433,7 @@ public Object getAttribute(String name) {
}

public Enumeration<String> getAttributeNames() {
return Collections.enumeration(this.attributes.keySet());
return Collections.enumeration(new LinkedHashSet<String>(this.attributes.keySet()));
}

public void setAttribute(String name, Object value) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -28,7 +28,6 @@
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.Vector;
import javax.activation.FileTypeMap;
import javax.portlet.PortletContext;
import javax.portlet.PortletRequestDispatcher;
Expand Down Expand Up @@ -210,7 +209,7 @@ public Object getAttribute(String name) {
}

public Enumeration<String> getAttributeNames() {
return new Vector<String>(this.attributes.keySet()).elements();
return Collections.enumeration(new LinkedHashSet<String>(this.attributes.keySet()));
}

public void setAttribute(String name, Object value) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,13 +21,12 @@
import java.util.Enumeration;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.Vector;

import javax.portlet.PortalContext;
import javax.portlet.PortletContext;
import javax.portlet.PortletMode;
Expand Down Expand Up @@ -332,7 +331,7 @@ public Object getAttribute(String name) {

public Enumeration<String> getAttributeNames() {
checkActive();
return new Vector<String>(this.attributes.keySet()).elements();
return Collections.enumeration(new LinkedHashSet<String>(this.attributes.keySet()));
}

public void setParameters(Map<String, String[]> parameters) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,10 +18,10 @@

import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Vector;
import javax.portlet.PortletContext;
import javax.portlet.PortletSession;
import javax.servlet.http.HttpSessionBindingEvent;
Expand Down Expand Up @@ -51,9 +51,9 @@ public class MockPortletSession implements PortletSession {

private final PortletContext portletContext;

private final Map<String, Object> portletAttributes = new HashMap<String, Object>();
private final Map<String, Object> portletAttributes = new LinkedHashMap<String, Object>();

private final Map<String, Object> applicationAttributes = new HashMap<String, Object>();
private final Map<String, Object> applicationAttributes = new LinkedHashMap<String, Object>();

private boolean invalid = false;

Expand Down Expand Up @@ -92,15 +92,15 @@ else if (scope == PortletSession.APPLICATION_SCOPE) {
}

public Enumeration<String> getAttributeNames() {
return new Vector<String>(this.portletAttributes.keySet()).elements();
return Collections.enumeration(new LinkedHashSet<String>(this.portletAttributes.keySet()));
}

public Enumeration<String> getAttributeNames(int scope) {
if (scope == PortletSession.PORTLET_SCOPE) {
return new Vector<String>(this.portletAttributes.keySet()).elements();
return Collections.enumeration(new LinkedHashSet<String>(this.portletAttributes.keySet()));
}
else if (scope == PortletSession.APPLICATION_SCOPE) {
return new Vector<String>(this.applicationAttributes.keySet()).elements();
return Collections.enumeration(new LinkedHashSet<String>(this.applicationAttributes.keySet()));
}
return null;
}
Expand Down

0 comments on commit 6a98b40

Please sign in to comment.