public List<Tag> getTagsOfType(TagType type) { List<Tag> typedTags = new ArrayList<Tag>(); for (Tag tag : allTags) if (tag.getType().equals(type)) typedTags.add(tag); return Collections.unmodifiableList(typedTags); }
@Test public void testByteBufferBackedKeyValueWithTags() throws Exception { KeyValue kvCell = new KeyValue(row1, fam1, qual1, 0l, Type.Put, row1, tags); ByteBuffer buf = ByteBuffer.allocateDirect(kvCell.getBuffer().length); ByteBufferUtils.copyFromArrayToBuffer(buf, kvCell.getBuffer(), 0, kvCell.getBuffer().length); ByteBufferedCell offheapKV = new OffheapKeyValue(buf, 0, buf.capacity(), true, 0l); assertEquals( ROW1, ByteBufferUtils.toStringBinary( offheapKV.getRowByteBuffer(), offheapKV.getRowPositionInByteBuffer(), offheapKV.getRowLength())); assertEquals( FAM1, ByteBufferUtils.toStringBinary( offheapKV.getFamilyByteBuffer(), offheapKV.getFamilyPositionInByteBuffer(), offheapKV.getFamilyLength())); assertEquals( QUAL1, ByteBufferUtils.toStringBinary( offheapKV.getQualifierByteBuffer(), offheapKV.getQualifierPositionInByteBuffer(), offheapKV.getQualifierLength())); assertEquals( ROW1, ByteBufferUtils.toStringBinary( offheapKV.getValueByteBuffer(), offheapKV.getValuePositionInByteBuffer(), offheapKV.getValueLength())); assertEquals(0L, offheapKV.getTimestamp()); assertEquals(Type.Put.getCode(), offheapKV.getTypeByte()); // change tags to handle both onheap and offheap stuff List<Tag> resTags = Tag.asList(offheapKV.getTagsArray(), offheapKV.getTagsOffset(), offheapKV.getTagsLength()); Tag tag1 = resTags.get(0); assertEquals(t1.getType(), tag1.getType()); assertEquals(Bytes.toString(t1.getValue()), Bytes.toString(getTagValue(tag1))); Tag tag2 = resTags.get(1); assertEquals(tag2.getType(), tag2.getType()); assertEquals(Bytes.toString(t2.getValue()), Bytes.toString(getTagValue(tag2))); Tag res = Tag.getTag(offheapKV.getTagsArray(), 0, offheapKV.getTagsLength(), (byte) 2); assertEquals(Bytes.toString(t2.getValue()), Bytes.toString(getTagValue(tag2))); res = Tag.getTag(offheapKV.getTagsArray(), 0, offheapKV.getTagsLength(), (byte) 3); assertNull(res); }
private static boolean renameWorld(String worldname, String newname) { if (isLoaded(worldname)) return false; Tag t = getData(worldname); if (t == null) return false; t = t.findTagByName("Data"); if (t == null || t.getType() != Type.TAG_Compound) return false; int i = 0; for (Tag tt : (Tag[]) t.getValue()) { if (tt.getName().equals("LevelName")) { t.removeTag(i); t.insertTag(new Tag(Type.TAG_String, "LevelName", newname), i); break; } i++; } return setData(worldname, t); }