<commit_before>/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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.apache.jackrabbit.oak.plugins.segment;

import static com.google.common.base.Preconditions.checkNotNull;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;

import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeBuilder;
import org.apache.jackrabbit.oak.spi.state.AbstractNodeState;
import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
import org.apache.jackrabbit.oak.spi.state.NodeState;

class SegmentNodeState extends AbstractNodeState {

    public static RecordId getRecordIdIfAvailable(NodeState state) {
        if (state instanceof SegmentNodeState) {
            SegmentNodeState sstate = (SegmentNodeState) state;
            return sstate.recordId;
        }
        return null;
    }

    private final SegmentReader reader;

    private final RecordId recordId;

    private NodeTemplate template = null;

    SegmentNodeState(SegmentReader reader, RecordId id) {
        this.reader = checkNotNull(reader);
        this.recordId = checkNotNull(id);
    }

    private synchronized NodeTemplate getTemplate() {
        if (template == null) {
            template = reader.readTemplate(reader.readRecordId(recordId, 0));
        }
        return template;
    }

    @Override
    public long getPropertyCount() {
        return getTemplate().getPropertyCount();
    }

    @Override @CheckForNull
    public PropertyState getProperty(String name) {
        checkNotNull(name);
        return getTemplate().getProperty(name, reader, recordId);
    }

    @Override @Nonnull
    public Iterable<PropertyState> getProperties() {
        return getTemplate().getProperties(reader, recordId);
    }

    @Override
    public long getChildNodeCount() {
        return getTemplate().getChildNodeCount(reader, recordId);
    }

    @Override
    public boolean hasChildNode(String name) {
        return getTemplate().hasChildNode(checkNotNull(name), reader, recordId);
    }

    @Override @CheckForNull
    public NodeState getChildNode(String name) {
        return getTemplate().getChildNode(checkNotNull(name), reader, recordId);
    }

    @Override
    public Iterable<String> getChildNodeNames() {
        return getTemplate().getChildNodeNames(reader, recordId);
    }

    @Override @Nonnull
    public Iterable<? extends ChildNodeEntry> getChildNodeEntries() {
        return getTemplate().getChildNodeEntries(reader, recordId);
    }

    @Override @Nonnull
    public NodeBuilder builder() {
        return new MemoryNodeBuilder(this);
    }

    public boolean equals(Object object) {
        if (this == object) {
            return true;
        } else if (object instanceof NodeState) {
            if (object instanceof SegmentNodeState
                    && recordId.equals(((SegmentNodeState) object).recordId)) {
                return true;
            } else {
                return super.equals(object);
            }
        } else {
            return false;
        }
    }

}<commit_msg>OAK-593: Segment-based MK<commit_after>/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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.apache.jackrabbit.oak.plugins.segment;

import static com.google.common.base.Preconditions.checkNotNull;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;

import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeBuilder;
import org.apache.jackrabbit.oak.spi.state.AbstractNodeState;
import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
import org.apache.jackrabbit.oak.spi.state.NodeState;

class SegmentNodeState extends AbstractNodeState {

    public static RecordId getRecordIdIfAvailable(NodeState state) {
        if (state instanceof SegmentNodeState) {
            SegmentNodeState sstate = (SegmentNodeState) state;
            return sstate.recordId;
        }
        return null;
    }

    private final SegmentReader reader;

    private final RecordId recordId;

    private NodeTemplate template = null;

    SegmentNodeState(SegmentReader reader, RecordId id) {
        this.reader = checkNotNull(reader);
        this.recordId = checkNotNull(id);
    }

    private synchronized NodeTemplate getTemplate() {
        if (template == null) {
            template = reader.readTemplate(reader.readRecordId(recordId, 0));
        }
        return template;
    }

    @Override
    public long getPropertyCount() {
        return getTemplate().getPropertyCount();
    }

    @Override @CheckForNull
    public PropertyState getProperty(String name) {
        checkNotNull(name);
        return getTemplate().getProperty(name, reader, recordId);
    }

    @Override @Nonnull
    public Iterable<PropertyState> getProperties() {
        return getTemplate().getProperties(reader, recordId);
    }

    @Override
    public long getChildNodeCount() {
        return getTemplate().getChildNodeCount(reader, recordId);
    }

    @Override
    public boolean hasChildNode(String name) {
        return getTemplate().hasChildNode(checkNotNull(name), reader, recordId);
    }

    @Override @CheckForNull
    public NodeState getChildNode(String name) {
        return getTemplate().getChildNode(checkNotNull(name), reader, recordId);
    }

    @Override
    public Iterable<String> getChildNodeNames() {
        return getTemplate().getChildNodeNames(reader, recordId);
    }

    @Override @Nonnull
    public Iterable<? extends ChildNodeEntry> getChildNodeEntries() {
        return getTemplate().getChildNodeEntries(reader, recordId);
    }

    @Override @Nonnull
    public NodeBuilder builder() {
        return new MemoryNodeBuilder(this);
    }

    public boolean equals(Object object) {
        if (this == object) {
            return true;
        } else if (object instanceof NodeState) {
            if (object instanceof SegmentNodeState) {
                SegmentNodeState that = (SegmentNodeState) object;
                if (recordId.equals(that.recordId)) {
                    return true;
                } else if (!getTemplate().equals(that.getTemplate())) {
                    return false;
                }
            }
            return super.equals(object);
        } else {
            return false;
        }
    }

}
{'fraction_non_alphanumeric': 0.08470736312146004, 'fraction_numerical': 0.0016362492133417243, 'mean_word_length': 3.015159171298636, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6651740', 'n_tokens_mistral': 2086, 'n_tokens_neox': 2021, 'n_words': 592}