subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r1658120 - in /subversion/trunk/subversion/bindings/javahl/native: Utility.cpp jniwrapper/jni_class_cache.cpp jniwrapper/jni_list.hpp jniwrapper/jni_string_map.cpp jniwrapper/jni_string_map.hpp org_apache_subversion_javahl_util_SubstLib.cpp
Date Sun, 08 Feb 2015 00:44:06 GMT
Author: brane
Date: Sun Feb  8 00:44:05 2015
New Revision: 1658120

URL: http://svn.apache.org/r1658120
Log:
Following up to r1658112, update the JavaHL new-style map wrapper
to use Java iterators instead of converting the map to an std::map.

[in subversion/bindings/javahl/native]

* jniwrapper/jni_string_map.hpp:
  (Java::BaseImmutableMap): Replaces Java::BaseMap.
  (Java::ImmutableMap): Replaces Java::Map.
  (Java::BaseMap): Replaces Java::BaseMutableMap.
   Derives from Java::BaseImmutableMap instead of Java::Object.
  (Java::Map): Replaces Java::MutableMap.
* jniwrapper/jni_string_map.cpp: Update list implementation.

* jniwrapper/jni_class_cache.cpp
  (Java::ClassCacheImpl): Update implementation of get_map,
   get_set, get_map_entry and get_hash_map.

* jniwrapper/jni_list.hpp
  (Java::BaseMutableList, Java::BaseList): Use the object-less
   constructor from Java::Object.

* Utility.cpp,
  org_apache_subversion_javahl_util_SubstLib.cpp:
   Update to new map types.

Modified:
    subversion/trunk/subversion/bindings/javahl/native/Utility.cpp
    subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_class_cache.cpp
    subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_list.hpp
    subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_string_map.cpp
    subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_string_map.hpp
    subversion/trunk/subversion/bindings/javahl/native/org_apache_subversion_javahl_util_SubstLib.cpp

Modified: subversion/trunk/subversion/bindings/javahl/native/Utility.cpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/Utility.cpp?rev=1658120&r1=1658119&r2=1658120&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/Utility.cpp (original)
+++ subversion/trunk/subversion/bindings/javahl/native/Utility.cpp Sun Feb  8 00:44:05 2015
@@ -52,7 +52,10 @@ public:
       const char* const safe_key =
         apr_pstrmemdup(m_pool, key.c_str(), key.size() + 1);
       if (!value.get())
-        apr_hash_set(m_hash, safe_key, key.size(), m_default);
+        {
+          if (m_default != NULL)
+            apr_hash_set(m_hash, safe_key, key.size(), m_default);
+        }
       else
         {
           Java::ByteArray::Contents val(value);
@@ -70,20 +73,22 @@ private:
   apr_hash_t* const m_hash;
   const svn_string_t* const m_default;
 };
+
+typedef ::Java::ImmutableMap< ::Java::ByteArray, jbyteArray> ImmutableByteArrayMap;
 } // anonymous namespace
 
 apr_hash_t*
 make_keyword_hash(::Java::Env env, jobject jkeywords, apr_pool_t* pool)
 {
   const svn_string_t* const empty = svn_string_create_empty(pool);
-  const ::Java::Map< ::Java::ByteArray, jbyteArray> keywords(env, jkeywords);
+  const ImmutableByteArrayMap keywords(env, jkeywords);
   return keywords.for_each(MapToHashIteration(empty, pool)).get();
 }
 
 apr_hash_t*
 make_property_hash(::Java::Env env, jobject jproperties, apr_pool_t* pool)
 {
-  const ::Java::Map< ::Java::ByteArray, jbyteArray> props(env, jproperties);
+  const ImmutableByteArrayMap props(env, jproperties);
   return props.for_each(MapToHashIteration(NULL, pool)).get();
 }
 

