Giter Site home page Giter Site logo

kvstore's Introduction

Keys and Values

Goal: Implement an in-memory key-value store with the specified API

Submission requirements

  • 'Production' quality code (simple, tested, good naming, no duplication)
  • No time limit but early submission of well written, working code will be looked favourably upon
  • Submit via github/gitlab/bitbucket
  • Runs out of the box using maven. i.e. This must work...
git clone <repo url> dir_name
cd dir_name
mvn test

...clone the code from your git repo, cd to the directory, invoke maven to run the tests

API requirements

Part 1

Provide an implementation of the following interface

public interface KeysAndValues {
    void accept(String kvPairs);
    String display();
}

void accept(String s)

  • kvPairs = zero, one or more comma separated, key-value pairs (e.g. "pi=314159,hello=world")
  • Trim all leading & trailing whitespace
  • numeric integer values accumulate
  • non-integers overwrite
  • problematic values are reported via the ErrorListener interface (see below)

Examples

14=15
A=B52
dry=D.R.Y.
14=7
14=4
dry=Don't Repeat Yourself

After invoking accept() on each of these key-value strings in the above order,

  • key 14 is equal to 26 (i.e. 15 + 7 + 4 ...an integer)
  • key dry is equal to Don't repeat yourself (...a string)

invoking accept("14=15, 14=7,A=B52, 14 = 4, dry = Don't Repeat Yourself") has the same effect.

String display()

  • String displays all key-value pairs (one pair per line)
  • Keys are sorted (alpha-ascending, case-insensitive)

Example

Assuming...

KeysAndValues kv = new MyKeysAndValuesImplementation(listener);
kv.accept("one=two");
kv.accept("Three=four");
kv.accept("5=6");
kv.accept("14=X");
String displayText = kv.display();

Then displayText will equal...

14=X
5=6
one=two
Three=four

Error reporting

public interface ErrorListener {
    void onError(String msg);
    void onError(String msg, Exception e);
    void onIncompleteAtomicGroup(Set<String> group, Set<String> missing);
}
  • All errors / failures / warnings must go through an implementation of the ErrorListener interface.
  • Provide a way of injecting an ErrorListener into your KeysAndValues implementation. Do not create a global instance.

Atomic groups

  • keys 441, 442, 500 are an 'atomic group'
  • all 3 must be defined if any one of them appears in the csv parameter to accept()
  • the keys don't have to appear in the same order and can appear anywhere in the string
  • the atomic group can be defined multiple times within the csv string (e.g. 441=1,442=1,500=1, 441=2,442=2,500=2, 441=3,442=3)
  • keys within the same group cannot 'overlap' (i.e. not: 441=1, 442=1, 441=2, 500=1, 442=2, 500=2)
  • if any key is missing, the ErrorListener is notified via onIncompleteAtomicGroup()

Examples

Single atomic group

kv.accept("441=one,X=Y, 442=2,500=three")

441=one 442=2 500=three X=Y

Atomic group specified twice

kv.accept("18=zzz,441=one,500=three,442=2,442= A,441 =3,35=D,500=ok  ")

18=zzz 35=D 441=3 442=A 500=ok

Incomplete group

kv.accept("441=3,500=not ok,13=qwerty")

13=qwerty

ErrorListener invoked with ...

listner.onIncompleteAtomicGroup([441,442,500], [442]);

Second group incomplete

kv.accept("500= three , 6 = 7 ,441= one,442=1,442=4")

441=one 442=1 500=three 6=7

ErrorListener message:

listner.onIncompleteAtomicGroup([441,442,500], [441,500]);

kvstore's People

Contributors

ficcitong avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.