lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shawn Heisey (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (SOLR-4048) Add a "getRecursive" method to NamedList
Date Wed, 07 Nov 2012 15:51:12 GMT

     [ https://issues.apache.org/jira/browse/SOLR-4048?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Shawn Heisey updated SOLR-4048:
-------------------------------

    Description: 
Most of the time when accessing data from a NamedList, what you'll be doing is using get()
to retrieve another NamedList, and doing so over and over until you reach the final level,
where you'll actually retrieve the value you want.

I propose adding a method to NamedList which would do all that heavy lifting for you.  I created
the following method for my own code.  It could be adapted fairly easily for inclusion into
NamedList itself.  The only reason I did not include it as a patch is because I figure you'll
want to ensure it meets all your particular coding guidelines, and that the JavaDoc is much
better than I have done here:

{code}
	/**
	 * Recursively parse a NamedList and return the value at the last level,
	 * assuming that the object found at each level is also a NamedList. For
	 * example, if "response" is the NamedList response from the Solr4 mbean
	 * handler, the following code makes sense:
	 * 
	 * String coreName = (String) getRecursiveFromResponse(response, new
	 * String[] { "solr-mbeans", "CORE", "core", "stats", "coreName" });
	 * 
	 * 
	 * @param namedList the NamedList to parse
	 * @param args A list of values to recursively request
	 * @return the object at the last level.
	 * @throws SolrServerException
	 */
	@SuppressWarnings("unchecked")
	private final Object getRecursiveFromResponse(
			NamedList<Object> namedList, String[] args)
			throws SolrServerException
	{

		NamedList<Object> list = null;
		Object value = null;
		try
		{
			for (String key : args)
			{
				if (list == null)
				{
					list = namedList;
				}
				else
				{
					list = (NamedList<Object>) value;
				}
				value = list.get(key);
			}
			return value;
		}
		catch (Exception e)
		{
			throw new SolrServerException(
					"Failed to recursively parse NamedList", e);
		}
	}
{code}


  was:
Most of the time when accessing data from a NamedList, what you'll be doing is using get()
to retrieve another NamedList, and doing so over and over until you reach the final level,
where you'll actually retrieve the value you want.

I propose adding a method to NamedList which would do all that heavy lifting for you.  I created
the following method for my own code.  It could be adapted fairly easily for inclusion into
NamedList itself.  The only reason I did not include it as a patch is because I figure you'll
want to ensure it meets all your particular coding guidelines, and that the JavaDoc is much
better than I have done here:

{code}
	/**
	 * Recursively parse a NamedList and return the value at the last level,
	 * assuming that the object found at each level is also a NamedList. For
	 * example, if "response" is the NamedList response from the Solr4 mbean
	 * handler, the following code makes sense:
	 * 
	 * String coreName = (String) getRecursiveFromResponse(response, new
	 * String[] { "solr-mbeans", "CORE", "core", "stats", "coreName" });
	 * 
	 * 
	 * @param namedList the NamedList to parse
	 * @param args A list of values to recursively request
	 * @return the object at the last level.
	 * @throws SolrServerException
	 */
	@SuppressWarnings("unchecked")
	private final Object getRecursiveFromResponse(
			NamedList<Object> namedList, String[] args)
			throws CommonSolrException
	{

		NamedList<Object> list = null;
		Object value = null;
		try
		{
			for (String key : args)
			{
				if (list == null)
				{
					list = namedList;
				}
				else
				{
					list = (NamedList<Object>) value;
				}
				value = list.get(key);
			}
			return value;
		}
		catch (Exception e)
		{
			throw new SolrServerException(
					"Failed to recursively parse NamedList", e);
		}
	}
{code}


    
> Add a "getRecursive" method to NamedList
> ----------------------------------------
>
>                 Key: SOLR-4048
>                 URL: https://issues.apache.org/jira/browse/SOLR-4048
>             Project: Solr
>          Issue Type: New Feature
>    Affects Versions: 4.0
>            Reporter: Shawn Heisey
>            Priority: Minor
>             Fix For: 4.1
>
>
> Most of the time when accessing data from a NamedList, what you'll be doing is using
get() to retrieve another NamedList, and doing so over and over until you reach the final
level, where you'll actually retrieve the value you want.
> I propose adding a method to NamedList which would do all that heavy lifting for you.
 I created the following method for my own code.  It could be adapted fairly easily for inclusion
into NamedList itself.  The only reason I did not include it as a patch is because I figure
you'll want to ensure it meets all your particular coding guidelines, and that the JavaDoc
is much better than I have done here:
> {code}
> 	/**
> 	 * Recursively parse a NamedList and return the value at the last level,
> 	 * assuming that the object found at each level is also a NamedList. For
> 	 * example, if "response" is the NamedList response from the Solr4 mbean
> 	 * handler, the following code makes sense:
> 	 * 
> 	 * String coreName = (String) getRecursiveFromResponse(response, new
> 	 * String[] { "solr-mbeans", "CORE", "core", "stats", "coreName" });
> 	 * 
> 	 * 
> 	 * @param namedList the NamedList to parse
> 	 * @param args A list of values to recursively request
> 	 * @return the object at the last level.
> 	 * @throws SolrServerException
> 	 */
> 	@SuppressWarnings("unchecked")
> 	private final Object getRecursiveFromResponse(
> 			NamedList<Object> namedList, String[] args)
> 			throws SolrServerException
> 	{
> 		NamedList<Object> list = null;
> 		Object value = null;
> 		try
> 		{
> 			for (String key : args)
> 			{
> 				if (list == null)
> 				{
> 					list = namedList;
> 				}
> 				else
> 				{
> 					list = (NamedList<Object>) value;
> 				}
> 				value = list.get(key);
> 			}
> 			return value;
> 		}
> 		catch (Exception e)
> 		{
> 			throw new SolrServerException(
> 					"Failed to recursively parse NamedList", e);
> 		}
> 	}
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org


Mime
View raw message