Modified: subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_class_cache.cpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_class_cache.cpp?rev=1658120&r1=1658119&r2=1658120&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_class_cache.cpp (original)
+++ subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_class_cache.cpp Sun
Feb  8 00:44:05 2015
@@ -173,10 +173,10 @@ class ClassCacheImpl
   JNIWRAPPER_DEFINE_CACHED_CLASS(list, BaseImmutableList);
   JNIWRAPPER_DEFINE_CACHED_CLASS(array_list, BaseList);
 
-  JNIWRAPPER_DEFINE_CACHED_CLASS(map, BaseMap);
-  JNIWRAPPER_DEFINE_CACHED_CLASS(set, BaseMap::Set);
-  JNIWRAPPER_DEFINE_CACHED_CLASS(map_entry, BaseMap::Entry);
-  JNIWRAPPER_DEFINE_CACHED_CLASS(hash_map, BaseMutableMap);
+  JNIWRAPPER_DEFINE_CACHED_CLASS(map, BaseImmutableMap);
+  JNIWRAPPER_DEFINE_CACHED_CLASS(set, BaseImmutableMap::Set);
+  JNIWRAPPER_DEFINE_CACHED_CLASS(map_entry, BaseImmutableMap::Entry);
+  JNIWRAPPER_DEFINE_CACHED_CLASS(hash_map, BaseMap);
 
   JNIWRAPPER_DEFINE_CACHED_CLASS(input_stream, InputStream);
   JNIWRAPPER_DEFINE_CACHED_CLASS(output_stream, OutputStream);

Modified: subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_list.hpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_list.hpp?rev=1658120&r1=1658119&r2=1658120&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_list.hpp (original)
+++ subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_list.hpp Sun Feb  8
00:44:05 2015
@@ -65,9 +65,8 @@ protected:
   /**
    * Constructor used by BaseList
    */
-  explicit BaseImmutableList(Env env, const Object::ClassImpl* pimpl,
-                             jobject jlist)
-    : Object(env, pimpl, jlist)
+  explicit BaseImmutableList(Env env, const Object::ClassImpl* pimpl)
+    : Object(env, pimpl)
     {}
 
   /**
@@ -208,7 +207,7 @@ protected:
    * with initial allocation size @a length.
    */
   explicit BaseList(Env env, jint length)
-    : BaseImmutableList(env, ClassCache::get_array_list(env), NULL)
+    : BaseImmutableList(env, ClassCache::get_array_list(env))
     {
       set_this(env.NewObject(get_class(), impl().m_mid_ctor, length));
     }

Modified: subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_string_map.cpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_string_map.cpp?rev=1658120&r1=1658119&r2=1658120&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_string_map.cpp (original)
+++ subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_string_map.cpp Sun Feb
 8 00:44:05 2015
