private void traverseInternal(Object root,boolean yieldRoot,IdentityHashMap<Object,Object> seen){
  if (root == null || seen.containsKey(root)) {
    return;
  }
  if (yieldRoot) {
    if (!visit(root)) {
      return;
    }
  }
  seen.put(root,root);
  if (root instanceof JSONObject) {
    JSONObject json=(JSONObject)root;
    Iterator<String> keys=json.keys();
    while (keys.hasNext()) {
      String key=keys.next();
      try {
        traverseInternal(json.get(key),true,seen);
      }
 catch (      JSONException e) {
        throw new RuntimeException(e);
      }
    }
  }
 else   if (root instanceof JSONArray) {
    JSONArray array=(JSONArray)root;
    for (int i=0; i < array.length(); ++i) {
      try {
        traverseInternal(array.get(i),true,seen);
      }
 catch (      JSONException e) {
        throw new RuntimeException(e);
      }
    }
  }
 else   if (root instanceof Map) {
    Map<?,?> map=(Map<?,?>)root;
    for (    Object value : map.values()) {
      traverseInternal(value,true,seen);
    }
  }
 else   if (root instanceof List) {
    List<?> list=(List<?>)root;
    for (    Object value : list) {
      traverseInternal(value,true,seen);
    }
  }
 else   if (root instanceof ParseObject) {
    if (traverseParseObjects) {
      ParseObject object=(ParseObject)root;
      for (      String key : object.keySet()) {
        traverseInternal(object.get(key),true,seen);
      }
    }
  }
 else   if (root instanceof ParseACL) {
    ParseACL acl=(ParseACL)root;
    ParseUser user=acl.getUnresolvedUser();
    if (user != null && user.isCurrentUser()) {
      traverseInternal(user,true,seen);
    }
  }
}

private void traverseInternal ( Object root , boolean yieldRoot , IdentityHashMap < Object , Object > seen ) { if ( root == null || seen . containsKey ( root ) ) { return ; } if ( yieldRoot ) { if ( ! visit ( root ) ) { return ; } } seen . put ( root , root ) ; if ( root instanceof JSONObject ) { JSONObject json = ( JSONObject ) root ; Iterator < String > keys = json . keys ( ) ; while ( keys . hasNext ( ) ) { String key = keys . next ( ) ; try { traverseInternal ( json . get ( key ) , true , seen ) ; } catch ( JSONException e ) { throw new RuntimeException ( e ) ; } } } else if ( root instanceof JSONArray ) { JSONArray array = ( JSONArray ) root ; for ( int i = 0 ; i < array . length ( ) ; ++ i ) { try { traverseInternal ( array . get ( i ) , true , seen ) ; } catch ( JSONException e ) { throw new RuntimeException ( e ) ; } } } else if ( root instanceof Map ) { Map < ? , ? > map = ( Map < ? , ? > ) root ; for ( Object value : map . values ( ) ) { traverseInternal ( value , true , seen ) ; } } else if ( root instanceof List ) { List < ? > list = ( List < ? > ) root ; for ( Object value : list ) { traverseInternal ( value , true , seen ) ; } } else if ( root instanceof ParseObject ) { if ( traverseParseObjects ) { ParseObject object = ( ParseObject ) root ; for ( String key : object . keySet ( ) ) { traverseInternal ( object . get ( key ) , true , seen ) ; } } } else if ( root instanceof ParseACL ) { ParseACL acl = ( ParseACL ) root ; ParseUser user = acl . getUnresolvedUser ( ) ; if ( user != null && user . isCurrentUser ( ) ) { traverseInternal ( user , true , seen ) ; } } }
internal implementation of traverse .
