Skip to content

Commit

Permalink
add shell interpreter
Browse files Browse the repository at this point in the history
  • Loading branch information
otrack committed Nov 29, 2019
1 parent d80a99f commit 6d16ac1
Show file tree
Hide file tree
Showing 11 changed files with 487 additions and 15 deletions.
49 changes: 42 additions & 7 deletions client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,35 @@
<version>${project.version}</version>
</dependency>

<!-- TEST -->

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<groupId>args4j</groupId>
<artifactId>args4j</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>args4j</groupId>
<artifactId>args4j</artifactId>
<groupId>info.picocli</groupId>
<artifactId>picocli</artifactId>
<version>4.0.4</version>
</dependency>

<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.9.11</version>
</dependency>

<dependency>
<groupId>pl.joegreen</groupId>
<artifactId>lambda-from-string</artifactId>
<version>1.6</version>
</dependency>

<!-- TEST -->

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>test</scope>
</dependency>

Expand All @@ -43,6 +61,24 @@
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<!-- annotationProcessorPaths requires maven-compiler-plugin version 3.5 or higher -->
<version>${maven-compiler-plugin-version}</version>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>info.picocli</groupId>
<artifactId>picocli-codegen</artifactId>
<version>4.0.4</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
<arg>-Aproject=${groupId}/${artifactId}</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
Expand Down Expand Up @@ -97,4 +133,3 @@
</build>

</project>

21 changes: 18 additions & 3 deletions client/src/main/java/org/infinispan/creson/AtomicCounter.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
package org.infinispan.creson;

import picocli.CommandLine.Command;
import picocli.CommandLine.Option;

import javax.persistence.Entity;
import javax.persistence.Id;

@Entity
@Command(name = "counter")
public class AtomicCounter implements Comparable<AtomicCounter> {

@Id
public String name;
public int count;
@Option(names = "-n" )
public String name = "cnt";

@Option(names = "-c" )
public int count = 0;

public AtomicCounter(){}

public AtomicCounter(String name) {
this.name = name;
}

public AtomicCounter(String name, int value){
this.name = name;
this.count = value;
Expand All @@ -21,7 +32,8 @@ public int increment() {
return increment(1);
}

public int increment(int inc){
@Command(name = "increment")
public int increment(@Option(names = "-i") int inc){
count+=inc;
return count;
}
Expand All @@ -30,16 +42,19 @@ public int decrement() {
return --count;
}

@Command(name = "tally")
public int tally() {
return count;
}

@Override
public int compareTo(AtomicCounter that) {
if (this.count < that.count) return -1;
else if (this.count > that.count) return +1;
else return 0;
}

@Command(name = "reset")
public void reset() {
count=0;
}
Expand Down
157 changes: 157 additions & 0 deletions client/src/main/java/org/infinispan/creson/AtomicList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
package org.infinispan.creson;

import picocli.CommandLine.Command;
import picocli.CommandLine.Option;

import javax.persistence.Entity;
import javax.persistence.Id;
import java.util.*;

@Entity
@Command(name = "list")
public class AtomicList<E> implements List<E> {

@Id
@Option(names = "-n" )
public String name = "list";

private List<E> delegate;

public AtomicList(){}

public AtomicList(String name){
this.name = name;
this.delegate = new ArrayList<>();
}

@Override
@Command(name = "size")
public int size() {
return delegate.size();
}

@Override
@Command(name = "isEmpty")
public boolean isEmpty() {
return delegate.isEmpty();
}

@Override
@Command(name = "contains")
public boolean contains(@Option(names = "-1") Object o) {
return delegate.contains(o);
}

@Override
public Iterator<E> iterator() {
throw new IllegalStateException();
}

@Override
@Command(name = "toArray")
public Object[] toArray() {
return (Object[]) delegate.toArray();
}

@Override
public <T> T[] toArray(T[] ts) {
throw new IllegalStateException();
}

@Override
@Command(name = "add")
public boolean add(@Option(names = "-1") E e) {
return delegate.add(e);
}

@Override
@Command(name = "remove")
public boolean remove(@Option(names = "-1") Object o) {
return delegate.remove(o);
}

@Override
@Command(name = "containsAll")
public boolean containsAll(@Option(names = "-1") Collection<?> collection) {
return delegate.containsAll(collection);
}

@Override
@Command(name = "addAll")
public boolean addAll(@Option(names = "-1") Collection<? extends E> collection) {
return delegate.addAll(collection);
}

@Override
public boolean addAll(int i, Collection<? extends E> collection) {
throw new IllegalStateException();
}

@Override
@Command(name = "removeAll")
public boolean removeAll(@Option(names = "-1") Collection<?> collection) {
return delegate.removeAll(collection);
}

@Override
@Command(name = "retainAll")
public boolean retainAll(@Option(names = "-1") Collection<?> collection) {
return delegate.retainAll(collection);
}

@Override
@Command(name = "clear")
public void clear() {
delegate.clear();
}

@Override
@Command(name = "get")
public E get(@Option(names = "-1") int i) {
return delegate.get(i);
}

@Override
@Command(name = "set")
public E set(@Option(names = "-1") int i, @Option(names = "-2") E e) {
return delegate.set(i,e);
}

@Override
public void add(int i, E e) {
throw new IllegalStateException();
}

@Override
public E remove(int i) {
throw new IllegalStateException();
}

@Override
@Command(name = "indexOf")
public int indexOf(@Option(names = "-1") Object o) {
return delegate.indexOf(o);
}

@Override
@Command(name = "lastIndexOf")
public int lastIndexOf(@Option(names = "-1") Object o) {
return delegate.lastIndexOf(o);
}

@Override
public ListIterator<E> listIterator() {
throw new IllegalStateException();
}

@Override
public ListIterator<E> listIterator(int i) {
throw new IllegalStateException();
}

@Override
@Command(name = "subList")
public List<E> subList(@Option(names = "-1") int i, @Option(names = "-2") int j) {
return new ArrayList<>(delegate.subList(i,j)); // inner class
}
}
Loading

0 comments on commit 6d16ac1

Please sign in to comment.