@@ -30,111 +30,81 @@
 
 namespace Java {
 
-// Class Java::BaseMap
+// Class Java::BaseImmutableMap
 
-const char* const BaseMap::m_class_name = "java/util/Map";
+const char* const BaseImmutableMap::m_class_name = "java/util/Map";
 
-BaseMap::ClassImpl::ClassImpl(Env env, jclass cls)
+BaseImmutableMap::ClassImpl::ClassImpl(Env env, jclass cls)
   : Object::ClassImpl(env, cls),
+    m_mid_put(env.GetMethodID(cls, "put",
+                              "(Ljava/lang/Object;Ljava/lang/Object;)"
+                              "Ljava/lang/Object;")),
+    m_mid_clear(env.GetMethodID(cls, "clear", "()V")),
+    m_mid_has_key(env.GetMethodID(cls, "containsKey",
+                                  "(Ljava/lang/Object;)Z")),
+    m_mid_get(env.GetMethodID(cls, "get",
+                              "(Ljava/lang/Object;)Ljava/lang/Object;")),
     m_mid_size(env.GetMethodID(cls, "size", "()I")),
     m_mid_entry_set(env.GetMethodID(cls, "entrySet", "()Ljava/util/Set;"))
 {}
 
-BaseMap::ClassImpl::~ClassImpl() {}
+BaseImmutableMap::ClassImpl::~ClassImpl() {}
 
-const char* const BaseMap::Set::m_class_name = "java/util/Set";
+jobject BaseImmutableMap::operator[](const std::string& index) const
+{
+  const String key(m_env, index);
+  if (!m_env.CallBooleanMethod(m_jthis, impl().m_mid_has_key, key.get()))
+    {
+      std::string msg(_("Map does not contain key: "));
+      msg += index;
+      throw std::out_of_range(msg.c_str());
+    }
+  return m_env.CallObjectMethod(m_jthis, impl().m_mid_get, key.get());
+}
 
-BaseMap::Set::ClassImpl::ClassImpl(Env env, jclass cls)
-  : Object::ClassImpl(env, cls),
-    m_mid_iterator(env.GetMethodID(cls, "iterator",
-                                   "()Ljava/util/Iterator;"))
-{}
+BaseImmutableMap::Iterator BaseImmutableMap::get_iterator() const
+{
+  const jobject jentry_set =
+    m_env.CallObjectMethod(m_jthis, impl().m_mid_entry_set);
+  const jobject jiterator =
+    m_env.CallObjectMethod(jentry_set, Set::impl(m_env).m_mid_iterator);
+  return Iterator(m_env, jiterator);
+}
 
-BaseMap::Set::ClassImpl::~ClassImpl() {}
+// Class Java::BaseImmutableMap::Entry
 
-const char* const BaseMap::Entry::m_class_name = "java/util/Map$Entry";
+const char* const BaseImmutableMap::Entry::m_class_name = "java/util/Map$Entry";
 
-BaseMap::Entry::ClassImpl::ClassImpl(Env env, jclass cls)
+BaseImmutableMap::Entry::ClassImpl::ClassImpl(Env env, jclass cls)
   : Object::ClassImpl(env, cls),
     m_mid_get_key(env.GetMethodID(cls, "getKey", "()Ljava/lang/Object;")),
     m_mid_get_value(env.GetMethodID(cls, "getValue", "()Ljava/lang/Object;"))
 {}
 
-BaseMap::Entry::ClassImpl::~ClassImpl() {}
+BaseImmutableMap::Entry::ClassImpl::~ClassImpl() {}
 
+// Class Java::BaseImmutableMap::Set
 
-jobject BaseMap::operator[](const std::string& index) const
-{
-  somap::const_iterator it = m_contents.find(index);
-  if (it == m_contents.end())
-    {
-      std::string msg(_("Map does not contain key: "));
-      msg += index;
-      throw std::out_of_range(msg.c_str());
-    }
-  return it->second;
-}
+const char* const BaseImmutableMap::Set::m_class_name = "java/util/Set";
 
-BaseMap::somap BaseMap::convert_to_map(Env env, jobject jmap)
-{
-  const ClassImpl* pimpl =
-    dynamic_cast<const ClassImpl*>(ClassCache::get_map(env));
+BaseImmutableMap::Set::ClassImpl::ClassImpl(Env env, jclass cls)
+  : Object::ClassImpl(env, cls),
+    m_mid_iterator(env.GetMethodID(cls, "iterator",
+                                   "()Ljava/util/Iterator;"))
+{}
 
-  if (!env.CallIntMethod(jmap, pimpl->m_mid_size))
-    return somap();
+BaseImmutableMap::Set::ClassImpl::~ClassImpl() {}
 
-  // Get an iterator over the map's entry set
-  const jobject entries = env.CallObjectMethod(jmap, pimpl->m_mid_entry_set);
-  const Entry::ClassImpl& entimpl = Entry::impl(env);
-
-  Iterator iterator(env, env.CallObjectMethod(entries,
-                                              Set::impl(env).m_mid_iterator));
-
-  // Iterate over the map, filling the native map
-  somap contents;
-  while (iterator.has_next())
-    {
-      const jobject entry = iterator.next();
-      const String keystr(
-          env, jstring(env.CallObjectMethod(entry, entimpl.m_mid_get_key)));
-      const jobject value(
-          env.CallObjectMethod(entry, entimpl.m_mid_get_value));
-      const String::Contents key(keystr);
-      contents.insert(somap::value_type(key.c_str(), value));
-    }
-  return contents;
-}
 
-// Class Java::BaseMutableMap
+// Class Java::BaseMap
 
-const char* const BaseMutableMap::m_class_name = "java/util/HashMap";
+const char* const BaseMap::m_class_name = "java/util/HashMap";
 
-BaseMutableMap::ClassImpl::ClassImpl(Env env, jclass cls)
-  : Object::ClassImpl(env, cls),
-    m_mid_ctor(env.GetMethodID(cls, "<init>", "(I)V")),
-    m_mid_put(env.GetMethodID(cls, "put",
-                              "(Ljava/lang/Object;Ljava/lang/Object;)"
-                              "Ljava/lang/Object;")),
-    m_mid_clear(env.GetMethodID(cls, "clear", "()V")),
-    m_mid_has_key(env.GetMethodID(cls, "containsKey",
-                                  "(Ljava/lang/Object;)Z")),
-    m_mid_get(env.GetMethodID(cls, "get",
-                              "(Ljava/lang/Object;)Ljava/lang/Object;")),
-    m_mid_size(env.GetMethodID(cls, "size", "()I"))
+BaseMap::ClassImpl::ClassImpl(Env env, jclass cls)
+  : BaseImmutableMap::ClassImpl(env, cls),
+    m_mid_ctor(env.GetMethodID(cls, "<init>", "(I)V"))
 {}
 
-BaseMutableMap::ClassImpl::~ClassImpl() {}
-
-jobject BaseMutableMap::operator[](const std::string& index) const
-{
-  const String key(m_env, index);
-  if (!m_env.CallBooleanMethod(m_jthis, impl().m_mid_has_key, key.get()))
-    {
-      std::string msg(_("Map does not contain key: "));
-      msg += index;
-      throw std::out_of_range(msg.c_str());
-    }
-  return m_env.CallObjectMethod(m_jthis, impl().m_mid_get, key.get());
-}
+BaseMap::ClassImpl::~ClassImpl() {}
 
 } // namespace Java

