infinispan.org.iq80.leveldb.table.BlockEntry Maven / Gradle / Ivy
/**
* Copyright (C) 2011 the original author or authors.
* See the notice.md file distributed with this work for additional
* information regarding copyright ownership.
*
* 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.
*/
package org.iq80.leveldb.table;
import com.google.common.base.Function;
import com.google.common.base.Preconditions;
import org.iq80.leveldb.util.Slice;
import java.util.Arrays;
import java.util.Map.Entry;
import static com.google.common.base.Charsets.UTF_8;
/**
* Binary Structure
*
*
*
*
* name
* offset
* length
* description
*
*
*
*
* shared key length
* 0
* vary
* variable length encoded int: size of shared key prefix with the key from the previous entry
*
*
* non-shared key length
* vary
* vary
* variable length encoded int: size of non-shared key suffix in this entry
*
*
* value length
* vary
* vary
* variable length encoded int: size of value in this entry
*
*
* non-shared key
* vary
* non-shared key length
* non-shared key data
*
*
* value
* vary
* value length
* value data
*
*
*
*/
public class BlockEntry implements Entry
{
public static final Function GET_KEY = new Function()
{
@Override
public Slice apply(BlockEntry blockEntry)
{
return blockEntry.getKey();
}
};
private final Slice key;
private final Slice value;
public BlockEntry(Slice key, Slice value)
{
Preconditions.checkNotNull(key, "key is null");
Preconditions.checkNotNull(value, "value is null");
this.key = key;
this.value = value;
}
public Slice getKey()
{
return key;
}
public Slice getValue()
{
return value;
}
/**
* @throws UnsupportedOperationException always
*/
@Override
public final Slice setValue(Slice value)
{
throw new UnsupportedOperationException();
}
@Override
public boolean equals(Object o)
{
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
BlockEntry entry = (BlockEntry) o;
if (!key.equals(entry.key)) {
return false;
}
if (!value.equals(entry.value)) {
return false;
}
return true;
}
@Override
public int hashCode()
{
int result = key.hashCode();
result = 31 * result + value.hashCode();
return result;
}
@Override
public String toString()
{
final StringBuilder sb = new StringBuilder();
sb.append("BlockEntry");
sb.append("{key=").append(key.toString(UTF_8)); // todo don't print the real value
sb.append(", value=").append(value.toString(UTF_8));
sb.append('}');
return sb.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy