import org.xerial.core.XerialException;
import org.xerial.silk.SilkWalker;
import org.xerial.util.bean.TypeInformation;
-import org.xerial.util.tree.TreeVisitor;
-import org.xerial.util.tree.TreeWalker;
/**
* Lens is an O-X mapping utility. O stands for Objects, and X for structured
throw new NullPointerException("silkFileResource");
SilkWalker walker = new SilkWalker(silkFileResource);
- RelationScanner scanner = new RelationScanner();
- walker.walk(scanner);
return null;
}
- private static class RelationScanner implements TreeVisitor
- {
-
- public void finish(TreeWalker walker) throws XerialException
- {
- // TODO Auto-generated method stub
-
- }
-
- public void init(TreeWalker walker) throws XerialException
- {
- // TODO Auto-generated method stub
-
- }
-
- public void visitNode(String nodeName, String immediateNodeValue, TreeWalker walker) throws XerialException
- {
- // TODO Auto-generated method stub
-
- }
-
- public void leaveNode(String nodeName, TreeWalker walker) throws XerialException
- {
- // TODO Auto-generated method stub
-
- }
-
- public void text(String textDataFragment, TreeWalker walker) throws XerialException
- {
- // TODO Auto-generated method stub
-
- }
-
- }
-
private enum SetterType {
ADDER, SETTER, GETTER, PUTTER, APPENDER
};
List<FieldSetter> setterContainer = new ArrayList<FieldSetter>();
// look for all super classes
- for (Class< ? > eachClass = type; eachClass != null; eachClass = type.getSuperclass())
+ for (Class< ? > eachClass = type; eachClass != null; eachClass = eachClass.getSuperclass())
{
// scan fields
for (Field eachField : eachClass.getFields())
--- /dev/null
+/*--------------------------------------------------------------------------
+ * Copyright 2009 Taro L. Saito
+ *
+ * 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.
+ *--------------------------------------------------------------------------*/
+//--------------------------------------
+// XerialJ
+//
+// Relation.java
+// Since: Feb 24, 2009 4:08:00 PM
+//
+// $URL$
+// $Author$
+//--------------------------------------
+package org.xerial.lens;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target( { ElementType.FIELD, ElementType.METHOD })
+public @interface Relation {
+ String key() default "key";
+
+ String value() default "value";
+}
--- /dev/null
+/*--------------------------------------------------------------------------
+ * Copyright 2009 Taro L. Saito
+ *
+ * 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.
+ *--------------------------------------------------------------------------*/
+//--------------------------------------
+// XerialJ
+//
+// Tuple.java
+// Since: Feb 24, 2009 5:31:10 PM
+//
+// $URL$
+// $Author$
+//--------------------------------------
+package org.xerial.lens;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.xerial.util.StringUtil;
+
+/**
+ * Tuple is a data structure for holding a list of objects.
+ *
+ * @author leo
+ *
+ */
+public class Tuple
+{
+ private List<Object> tuple;
+
+ /**
+ * Set the tuple value at the specified index
+ *
+ * @param tupleIndex
+ * tuple index
+ * @param value
+ * value object to set
+ */
+ public void set(int tupleIndex, Object value)
+ {
+ tuple.set(tupleIndex, value);
+ }
+
+ /**
+ * Append a new value to the tail of the tuple
+ *
+ * @param value
+ * value object to append
+ */
+ public void append(Object value)
+ {
+ tuple.add(value);
+ }
+
+ /**
+ * Get the tuple size
+ *
+ * @return tuple size
+ */
+ public int size()
+ {
+ assert tuple != null;
+ return tuple.size();
+ }
+
+ /**
+ * Create a new fixed-size tuple. Use this factory method for
+ * space-efficiency.
+ *
+ * @param tupleSize
+ * size of a new tuple
+ * @return fixed-size tuple
+ */
+ public static Tuple newFixedSizeTuple(int tupleSize)
+ {
+ return new Tuple(tupleSize);
+ }
+
+ public static Tuple newPair(Object attribute1, Object attribute2)
+ {
+ Tuple t = newFixedSizeTuple(2);
+ t.set(0, attribute1);
+ t.set(1, attribute2);
+ return t;
+ }
+
+ private Tuple(int tupleSize)
+ {
+ tuple = new ArrayList<Object>(tupleSize);
+
+ // initialize the tuple with null values
+ for (int i = 0; i < tupleSize; ++i)
+ tuple.add(null);
+ }
+
+ /**
+ * Get the tuple value at the specified index
+ *
+ * @param index
+ * tuple index in the tuple to retrieve value
+ * @return value at the specified tuple index
+ * @throws IndexOutOfBoundsException
+ * when index exceeds the tuple size
+ */
+ public Object get(int index)
+ {
+ return tuple.get(index);
+ }
+
+ @Override
+ public String toString()
+ {
+ return String.format("(%s)", StringUtil.join(tuple, ", "));
+ }
+
+ /*
+ public int compareTo(Tuple o)
+ {
+ if (o instanceof Tuple)
+ {
+ Tuple other = Tuple.class.cast(o);
+ int s1 = size();
+ int s2 = other.size();
+ if (s1 < s2)
+ {
+ return -1;
+ }
+ else if (s1 > s2)
+ {
+ return 1;
+ }
+ else
+ {
+ for (int i = 0; i < s1; ++i)
+ {
+
+ }
+ }
+
+ }
+ }
+ */
+
+}
--- /dev/null
+/*--------------------------------------------------------------------------
+ * Copyright 2009 Taro L. Saito
+ *
+ * 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.
+ *--------------------------------------------------------------------------*/
+//--------------------------------------
+// XerialJ
+//
+// StreamAmoebaJoin.java
+// Since: Feb 24, 2009 2:00:28 PM
+//
+// $URL$
+// $Author$
+//--------------------------------------
+package org.xerial.lens.impl;
+
+import org.xerial.core.XerialException;
+import org.xerial.util.graph.Lattice;
+import org.xerial.util.graph.LatticeCursor;
+import org.xerial.util.tree.TreeVisitor;
+import org.xerial.util.tree.TreeWalker;
+
+/**
+ * Stream amoeba join processor
+ *
+ * @author leo
+ *
+ */
+public class StreamAmoebaJoin
+{
+
+ public StreamAmoebaJoin()
+ {
+
+ }
+
+ public void process(TreeWalker walker) throws XerialException
+ {
+ TreeStreamProcessor processor = new TreeStreamProcessor();
+ walker.walk(processor);
+ }
+
+ private class TreeStreamProcessor implements TreeVisitor
+ {
+ Lattice<String> contextNodeSet = new Lattice<String>();
+ LatticeCursor<String> cursor;
+
+ public void finish(TreeWalker walker) throws XerialException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void init(TreeWalker walker) throws XerialException
+ {
+ cursor = contextNodeSet.cursor();
+ }
+
+ public void leaveNode(String nodeName, TreeWalker walker) throws XerialException
+ {
+ int prevStateID = cursor.getNodeID();
+ int nextStateID = cursor.back(nodeName).getID();
+
+ }
+
+ public void text(String textDataFragment, TreeWalker walker) throws XerialException
+ {
+
+ }
+
+ public void visitNode(String nodeName, String immediateNodeValue, TreeWalker walker) throws XerialException
+ {
+ int prevStateID = cursor.getNodeID();
+ int nextStateID = cursor.next(nodeName).getID();
+
+ }
+
+ }
+
+ private class ActionTable
+ {
+
+ }
+
+}
//--------------------------------------
package org.xerial.util;
-/**
+/**
* Pair of two objects
+ *
* @author leo
- *
+ *
*/
public class Pair<X, Y>
{
private X x;
private Y y;
-
+
/**
*
*/
this.x = x;
this.y = y;
}
+
public X getFirst()
{
return x;
}
+
public Y getSecond()
{
return y;
}
+
public void setFirst(X x)
{
this.x = x;
}
+
public void setSecond(Y y)
{
this.y = y;
}
-
-}
-
+ public static <X, Y> Pair<X, Y> newPair(X x, Y y)
+ {
+ return new Pair<X, Y>(x, y);
+ }
+ @Override
+ public String toString()
+ {
+ return String.format("(%s, %s)", x, y);
+ }
+}
package org.xerial.util;\r
\r
/**\r
- * Triplet structure \r
+ * Triplet structure\r
* \r
* @author leo\r
- *\r
+ * \r
*/\r
-public class Triplet<E, F, J> \r
+public class Triplet<E, F, J>\r
{\r
private E first;\r
private F second;\r
private J third;\r
+\r
public Triplet(E first, F second, J third)\r
{\r
this.first = first;\r
this.second = second;\r
this.third = third;\r
}\r
- \r
+\r
/**\r
* @return Returns the first.\r
*/\r
{\r
return first;\r
}\r
+\r
/**\r
- * @param first The first to set.\r
+ * @param first\r
+ * The first to set.\r
*/\r
public void setFirst(E first)\r
{\r
this.first = first;\r
}\r
+\r
/**\r
* @return Returns the second.\r
*/\r
{\r
return second;\r
}\r
+\r
/**\r
- * @param second The second to set.\r
+ * @param second\r
+ * The second to set.\r
*/\r
public void setSecond(F second)\r
{\r
this.second = second;\r
}\r
+\r
/**\r
* @return Returns the third.\r
*/\r
{\r
return third;\r
}\r
+\r
/**\r
- * @param third The third to set.\r
+ * @param third\r
+ * The third to set.\r
*/\r
public void setThird(J third)\r
{\r
this.third = third;\r
}\r
-}\r
\r
+ public static <E, F, J> Triplet<E, F, J> newTriplet(E first, F second, J third)\r
+ {\r
+ return new Triplet<E, F, J>(first, second, third);\r
+ }\r
+\r
+ @Override\r
+ public String toString()\r
+ {\r
+ return String.format("(%s, %s, %s)", first, second, third);\r
+ }\r
+\r
+}\r
import org.w3c.dom.Element;
import org.xerial.util.ArrayDeque;
+import org.xerial.util.Pair;
+import org.xerial.util.Triplet;
/**
* BasicType class holds information of standard types that can be directly
return Element.class.isAssignableFrom(c);
}
+ public static boolean isPair(Class< ? > c)
+ {
+ return Pair.class.isAssignableFrom(c);
+ }
+
+ public static boolean isTriplet(Class< ? > c)
+ {
+ return Triplet.class.isAssignableFrom(c);
+ }
+
public static boolean hasPublicConstructor(Class< ? > c)
{
for (Constructor< ? > constructor : c.getConstructors())
package org.xerial.lens;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.junit.Test;
import org.xerial.silk.SilkUtilTest;
import org.xerial.util.FileResource;
+import org.xerial.util.Pair;
import org.xerial.util.log.Logger;
public class LensTest
@Test
public void testTranslateSilk()
+ {}
+
+ static class GeneTableOneToMany
{
- fail("Not yet implemented");
+ @Relation(key = "coordinate", value = "gene")
+ public Map<Coordinate, List<GeneSequence>> sequenceTable;
}
- static class GeneTable
+ /**
+ * Example of showing that adder with two arguments corresponds to a
+ * Map<Key, Collection<Value>> parameter.
+ *
+ * @author leo
+ *
+ */
+ static class GeneTableWithMapAdder
{
private Map<Coordinate, List<GeneSequence>> sequenceTable;
+
+ @Relation(key = "coordinate", value = "gene")
+ public void add(Coordinate coordinate, GeneSequence gene)
+ {
+ List<GeneSequence> geneList = sequenceTable.get(coordinate);
+ if (geneList == null)
+ {
+ geneList = new ArrayList<GeneSequence>();
+ sequenceTable.put(coordinate, geneList);
+ }
+ geneList.add(gene);
+ }
+ }
+
+ static class GeneTableOneToOne
+ {
+ @Relation(key = "coordinate", value = "gene")
+ public List<Pair<Coordinate, GeneSequence>> geneList;
+ }
+
+ static class GeneTableOneToOneWithAdder
+ {
+ public List<Pair<Coordinate, GeneSequence>> geneList;
+
+ @Relation(key = "coordinate", value = "gene")
+ public void add(Coordinate coordinate, GeneSequence gene)
+ {
+ geneList.add(Pair.newPair(coordinate, gene));
+ }
}
static class GeneSequence
-\r
--coordinate(group:utgb, type:chromosome, species:human, revision:hg18)\r
- -coordinate.name:chr1\r
- -entry(name, start, strand, sequence, param[json])|\r
+-coordinate(group:utgb, type:chromosome, species:human, revision:hg18, name:chr1)\r
+ -gene(name, start, strand, sequence, param[json])|\r
TAG1 100 + ACCCGGTTTTGGCGCTTTCCTTTC[----]TTGGCCTTGGGGCCCATCB {"link":"http://somewhere.org/", "description":"reference sequence"}\r
TAG2 100 - ACCCGG---GGCGCTTTCCCTTTC --AC TTGGCCTTGGGGCCCATCG \r
\r
-#-coordinate.name:chr2\r
-# -entry(name, start, strand, sequence, param[json])|\r
-#TAG3 100 - ACCCGGTTTTGGCGCTTTCCTTTC[----]TTGGCCTTGGGGCCCATCB {"memo":"in/del"} \r
-#TAG4 100 + ACCCGG---GGCGCTTTCCCTTTC --AC TTGGCCTTGGGGCCCATCG \r
-\r
-\r
+-(group:utgb, type:chromosome, species:human, revision:hg18)\r
+ -coordinate(name:chr2)\r
+ -gene(name, start, strand, sequence, param[json])|\r
+TAG3 100 - ACCCGGTTTTGGCGCTTTCCTTTC[----]TTGGCCTTGGGGCCCATCB {"memo":"in/del"} \r
+TAG4 100 + ACCCGG---GGCGCTTTCCCTTTC --AC TTGGCCTTGGGGCCCATCG \r
import org.w3c.dom.Node;
import org.w3c.dom.Text;
import org.xerial.util.ArrayDeque;
+import org.xerial.util.Pair;
+import org.xerial.util.Triplet;
import org.xerial.util.bean.sample.Book;
import org.xerial.util.log.Logger;
}
@Test
+ public void testIsPair()
+ {
+ assertTrue(TypeInformation.isPair(Pair.class));
+ assertTrue(!TypeInformation.isPair(Triplet.class));
+ }
+
+ @Test
+ public void testIsTriplet()
+ {
+ assertTrue(!TypeInformation.isTriplet(Pair.class));
+ assertTrue(TypeInformation.isTriplet(Triplet.class));
+ }
+
+ @Test
public void testIsQueue() throws Exception
{
assertTrue(TypeInformation.isQueue(Queue.class));