Modified: subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_string_map.hpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_string_map.hpp?rev=1658120&r1=1658119&r2=1658120&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_string_map.hpp (original)
+++ subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_string_map.hpp Sun Feb
 8 00:44:05 2015
@@ -24,9 +24,7 @@
 #ifndef SVN_JAVAHL_JNIWRAPPER_STRING_MAP_HPP
 #define SVN_JAVAHL_JNIWRAPPER_STRING_MAP_HPP
 
-#include <map>
 #include <string>
-#include <algorithm>
 
 #include "jni_env.hpp"
 #include "jni_object.hpp"
@@ -37,42 +35,65 @@ namespace Java {
 /**
  * Non-template base for an immutable type-safe Java map with String keys.
  *
- * Converts the map to a @c std::map containing @c jobject references.
- *
  * @since New in 1.9.
  */
-class BaseMap : public Object
+class BaseImmutableMap : public Object
 {
-  typedef std::map<std::string, jobject> somap;
-
 public:
   /**
    * Returns the number of elements in the map.
    */
   jint length() const
     {
-      return jint(m_contents.size());
+      return m_env.CallIntMethod(m_jthis, impl().m_mid_size);
+    }
+
+  /**
+   * Checks if the map is empty.
+   */
+  bool is_empty() const
+    {
+      return (length() == 0);
     }
 
 protected:
   /**
-   * Constructs the map wrapper, converting the contents to an
-   * @c std::map.
+   * Constructs the map wrapper.
    */
-  explicit BaseMap(Env env, jobject jmap)
-    : Object(env, ClassCache::get_map(env), jmap),
-      m_contents(convert_to_map(env, m_jthis))
+  explicit BaseImmutableMap(Env env, jobject jmap)
+    : Object(env, ClassCache::get_map(env), jmap)
     {}
 
   /**
+   * Constructor used by BaseMap.
+   */
+  explicit BaseImmutableMap(Env env, const Object::ClassImpl* pimpl)
+    : Object(env, pimpl)
+    {}
+
+  /**
+   * Clears the contents of the map.
+   */
+  void clear()
+    {
+      m_env.CallVoidMethod(m_jthis, impl().m_mid_clear);
+    }
+
+  /**
+   * Inserts @a obj identified by @a key into the map.
+   */
+  void put(const std::string& key, jobject obj)
+    {
+      m_env.CallObjectMethod(m_jthis, impl().m_mid_put,
+                             String(m_env, key).get(), obj);
+    }
+
+  /**
    * Returns the object reference identified by @a index.
    * @throw std::out_of_range if there is no such element.
    */
   jobject operator[](const std::string& index) const;
 
-  const somap m_contents;
-
-private:
   /**
    * This object's implementation details.
    */
@@ -86,6 +107,10 @@ private:
   public:
     virtual ~ClassImpl();
 
+    const MethodID m_mid_put;
+    const MethodID m_mid_clear;
+    const MethodID m_mid_has_key;
+    const MethodID m_mid_get;
     const MethodID m_mid_size;
     const MethodID m_mid_entry_set;
   };
@@ -97,10 +122,38 @@ private:
 
   friend class ClassCacheImpl;
   static const char* const m_class_name;
-  static somap convert_to_map(Env env, jobject jmap);
 
-  struct Set
+  class Iterator : public BaseIterator
   {
+    friend class BaseImmutableMap;
+    explicit Iterator(Env env, jobject jiterator)
+      : BaseIterator(env, jiterator)
+      {}
+  };
+
+  Iterator get_iterator() const;
+
+  class Entry : public Object
+  {
+  public:
+    explicit Entry(Env env, jobject jentry)
+    : Object(env, ClassCache::get_map_entry(env), jentry)
+    {}
+
+    const std::string key() const
+      {
+        const jstring jkey =
+          jstring(m_env.CallObjectMethod(m_jthis, impl().m_mid_get_key));
+        const String::Contents key(String(m_env, jkey));
+        return std::string(key.c_str());
+      }
+
+    jobject value() const
+      {
+        return m_env.CallObjectMethod(m_jthis, impl().m_mid_get_value);
+      }
+
+  private:
     /**
      * This object's implementation details.
      */
@@ -114,25 +167,20 @@ private:
     public:
       virtual ~ClassImpl();
 
-      const MethodID m_mid_iterator;
+      const MethodID m_mid_get_key;
+      const MethodID m_mid_get_value;
     };
 
+    friend class ClassCacheImpl;
     static const char* const m_class_name;
-    static const ClassImpl& impl(Env env)
+    const ClassImpl& impl() const
       {
-        return *dynamic_cast<const ClassImpl*>(ClassCache::get_set(env));
+        return *dynamic_cast<const ClassImpl*>(m_impl);
       }
   };
 
