/** * @param binding the specific kind of {@link RevObject} for which to return its bound enum * value * @return the enum value bound to {@code binding} */ public static TYPE valueOf(final Class<? extends RevObject> binding) { Preconditions.checkNotNull(binding); Integer value = byBinding.get(binding); Preconditions.checkNotNull(value); return valueOf(value); } }
public TYPE readHeader(DataInput in) throws IOException { final int header = in.readByte() & 0xFF; checkState(header > -1 && header < 6, "Illegal RevObject type header: %s, must be between 0 and 4 inclusive", Integer.valueOf(header)); final RevObject.TYPE type = TYPE.valueOf(header); return type; }
/** * @param binding the specific kind of {@link RevObject} for which to return its bound enum * value * @return the enum value bound to {@code binding} */ public static TYPE valueOf(final Class<? extends RevObject> binding) { Preconditions.checkNotNull(binding); Integer value = byBinding.get(binding); Preconditions.checkNotNull(value); return valueOf(value); } }
final int extraDataMask = typeAndMasks & EXTRA_DATA_READ_MASK; final RevObject.TYPE contentType = RevObject.TYPE.valueOf(nodeType); final String name = in.readUTF(); final ObjectId objectId = readObjectId(in);
final TYPE objType = RevObject.class.equals(type) ? null : RevObject.TYPE.valueOf(type); final String tableName = db.tableNameForType(objType, null);
@Override public <T extends RevObject> T getIfPresent(final ObjectId id, final Class<T> type) throws IllegalArgumentException { checkNotNull(id, "argument id is null"); checkNotNull(type, "argument class is null"); checkState(isOpen(), "db is closed"); config.checkRepositoryExists(); final RevObject obj; if (RevTree.EMPTY_TREE_ID.equals(id)) { return type.isAssignableFrom(RevTree.class) ? type.cast(RevTree.EMPTY) : null; } @Nullable final TYPE objectType; if (RevObject.class.equals(type)) { objectType = null; } else { objectType = RevObject.TYPE.valueOf(type); } obj = getIfPresent(id, objectType, dataSource); if (obj == null) { return null; } if (!type.isAssignableFrom(obj.getClass())) { return null; } return type.cast(obj); }
@Override public <T extends RevObject> T getIfPresent(final ObjectId id, final Class<T> type) throws IllegalArgumentException { checkNotNull(id, "argument id is null"); checkNotNull(type, "argument class is null"); checkState(isOpen(), "db is closed"); config.checkRepositoryExists(); final RevObject obj; if (RevTree.EMPTY_TREE_ID.equals(id)) { return type.isAssignableFrom(RevTree.class) ? type.cast(RevTree.EMPTY) : null; } @Nullable final TYPE objectType; if (RevObject.class.equals(type)) { objectType = null; } else { objectType = RevObject.TYPE.valueOf(type); } obj = getIfPresent(id, objectType, dataSource); if (obj == null) { return null; } if (!type.isAssignableFrom(obj.getClass())) { return null; } return type.cast(obj); }
@SuppressWarnings("unchecked") @Override public Node readNode(DataInput in) throws IOException { final int typeAndMasks = in.readByte() & 0xFF; final int nodeType = typeAndMasks & TYPE_READ_MASK; final int boundsMask = typeAndMasks & BOUNDS_READ_MASK; //unused final int metadataMask = typeAndMasks & METADATA_READ_MASK; final int extraDataMask = typeAndMasks & EXTRA_DATA_READ_MASK; final RevObject.TYPE contentType = RevObject.TYPE.valueOf(nodeType); final String name = in.readUTF(); final ObjectId objectId = readObjectId(in); ObjectId metadataId = ObjectId.NULL; if (metadataMask == METADATA_PRESENT_MASK) { metadataId = readObjectId(in); } @Nullable final Envelope bbox = readBounds(in); Map<String, Object> extraData = null; if (extraDataMask == EXTRA_DATA_PRESENT_MASK) { Object extra = valueEncoder.decode(FieldType.MAP, in); Preconditions.checkState(extra instanceof Map); extraData = (Map<String, Object>) extra; } final Node node; node = Node.create(name, objectId, metadataId, contentType, bbox, extraData); return node; }
@SuppressWarnings("unchecked") @Override public Node readNode(DataInput in) throws IOException { final int typeAndMasks = in.readByte() & 0xFF; final int nodeType = typeAndMasks & TYPE_READ_MASK; // final int boundsMask = typeAndMasks & BOUNDS_READ_MASK; //unused final int metadataMask = typeAndMasks & METADATA_READ_MASK; final int extraDataMask = typeAndMasks & EXTRA_DATA_READ_MASK; final RevObject.TYPE contentType = RevObject.TYPE.valueOf(nodeType); final String name = in.readUTF(); final ObjectId objectId = readObjectId(in); ObjectId metadataId = ObjectId.NULL; if (metadataMask == METADATA_PRESENT_MASK) { metadataId = readObjectId(in); } @Nullable final Envelope bbox = readBounds(in); Map<String, Object> extraData = null; if (extraDataMask == EXTRA_DATA_PRESENT_MASK) { Object extra = valueEncoder.decode(FieldType.MAP, in); Preconditions.checkState(extra instanceof Map); extraData = (Map<String, Object>) extra; } final Node node; node = RevObjectFactory.defaultInstance().createNode(name, objectId, metadataId, contentType, bbox, extraData); return node; }
@SuppressWarnings("unchecked") protected Node parseNodeLine(String line) { List<String> tokens = newArrayList(Splitter.on('\t').split(line)); final int numTokens = tokens.size(); Preconditions.checkArgument(numTokens == 6 || numTokens == 7, "Wrong tree element definition: %s", line); TYPE type = TYPE.valueOf(tokens.get(1)); String name = tokens.get(2); ObjectId id = ObjectId.valueOf(tokens.get(3)); ObjectId metadataId = ObjectId.valueOf(tokens.get(4)); Envelope bbox = parseBBox(tokens.get(5)); Map<String, Object> extraData = null; if (numTokens == 7) { String extraDataAsString = tokens.get(6); extraData = Converters.convert(extraDataAsString, Map.class); } return org.locationtech.geogig.model.RevObjectFactory.defaultInstance().createNode(name, id, metadataId, type, bbox, extraData); }
@Override public T read(ObjectId id, InputStream rawData) throws IllegalArgumentException { try { BufferedReader reader; reader = new BufferedReader(new InputStreamReader(rawData, "UTF-8")); TYPE type = RevObject.TYPE.valueOf(requireLine(reader).trim()); T parsed = read(id, reader, type); Preconditions.checkState(parsed != null, "parsed to null"); if (id != null) { Preconditions.checkState(id.equals(parsed.getId()), "Expected and parsed object ids don't match: %s %s", id, parsed.getId()); } return parsed; } catch (IOException e) { throw new RuntimeException(e); } }
protected Node parseNodeLine(String line) { List<String> tokens = newArrayList(Splitter.on('\t').split(line)); final int numTokens = tokens.size(); Preconditions.checkArgument(numTokens == 6 || numTokens == 7, "Wrong tree element definition: %s", line); TYPE type = TYPE.valueOf(tokens.get(1)); String name = tokens.get(2); ObjectId id = ObjectId.valueOf(tokens.get(3)); ObjectId metadataId = ObjectId.valueOf(tokens.get(4)); Envelope bbox = parseBBox(tokens.get(5)); Map<String, Object> extraData = null; if (numTokens == 7) { String extraDataAsString = tokens.get(6); extraData = Converters.convert(extraDataAsString, Map.class); } org.locationtech.geogig.model.Node ref = org.locationtech.geogig.model.Node.create(name, id, metadataId, type, bbox, extraData); return ref; }
@Override public T read(ObjectId id, InputStream rawData) throws IllegalArgumentException { try { BufferedReader reader; reader = new BufferedReader(new InputStreamReader(rawData, "UTF-8")); TYPE type = RevObject.TYPE.valueOf(requireLine(reader).trim()); T parsed = read(id, reader, type); Preconditions.checkState(parsed != null, "parsed to null"); if (id != null) { Preconditions.checkState(id.equals(parsed.getId()), "Expected and parsed object ids don't match: %s %s", id, parsed.getId()); } return parsed; } catch (Exception e) { throw Throwables.propagate(e); } }
@Test public void testTypeValues() { assertEquals(RevObject.TYPE.COMMIT, RevObject.TYPE.valueOf(RevCommit.class)); assertEquals(RevObject.TYPE.FEATURE, RevObject.TYPE.valueOf(RevFeature.class)); assertEquals(RevObject.TYPE.FEATURETYPE, RevObject.TYPE.valueOf(RevFeatureType.class)); assertEquals(RevObject.TYPE.TAG, RevObject.TYPE.valueOf(RevTag.class)); assertEquals(RevObject.TYPE.TREE, RevObject.TYPE.valueOf(RevTree.class)); assertEquals(RevObject.TYPE.COMMIT, RevObject.TYPE.valueOf(RevObject.TYPE.COMMIT.value())); assertEquals(RevObject.TYPE.FEATURE, RevObject.TYPE.valueOf(RevObject.TYPE.FEATURE.value())); assertEquals(RevObject.TYPE.FEATURETYPE, RevObject.TYPE.valueOf(RevObject.TYPE.FEATURETYPE.value())); assertEquals(RevObject.TYPE.TAG, RevObject.TYPE.valueOf(RevObject.TYPE.TAG.value())); assertEquals(RevObject.TYPE.TREE, RevObject.TYPE.valueOf(RevObject.TYPE.TREE.value())); }
private RevObject.TYPE getType(Class<? extends RevObject> clazz) { return TYPE.valueOf(clazz); }
public static Header parse(ByteBuffer data) { DataInput in = RevTreeFormat.asDataInput(data); try { final int type = in.readUnsignedByte(); TYPE _type = TYPE.valueOf(type); Preconditions.checkArgument(TYPE.TREE.equals(_type)); final long size = Varint.readUnsignedVarLong(in); final int trees = Varint.readUnsignedVarInt(in); return new Header(size, trees); } catch (IOException e) { throw Throwables.propagate(e); } } }
public static Header parse(ByteBuffer data) { DataInput in = RevTreeFormat.asDataInput(data); try { final int type = in.readUnsignedByte(); TYPE _type = TYPE.valueOf(type); Preconditions.checkArgument(TYPE.TREE.equals(_type)); final long size = Varint.readUnsignedVarLong(in); final int trees = Varint.readUnsignedVarInt(in); return new Header(size, trees); } catch (IOException e) { throw new RuntimeException(e); } } }
public static Node readNode(DataInput in) throws IOException { final String name = in.readUTF(); final byte[] objectId = new byte[20]; in.readFully(objectId); final byte[] metadataId = new byte[20]; in.readFully(metadataId); final RevObject.TYPE contentType = RevObject.TYPE.valueOf(in.readByte()); final Envelope bbox = readBBox(in); Map<String, Object> extraData = DataStreamValueSerializerV1.INSTANCE.readMap(in); final Node node; node = Node.create(name, ObjectId.createNoClone(objectId), ObjectId.createNoClone(metadataId), contentType, bbox, extraData); return node; }
public TYPE readHeader(DataInput in) throws IOException { final int header = in.readByte() & 0xFF; checkState(header > -1 && header < 6, "Illegal RevObject type header: %s, must be between 0 and 4 inclusive", Integer.valueOf(header)); final RevObject.TYPE type = TYPE.valueOf(header); return type; }
public static Node readNode(DataInput in) throws IOException { final String name = in.readUTF(); final ObjectId objectId = ObjectId.readFrom(in); final ObjectId metadataId = ObjectId.readFrom(in); final RevObject.TYPE contentType = RevObject.TYPE.valueOf(in.readByte()); final Envelope bbox = readBBox(in); Map<String, Object> extraData = DataStreamValueSerializerV1.INSTANCE.readMap(in); final Node node; node = RevObjectFactory.defaultInstance().createNode(name, objectId, metadataId, contentType, bbox, extraData); return node; }