Skip to content

Commit

Permalink
Issue #4814 - Exposing AttributeMap.getAttributeNameSet() on Attributes.
Browse files Browse the repository at this point in the history
The underlying AttributesMap already has a .getAttributeNameSet()
method, expose it on the Attributes interface.

Signed-off-by: Joakim Erdfelt <[email protected]>
  • Loading branch information
joakime committed Apr 27, 2020
1 parent 862562c commit d460786
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -365,11 +365,7 @@ public Object getAttribute(String name)
@Override
public Enumeration<String> getAttributeNames()
{
Set<String> names = new HashSet<>();
for (Enumeration<String> e = _attributes.getAttributeNames(); e.hasMoreElements(); )
{
names.add(e.nextElement());
}
Set<String> names = new HashSet<>(_attributes.getAttributeNameSet());
names.add(JAVAX_SERVLET_REQUEST_X_509_CERTIFICATE);
names.add(JAVAX_SERVLET_REQUEST_CIPHER_SUITE);
names.add(JAVAX_SERVLET_REQUEST_KEY_SIZE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.Arrays;
import java.util.Enumeration;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.Future;
import javax.servlet.ServletContext;
Expand Down Expand Up @@ -594,6 +595,12 @@ public Enumeration<String> getAttributeNames()
return _attributes.getAttributeNames();
}

@Override
public Set<String> getAttributeNameSet()
{
return _attributes.getAttributeNameSet();
}

/*
* @see org.eclipse.util.AttributesMap#removeAttribute(java.lang.String)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,12 @@ public Enumeration<String> getAttributeNames()
return AttributesMap.getAttributeNamesCopy(_attributes);
}

@Override
public Set<String> getAttributeNameSet()
{
return _attributes.getAttributeNameSet();
}

/**
* @return Returns the attributes.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

package org.eclipse.jetty.server.handler;

import java.util.Enumeration;
import java.util.HashSet;
import java.util.Set;
import javax.servlet.ServletContextAttributeEvent;
Expand Down Expand Up @@ -77,10 +76,8 @@ public void attributeAdded(ServletContextAttributeEvent event)
public void contextInitialized(ServletContextEvent event)
{
// Update existing attributes
Enumeration<String> e = event.getServletContext().getAttributeNames();
while (e.hasMoreElements())
for (String name : _context.getServletContext().getAttributeNameSet())
{
String name = e.nextElement();
if (_managedAttributes.contains(name))
updateBean(name, null, event.getServletContext().getAttribute(name));
}
Expand All @@ -89,10 +86,8 @@ public void contextInitialized(ServletContextEvent event)
@Override
public void contextDestroyed(ServletContextEvent event)
{
Enumeration<String> e = _context.getServletContext().getAttributeNames();
while (e.hasMoreElements())
for (String name : _context.getServletContext().getAttributeNameSet())
{
String name = e.nextElement();
if (_managedAttributes.contains(name))
updateBean(name, event.getServletContext().getAttribute(name), null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

package org.eclipse.jetty.server.handler.jmx;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

Expand All @@ -42,10 +41,8 @@ public Map<String, Object> getContextAttributes()
{
Map<String, Object> map = new HashMap<String, Object>();
Attributes attrs = ((ContextHandler)_managed).getAttributes();
Enumeration<String> en = attrs.getAttributeNames();
while (en.hasMoreElements())
for (String name : attrs.getAttributeNameSet())
{
String name = en.nextElement();
Object value = attrs.getAttribute(name);
map.put(name, value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.eclipse.jetty.util;

import java.util.Enumeration;
import java.util.Set;

/**
* Attributes.
Expand All @@ -32,6 +33,8 @@ public interface Attributes

Object getAttribute(String name);

Set<String> getAttributeNameSet();

Enumeration<String> getAttributeNames();

void clearAttributes();
Expand Down Expand Up @@ -83,6 +86,12 @@ public Enumeration<String> getAttributeNames()
return _attributes.getAttributeNames();
}

@Override
public Set<String> getAttributeNameSet()
{
return _attributes.getAttributeNameSet();
}

@Override
public void clearAttributes()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public Enumeration<String> getAttributeNames()
return Collections.enumeration(getAttributeNameSet());
}

@Override
public Set<String> getAttributeNameSet()
{
return keySet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import org.eclipse.jetty.util.Attributes;

Expand Down Expand Up @@ -60,6 +61,12 @@ public synchronized Enumeration<String> getAttributeNames()
return Collections.enumeration(_map.keySet());
}

@Override
public Set<String> getAttributeNameSet()
{
return _map.keySet();
}

@Override
public synchronized void clearAttributes()
{
Expand Down

0 comments on commit d460786

Please sign in to comment.