Author: tobr
Date: Tue Feb 12 15:49:45 2013
New Revision: 1445215
URL: http://svn.apache.org/r1445215
Log:
added new ParserData API as container for the parsed data
Added:
incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/core/AbstractParserData.java
(with props)
incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/core/ParserData.java
(with props)
Added:
incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/core/AbstractParserData.java
URL:
http://svn.apache.org/viewvc/incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/core/AbstractParserData.java?rev=1445215&view=auto
==============================================================================
---
incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/core/AbstractParserData.java
(added)
+++
incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/core/AbstractParserData.java
Tue Feb 12 15:49:45 2013
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.droids.core;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Abstract class implementing the {@link ParserData} interface methods.
+ */
+public abstract class AbstractParserData implements ParserData {
+
+ private Map<String, String[]> data = null;
+
+ /**
+ * Constructs a new, empty parser data.
+ */
+ public AbstractParserData() {
+ data = new HashMap<String, String[]>();
+ }
+
+ @Override
+ public String[] names() {
+ return data.keySet().toArray(new String[data.keySet().size()]);
+ }
+
+ @Override
+ public String get(final String name) {
+ String[] values = data.get(name);
+ if (values == null) {
+ return null;
+ } else {
+ return values[0];
+ }
+ }
+
+ @Override
+ public String[] getValues(final String name) {
+ String[] values = data.get(name);
+ if (values == null) {
+ values = new String[0];
+ }
+ return values;
+ }
+
+ private String[] appendedValues(String[] values, final String value) {
+ String[] newValues = new String[values.length + 1];
+ System.arraycopy(values, 0, newValues, 0, values.length);
+ newValues[newValues.length - 1] = value;
+ return newValues;
+ }
+
+ @Override
+ public void add(final String name, final String value) {
+ String[] values = data.get(name);
+ if (values == null) {
+ set(name, value);
+ } else {
+ data.put(name, appendedValues(values, value));
+ }
+ }
+
+ @Override
+ public void set(String name, String value) {
+ if (value != null) {
+ data.put(name, new String[]{value});
+ } else {
+ data.remove(name);
+ }
+ }
+
+ @Override
+ public void set(String name, String[] value) {
+ if (value != null) {
+ data.put(name, value);
+ } else {
+ data.remove(name);
+ }
+ }
+
+ /**
+ * Returns the size of the data map.
+ *
+ * @return number of items
+ */
+ public int size() {
+ return data.size();
+ }
+}
Propchange:
incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/core/AbstractParserData.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/core/AbstractParserData.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange:
incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/core/AbstractParserData.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/core/ParserData.java
URL:
http://svn.apache.org/viewvc/incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/core/ParserData.java?rev=1445215&view=auto
==============================================================================
---
incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/core/ParserData.java
(added)
+++
incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/core/ParserData.java
Tue Feb 12 15:49:45 2013
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.droids.core;
+
+/**
+ *
+ * The data retrieved from the parser.
+ *
+ */
+public interface ParserData {
+
+ /**
+ * Returns an array of the names contained in the parser data.
+ *
+ * @return data names
+ */
+ public String[] names();
+
+ /**
+ * Set parser data name/value. Associate the specified value to the
specified
+ * parser data name. If some previous values were associated to this name,
+ * they are removed. If the given value is <code>null</code>, then the
+ * parser data entry is removed.
+ *
+ * @param name the parser data name.
+ * @param value the parser data value, or <code>null</code>
+ */
+ public void set(final String name, final String value);
+
+ /**
+ * Set multiple values for a name.
+ * If the given value is <code>null</code>, then the parser data entry is
removed.
+ *
+ * @param name the data name
+ * @param value the data value
+ */
+ public void set(final String name, final String[] value);
+
+ /**
+ * Add a parser data name/value mapping. Add the specified value to the
list of
+ * values associated to the specified parser data name.
+ *
+ * @param name the parser data name.
+ * @param value the parser data value.
+ */
+ public void add(final String name, final String value);
+
+ /**
+ * Get the value associated to a parser data name. If many values are
associated
+ * to the specified name, then the first one is returned.
+ *
+ * @param name of the parser data.
+ * @return the value associated to the specified parser data name.
+ */
+ public String get(final String name);
+
+ /**
+ * Get the values associated to a parser data name.
+ *
+ * @param name of the parser data.
+ * @return the values associated to a parser data name.
+ */
+ public String[] getValues(final String name);
+
+}
Propchange:
incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/core/ParserData.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/core/ParserData.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange:
incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/core/ParserData.java
------------------------------------------------------------------------------
svn:mime-type = text/plain