com.couchbase.client.protocol.views.ComplexKey Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of couchbase-client Show documentation
Show all versions of couchbase-client Show documentation
The official Couchbase Java SDK
/**
* Copyright (C) 2009-2013 Couchbase, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALING
* IN THE SOFTWARE.
*/
package com.couchbase.client.protocol.views;
import java.util.Arrays;
import java.util.List;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONObject;
/**
* Allows simple definition of complex JSON keys for query inputs.
*
* If you use the ComplexKex class, the stored objects ultimately get converted
* into a JSON string. As a result, make sure your custom objects implement the
* "toString" method accordingly (unless you work with trivial types like
* Strings or numbers).
*
* Instead of using a constructor, use the static "of" method to generate your
* objects. You can also use a special empty object or array.
*
* Here are some simple examples:
*
* // generated JSON: [2012,9,7]
* ComplexKey.of(2012, 9, 7);
*
* // generated JSON: ["Hello","World",5.12]
* ComplexKey.of("Hello", "World", 5.12);
*
* // generated JSON: {}
* ComplexKey.of(ComplexKey.emptyObject());
*
* // generated JSON: []
* ComplexKey.of(ComplexKey.emptyArray());
*
* This was inspired by the Ektorp project, which queries Apache CouchDB.
*/
public final class ComplexKey {
/**
* Holds the list of object components to convert.
*/
private final List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy