if (isObject(instance)) {
collatedInstances = collatedInstances || {};
forEach(instance, function (instanceValue, instanceKey) {
var currentEventualSchemaLevel = collatedInstances[instanceKey] || {};
var keyAddedForFirstTime = !(instanceKey in collatedInstances);
increaseCount = !keyAddedForFirstTime;
currentEventualSchemaLevel = self._addInstance(currentEventualSchemaLevel, instanceValue, true);
currentEventualSchemaLevel._propertyCount = (increaseCount && currentEventualSchemaLevel._propertyCount) ? currentEventualSchemaLevel._propertyCount + 1 : 1;
if (keyAddedForFirstTime) {
self._propertyCount += 1;
}
collatedInstances[instanceKey] = currentEventualSchemaLevel;
});
return collatedInstances;
}
if (isArrayOfObjects(instance)) {
collatedInstances = collatedInstances || {};
forEach(instance, function (instanceValue, instanceKey) {
var currentEventualSchemaLevel = {};
currentEventualSchemaLevel._arrayObjects = self._addInstance(extend({}, collatedInstances._arrayObjects), instanceValue, false);
currentEventualSchemaLevel._propertyCount = collatedInstances._propertyCount ? collatedInstances._propertyCount : 0;
collatedInstances = currentEventualSchemaLevel;
});