-  class Iterator : public BaseIterator
-  {
-    friend class BaseMap;
-    explicit Iterator(Env env, jobject jiterator)
-      : BaseIterator(env, jiterator)
-      {}
-  };
-
-  struct Entry
+private:
+  struct Set
   {
     /**
      * This object's implementation details.
@@ -147,14 +195,13 @@ private:
     public:
       virtual ~ClassImpl();
 
-      const MethodID m_mid_get_key;
-      const MethodID m_mid_get_value;
+      const MethodID m_mid_iterator;
     };
 
     static const char* const m_class_name;
     static const ClassImpl& impl(Env env)
       {
-        return *dynamic_cast<const ClassImpl*>(ClassCache::get_map_entry(env));
+        return *dynamic_cast<const ClassImpl*>(ClassCache::get_set(env));
       }
   };
 };
@@ -165,15 +212,15 @@ private:
  * @since New in 1.9.
  */
 template <typename T, typename NativeT=jobject>
-class Map : public BaseMap
+class ImmutableMap : public BaseImmutableMap
 {
 public:
   /**
    * Constructs the map wrapper, converting the contents to an
    * @c std::map.
    */
-  explicit Map(Env env, jobject jmap)
-    : BaseMap(env, jmap)
+  explicit ImmutableMap(Env env, jobject jmap)
+    : BaseImmutableMap(env, jmap)
     {}
 
   /**
@@ -182,7 +229,7 @@ public:
    */
   T operator[](const std::string& index) const
     {
-      return T(m_env, NativeT(BaseMap::operator[](index)));
+      return T(m_env, NativeT(BaseImmutableMap::operator[](index)));
     }
 
   /**
@@ -190,37 +237,22 @@ public:
    * each item.
    * @see std::for_each
    * @note Unlike std::for_each, which invokes the functor with a
-   *     single @c value_type argument, this iterator adapts it to cal
-   *     @a function with separate @c const references to the key and
-   *     value.
+   *       single @c value_type argument, this iterator calls
+   *       @a function with separate @c const references to the key
+   *       and value.
    */
   template<typename F>
   F for_each(F function) const
     {
-      const FunctorAdapter<F> adapter(m_env, function);
-      std::for_each(m_contents.begin(), m_contents.end(), adapter);
+      Iterator iter(get_iterator());
+      while (iter.has_next())
+        {
+          Entry entry(m_env, iter.next());
+          const std::string& key(entry.key());
+          function(key, T(m_env, NativeT(entry.value())));
+        }
       return function;
     }
-
-private:
-  template<typename F>
-  struct FunctorAdapter
-  {
-    explicit FunctorAdapter(const Env& env, F& function)
-      : m_env(env),
-        m_function(function)
-      {}
-
-    void operator()(const std::pair<std::string, jobject>& item) const
-      {
-        const std::string& key(item.first);
-        const T value(m_env, NativeT(item.second));
-        m_function(key, value);
-      }
-
-    const Env& m_env;
-    F& m_function;
-  };
 };
 
 /**
@@ -228,7 +260,7 @@ private:
  *
  * @since New in 1.9.
  */
-class BaseMutableMap : public Object
+class BaseMap : public BaseImmutableMap
 {
 public:
   /**
@@ -236,64 +268,32 @@ public:
    */
   void clear()
     {
-      m_env.CallVoidMethod(m_jthis, impl().m_mid_clear);
-    }
-
-  /**
-   * Returns the number of elements in the map.
-   */
-  jint length() const
-    {
-      return m_env.CallIntMethod(m_jthis, impl().m_mid_size);
-    }
-
-  /**
-   * Checks if the map is empty.
-   */
-  bool is_empty() const
-    {
-      return (length() == 0);
+      BaseImmutableMap::clear();
     }
 
 protected:
   /**
-   * Constructs the map wrapper, deriving the class from @a jmap.
+   * Constructs the map wrapper, treating @a jmap as a @c java.util.Map.
    */
-  explicit BaseMutableMap(Env env, jobject jmap)
-    : Object(env, ClassCache::get_hash_map(env), jmap)
+  explicit BaseMap(Env env, jobject jmap)
+    : BaseImmutableMap(env, jmap)
     {}
 
   /**
    * Constructs and wraps an empty map of type @c java.util.HashMap
    * with initial allocation size @a length.
    */
-  explicit BaseMutableMap(Env env, jint length)
-    : Object(env, ClassCache::get_hash_map(env))
+  explicit BaseMap(Env env, jint length)
+    : BaseImmutableMap(env, ClassCache::get_hash_map(env))
     {
       set_this(env.NewObject(get_class(), impl().m_mid_ctor, length));
     }
 
-
-  /**
-   * Inserts @a obj identified by @a key into the map.
-   */
-  void put(const std::string& key, jobject obj)
-    {
-      m_env.CallObjectMethod(m_jthis, impl().m_mid_put,
-                             String(m_env, key).get(), obj);
-    }
-
-  /**
-   * Returns the object reference identified by @a index.
-   * @throw std::out_of_range if there is no such element.
-   */
-  jobject operator[](const std::string& index) const;
-
 private:
   /**
    * This object's implementation details.
    */
-  class ClassImpl : public Object::ClassImpl
+  class ClassImpl : public BaseImmutableMap::ClassImpl
   {
     friend class ClassCacheImpl;
 
@@ -304,11 +304,6 @@ private:
     virtual ~ClassImpl();
 
     const MethodID m_mid_ctor;
-    const MethodID m_mid_put;
-    const MethodID m_mid_clear;
-    const MethodID m_mid_has_key;
-    const MethodID m_mid_get;
-    const MethodID m_mid_size;
   };
 
   const ClassImpl& impl() const
@@ -326,22 +321,22 @@ private:
  * @since New in 1.9.
  */
 template <typename T, typename NativeT=jobject>
-class MutableMap : public BaseMutableMap
+class Map : public BaseMap
 {
 public:
   /**
    * Constructs the map wrapper, deriving the class from @a jmap.
    */
-  explicit MutableMap(Env env, jobject jmap)
-    : BaseMutableMap(env, jmap)
+  explicit Map(Env env, jobject jmap)
+    : BaseMap(env, jmap)
     {}
 
   /**
    * Constructs and wraps an empty map of type @c java.util.HashMap
    * with initial allocation size @a length.
    */
-  explicit MutableMap(Env env, jint length = 0)
-    : BaseMutableMap(env, length)
+  explicit Map(Env env, jint length = 0)
+    : BaseMap(env, length)
     {}
 
   /**
@@ -349,7 +344,7 @@ public:
    */
   void put(const std::string& key, const T& obj)
     {
-      BaseMutableMap::put(key, obj.get());
+      BaseMap::put(key, obj.get());
     }
 
   /**
@@ -358,7 +353,29 @@ public:
    */
   T operator[](const std::string& index) const
     {
-      return T(m_env, NativeT(BaseMutableMap::operator[](index)));
+      return T(m_env, NativeT(BaseMap::operator[](index)));
+    }
+
+  /**
+   * Iterates over the items in the map, calling @a function for
+   * each item.
+   * @see std::for_each
+   * @note Unlike std::for_each, which invokes the functor with a
+   *       single @c value_type argument, this iterator calls
+   *       @a function with separate @c const references to the key
+   *       and value.
+   */
+  template<typename F>
+  F for_each(F function) const
+    {
+      Iterator iter(get_iterator());
+      while (iter.has_next())
+        {
+          Entry entry(m_env, iter.next());
+          const std::string& key(entry.key());
+          function(key, T(m_env, NativeT(entry.value())));
+        }
+      return function;
     }
 };
 

Modified: subversion/trunk/subversion/bindings/javahl/native/org_apache_subversion_javahl_util_SubstLib.cpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/org_apache_subversion_javahl_util_SubstLib.cpp?rev=1658120&r1=1658119&r2=1658120&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/org_apache_subversion_javahl_util_SubstLib.cpp
(original)
+++ subversion/trunk/subversion/bindings/javahl/native/org_apache_subversion_javahl_util_SubstLib.cpp
Sun Feb  8 00:44:05 2015
@@ -118,6 +118,8 @@ Java_org_apache_subversion_javahl_util_S
     jstring jurl, jstring jrepos_root_url,
     jobject jdate, jstring jauthor)
 {
+  typedef Java::Map<Java::ByteArray, jbyteArray> ByteArrayMap;
+
   SVN_JAVAHL_JNI_TRY(SubstLib, buildKeywords)
     {
       const Java::Env env(jenv);
@@ -130,8 +132,7 @@ Java_org_apache_subversion_javahl_util_S
           env, pool, jkeywords_value, jrevision,
           jurl, jrepos_root_url, jdate, jauthor);
 
-      Java::MutableMap<Java::ByteArray, jbyteArray>
-        keywords(env, jint(apr_hash_count(kw)));
+      ByteArrayMap keywords(env, jint(apr_hash_count(kw)));
       for (apr_hash_index_t* hi = apr_hash_first(pool.getPool(), kw);
            hi; hi = apr_hash_next(hi))
         {



Mime
View raw message