<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.jena.sparql.util;

import static java.util.Objects.requireNonNull;
import static org.apache.jena.atlas.iterator.Iter.count;
import static org.apache.jena.atlas.iterator.Iter.map;
import static org.apache.jena.ext.com.google.common.collect.Iterators.concat;
import static org.apache.jena.graph.Node.ANY;
import static org.apache.jena.query.ReadWrite.READ;
import static org.apache.jena.sparql.core.Quad.defaultGraphIRI;
import static org.apache.jena.sparql.util.graph.GraphUtils.triples2quads;

import java.util.Iterator;

import org.apache.jena.atlas.lib.PairOfSameType;
import org.apache.jena.graph.Graph;
import org.apache.jena.graph.Node;
import org.apache.jena.graph.compose.MultiUnion;
import org.apache.jena.query.ReadWrite;
import org.apache.jena.query.TxnType;
import org.apache.jena.shared.Lock;
import org.apache.jena.sparql.core.DatasetGraph;
import org.apache.jena.sparql.core.Quad;

public abstract class DyadicDatasetGraph extends PairOfSameType<DatasetGraph> implements DatasetGraph {

    private Context context;

    private final Lock lock;

    protected DyadicDatasetGraph(DatasetGraph left, DatasetGraph right, Context c) {
        super(requireNonNull(left), requireNonNull(right));
        this.context = requireNonNull(c);
        this.lock = new PairLock(left.getLock(), right.getLock());
    }

    protected static void throwNoMutationAllowed() {
        throw new UnsupportedOperationException("This view does not allow mutation!");
    }

    @Override
    public void commit() {
        throwNoMutationAllowed();
    }

    @Override
    public void begin(TxnType type) {
        switch (type) {
        case WRITE:
            throwNoMutationAllowed();
        default:
            forEach(dsg -> dsg.begin(type));
        }
    }

    @Override
    public boolean promote() {
        return false;
    }

    @Override
    public ReadWrite transactionMode() {
        return apply((rw1, rw2) -> rw1 == rw2 ? rw1 : null, DatasetGraph::transactionMode);
    }

    @Override
    public TxnType transactionType() {
        return apply((t1, t2) -> t1 == t2 ? t1 : null, DatasetGraph::transactionType);
    }

    @Override
    public synchronized void begin(ReadWrite readWrite) {
        switch (readWrite) {
        case WRITE:
            throwNoMutationAllowed();
        case READ:
            forEach(dsg -> dsg.begin(READ));
        }
    }

    @Override
    public void abort() {
        forEach(DatasetGraph::abort);
    }

    @Override
    public void end() {
        forEach(DatasetGraph::end);
    }

    @Override
    public boolean isInTransaction() {
        return either(DatasetGraph::isInTransaction);
    }

    @Override
    public void setDefaultGraph(Graph g) {
        throwNoMutationAllowed();
    }

    @Override
    public void addGraph(Node graphName, Graph graph) {
        throwNoMutationAllowed();
    }

    @Override
    public void removeGraph(Node graphName) {<commit_msg>Use TxnType::convert facility<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.jena.sparql.util;

import static java.util.Objects.requireNonNull;
import static org.apache.jena.atlas.iterator.Iter.count;
import static org.apache.jena.atlas.iterator.Iter.map;
import static org.apache.jena.ext.com.google.common.collect.Iterators.concat;
import static org.apache.jena.graph.Node.ANY;
import static org.apache.jena.query.TxnType.READ;
import static org.apache.jena.sparql.core.Quad.defaultGraphIRI;
import static org.apache.jena.sparql.util.graph.GraphUtils.triples2quads;

import java.util.Iterator;

import org.apache.jena.atlas.lib.PairOfSameType;
import org.apache.jena.graph.Graph;
import org.apache.jena.graph.Node;
import org.apache.jena.graph.compose.MultiUnion;
import org.apache.jena.query.ReadWrite;
import org.apache.jena.query.TxnType;
import org.apache.jena.shared.Lock;
import org.apache.jena.sparql.core.DatasetGraph;
import org.apache.jena.sparql.core.Quad;

public abstract class DyadicDatasetGraph extends PairOfSameType<DatasetGraph> implements DatasetGraph {

    private Context context;

    private final Lock lock;

    protected DyadicDatasetGraph(DatasetGraph left, DatasetGraph right, Context c) {
        super(requireNonNull(left), requireNonNull(right));
        this.context = requireNonNull(c);
        this.lock = new PairLock(left.getLock(), right.getLock());
    }

    protected static void throwNoMutationAllowed() {
        throw new UnsupportedOperationException("This view does not allow mutation!");
    }

    @Override
    public void commit() {
        throwNoMutationAllowed();
    }

    @Override
    public void begin(TxnType type) {
        switch (type) {
        case READ:
            forEach(dsg -> dsg.begin(type));
            break;
        default:
            throwNoMutationAllowed();
        }
    }

    @Override
    public boolean promote() {
        // no mutation allowed
        return false;
    }

    @Override
    public ReadWrite transactionMode() {
        return TxnType.convert(transactionType());
    }

    @Override
    public TxnType transactionType() {
        return both(dsg -> dsg.transactionType() == READ) ? READ : null;
    }

    @Override
    public synchronized void begin(ReadWrite readWrite) {
        begin(TxnType.convert(readWrite));
    }

    @Override
    public void abort() {
        forEach(DatasetGraph::abort);
    }

    @Override
    public void end() {
        forEach(DatasetGraph::end);
    }

    @Override
    public boolean isInTransaction() {
        return either(DatasetGraph::isInTransaction);
    }

    @Override
    public void setDefaultGraph(Graph g) {
        throwNoMutationAllowed();
    }

    @Override
    public void addGraph(Node graphName, Graph graph) {
        throwNoMutationAllowed();
    }

    @Override
    public void removeGraph(Node graphName) {
{'fraction_non_alphanumeric': 0.0934228187919463, 'fraction_numerical': 0.0026845637583892616, 'mean_word_length': 3.2311186825667235, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '2372573', 'n_tokens_mistral': 2138, 'n_tokens_neox': 2122, 'n_words': 588}