// 
// Decompiled by Procyon v0.6.0
// 

package org.bson.json;

import org.bson.codecs.Encoder;
import org.bson.BsonDocumentWrapper;
import org.bson.BsonDocument;
import org.bson.codecs.configuration.CodecRegistry;
import org.bson.assertions.Assertions;
import org.bson.conversions.Bson;

public class JsonObject implements Bson
{
    private final String json;
    
    public JsonObject(final String json) {
        Assertions.notNull("Json", json);
        boolean foundBrace = false;
        for (int i = 0; i < json.length(); ++i) {
            final char c = json.charAt(i);
            if (c == '{') {
                foundBrace = true;
                break;
            }
            Assertions.isTrueArgument("json is a valid JSON object", Character.isWhitespace(c));
        }
        Assertions.isTrueArgument("json is a valid JSON object", foundBrace);
        this.json = json;
    }
    
    public String getJson() {
        return this.json;
    }
    
    @Override
    public <TDocument> BsonDocument toBsonDocument(final Class<TDocument> documentClass, final CodecRegistry registry) {
        return new BsonDocumentWrapper<Object>(this, registry.get(JsonObject.class));
    }
    
    @Override
    public boolean equals(final Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || this.getClass() != o.getClass()) {
            return false;
        }
        final JsonObject that = (JsonObject)o;
        return this.json.equals(that.getJson());
    }
    
    @Override
    public int hashCode() {
        return this.json.hashCode();
    }
    
    @Override
    public String toString() {
        return this.json;
    }
}
