/*
 * 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.jena.atlas.json;

import java.util.* ;
import java.util.Map.Entry ;

public class JsonObject extends JsonValue
{
    private final Map<String, JsonValue> map = new LinkedHashMap<>() ;
    
    @Override
    public boolean isObject()       { return true ; }
    @Override
    public JsonObject getAsObject() { return this ; }
    
    @Override
    public void visit(JsonVisitor visitor)
    { visitor.visit(this) ; }

    @Override
    public int hashCode()
    {
        return map.hashCode() ;
    }
    
    @Override
    public boolean equals(Object other)
    {
        if ( ! ( other instanceof JsonObject) ) return false ;
        return map.equals(((JsonObject)other).map) ;
    }
    
    public void clear()
    { map.clear() ; }
    
    public boolean hasKey(Object key)
    {
        return map.containsKey(key) ;
    }
    
//    @Override
//    public boolean containsValue(Object value)
//    {
//        return map.containsValue(value) ;
//    }
    
    public Set<String> keys()
    {
        return map.keySet() ;
    }

    
    public Set<Entry<String, JsonValue>> entrySet()
    {
        return map.entrySet() ;
    }
    
    public JsonValue get(String key)
    {
        return map.get(key) ;
    }

    public boolean isEmpty()
    {
        return map.isEmpty() ;
    }

    public Set<String> keySet()
    {
        return map.keySet() ;
    }

    public JsonValue put(String key, JsonValue value)
    {
        return map.put(key, value) ;
    }
    

    public JsonValue put(String key, String value)
    {
        return map.put(key, new JsonString(value)) ;
    }

    public JsonValue put(String key, long value)
    {
        return map.put(key, JsonNumber.value(value)) ;
    }

    public JsonValue put(String key, boolean b)
    {
        return map.put(key, new JsonBoolean(b)) ;
    }

    public void putAll(Map< ? extends String, ? extends JsonValue> m)
    {
        map.putAll(m) ;
    }
    
    public JsonValue remove(Object key)
    {
        return map.remove(key) ;
    }

    public int size()
    {
        return map.size() ;
    }

    public Collection<JsonValue> values()
    {
        return map.values() ;
    }
}

@@ -886,16 +886,55 @@
 .Entry ;
+%0Aimport java.util.function.BiConsumer ;
 %0A%0Apublic
@@ -1315,20 +1315,16 @@
 shCode()
-%0A   
  %7B%0A     
@@ -1352,28 +1352,24 @@
 e() ;%0A    %7D%0A
-    
 %0A    @Overri
@@ -1410,20 +1410,16 @@
 t other)
-%0A   
  %7B%0A     
@@ -1427,19 +1427,17 @@
   if ( !
- ( 
+(
 other in
@@ -1458,16 +1458,28 @@
 bject) )
+%0A           
  return 
@@ -1630,36 +1630,32 @@
 sKey(Object key)
-%0A   
  %7B%0A        retur
@@ -1754,22 +1754,16 @@
 t value)
-%0A//   
  %7B%0A//   
@@ -1843,20 +1843,16 @@
 %3E keys()
-%0A   
  %7B%0A     
@@ -1883,21 +1883,16 @@
 %0A    %7D%0A%0A
-    %0A
     publ
@@ -1930,28 +1930,24 @@
 %3E entrySet()
-%0A   
  %7B%0A        r
@@ -1967,36 +1967,32 @@
 rySet() ;%0A    %7D%0A
-    
 %0A    public Json
@@ -2008,28 +2008,24 @@
 (String key)
-%0A   
  %7B%0A        r
@@ -2080,20 +2080,16 @@
 sEmpty()
-%0A   
  %7B%0A     
@@ -2152,20 +2152,16 @@
 keySet()
-%0A   
  %7B%0A     
@@ -2184,32 +2184,133 @@
 ySet() ;%0A    %7D%0A%0A
+    public void forEach(BiConsumer%3CString, JsonValue%3E action) %7B%0A        map.forEach(action) ;%0A    %7D%0A%0A
     public JsonV
@@ -2342,28 +2342,24 @@
 Value value)
-%0A   
  %7B%0A        r
@@ -2391,21 +2391,16 @@
  ;%0A    %7D
-%0A    
 %0A%0A    pu
@@ -2435,36 +2435,32 @@
 y, String value)
-%0A   
  %7B%0A        retur
@@ -2554,20 +2554,16 @@
 g value)
-%0A   
  %7B%0A     
@@ -2666,20 +2666,16 @@
 olean b)
-%0A   
  %7B%0A     
@@ -2753,17 +2753,16 @@
 All(Map%3C
- 
 ? extend
@@ -2794,20 +2794,16 @@
 alue%3E m)
-%0A   
  %7B%0A     
@@ -2819,36 +2819,32 @@
 tAll(m) ;%0A    %7D%0A
-    
 %0A    public Json
@@ -2867,20 +2867,16 @@
 ect key)
-%0A   
  %7B%0A     
@@ -2931,20 +2931,16 @@
 t size()
-%0A   
  %7B%0A     
@@ -3010,20 +3010,16 @@
 values()
-%0A   
  %7B%0A     

Add "forEach"