Mercurial > hg > truffle
comparison truffle/com.oracle.truffle.tck/src/com/oracle/truffle/tck/Schema.java @ 22496:b3569a53c24c
Refactor and improve ComplexNumber sequence tests
author | Matthias Grimmer <grimmer@ssw.jku.at> |
---|---|
date | Mon, 14 Dec 2015 14:20:08 +0100 |
parents | aeba89e1d8da |
children |
comparison
equal
deleted
inserted
replaced
22495:aeba89e1d8da | 22496:b3569a53c24c |
---|---|
23 * questions. | 23 * questions. |
24 */ | 24 */ |
25 package com.oracle.truffle.tck; | 25 package com.oracle.truffle.tck; |
26 | 26 |
27 import java.nio.ByteBuffer; | 27 import java.nio.ByteBuffer; |
28 import java.util.HashMap; | |
29 import java.util.List; | 28 import java.util.List; |
30 import java.util.Map; | |
31 | 29 |
32 public final class Schema { | 30 final class Schema { |
33 | 31 |
34 public enum Type { | 32 enum Type { |
35 DOUBLE(Double.SIZE / Byte.SIZE), | 33 DOUBLE(Double.SIZE / Byte.SIZE), |
36 INT(Integer.SIZE / Byte.SIZE); | 34 INT(Integer.SIZE / Byte.SIZE); |
37 | 35 |
38 private final int size; | 36 private final int size; |
39 | 37 |
45 private final int size; | 43 private final int size; |
46 private final boolean rowBased; | 44 private final boolean rowBased; |
47 private final List<String> names; | 45 private final List<String> names; |
48 private final List<Type> types; | 46 private final List<Type> types; |
49 | 47 |
50 public Schema(int size, boolean rowBased, List<String> names, List<Type> types) { | 48 Schema(int size, boolean rowBased, List<String> names, List<Type> types) { |
51 this.size = size; | 49 this.size = size; |
52 this.rowBased = rowBased; | 50 this.rowBased = rowBased; |
53 this.names = names; | 51 this.names = names; |
54 this.types = types; | 52 this.types = types; |
55 } | 53 } |
56 | 54 |
57 public int length() { | 55 public int length() { |
58 return size; | 56 return size; |
59 } | 57 } |
60 | 58 |
61 // for simplicity: structured data is read-only | 59 public Object get(byte[] buffer, int index, String name) { |
62 | |
63 public Map<String, Object> getEntry(byte[] buffer, int index) { | |
64 Map<String, Object> entry = new HashMap<>(); | |
65 for (int i = 0; i < names.size(); i++) { | |
66 String name = names.get(i); | |
67 Object value = get(buffer, index, name); | |
68 entry.put(name, value); | |
69 } | |
70 return entry; | |
71 } | |
72 | |
73 private Object get(byte[] buffer, int index, String name) { | |
74 assert names.contains(name); | 60 assert names.contains(name); |
75 int offset = rowBased ? getRowOffset(name, index) : getColumnOffset(name, index); | 61 int offset = rowBased ? getRowOffset(name, index) : getColumnOffset(name, index); |
76 if (types.get(names.indexOf(name)) == Type.DOUBLE) { | 62 if (types.get(names.indexOf(name)) == Type.DOUBLE) { |
77 byte[] b = new byte[Type.DOUBLE.size]; | 63 byte[] b = new byte[Type.DOUBLE.size]; |
78 for (int i = 0; i < Type.DOUBLE.size; i++) { | 64 for (int i = 0; i < Type.DOUBLE.size; i++) { |