Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save alphazero/354972 to your computer and use it in GitHub Desktop.
Save alphazero/354972 to your computer and use it in GitHub Desktop.
/*
* Copyright 2009 Joubin Houshyar
*
* Licensed 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 design.api;
/**
* A sketch for a fluid option spec'ing in JRedis methods.
*
* @author Joubin Houshyar ([email protected])
* @version alpha.0, Apr 3, 2010
* @since alpha.0
*
*/
public class UsingOpts {
public static void main (String[] args) {
SomeAPI api = null;
api.set("foo", "bar", Options.set().LIMIT(10, 99).ALPHA().WITHSCORES());
api.set("foo", "bar");
}
public interface SomeAPI {
public void set(String key, String value, Options...opts);
}
public interface Option{
/** species the BY clause */
Options BY (String pattern);
/** specifies the GET clause */
Options GET (String pattern);
/** specifies the LIMIT class: from is the intial index, count is the number of results */
Options LIMIT (long from, long count);
/** default sort is ASCending -- use this in your sort to specify DESC sort */
Options DESC ();
/** sort is be default numeric -- use this to indicate lexiographic alphanumeric sort */
Options ALPHA ();
}
public static class Options implements Option {
public static Options set() {
return new Options();
}
public Options ALPHA () {
return this;
}
public Options WITHSCORES () {
return this;
}
public Options BY (String pattern) {
return this;
}
public Options DESC () {
return this;
}
public Options GET (String pattern) {
return this;
}
public Options LIMIT (long from, long count) {
return this;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment