<commit_before>package io.liveoak.spi.resource;

import java.util.Collection;
import java.util.Map;

import io.liveoak.spi.RequestContext;
import io.liveoak.spi.resource.async.PropertySink;
import io.liveoak.spi.resource.async.Resource;
import io.liveoak.spi.resource.async.ResourceSink;
import io.liveoak.spi.resource.async.Responder;
import io.liveoak.spi.state.ResourceState;

/**
 * @author <NAME>
 */
public interface SynchronousResource extends Resource {

    default Collection<? extends Resource> members(RequestContext ctx) throws Exception {
        return null;
    }

    default Resource member(RequestContext ctx, String id) throws Exception {
        Collection<? extends Resource> members = members(ctx);
        if (members == null) {
            return null;
        }
        for (Resource member: members) {
            if (id.equals(member.id())) {
                return member;
            }
        }
        return null;
    }

    default Map<String, ?> properties(RequestContext ctx) throws Exception {
        return null;
    }

    default void properties(ResourceState props) throws Exception {
        // nothing
    }

    @Override
    default void readMembers(RequestContext ctx, ResourceSink sink) throws Exception {
        try {
            Collection<? extends Resource> members = members(ctx);
            if (members != null) {
                for (Resource each : members) {
                    sink.accept(each);
                }
            }
        } catch (Throwable e) {
            sink.error(e);
        } finally {
            sink.complete();
        }
    }

    @Override
    default void readMember(RequestContext ctx, String id, Responder responder) throws Exception {
        Resource member = member(ctx, id);
        if (member == null) {
            responder.noSuchResource(id);
            return;
        }

        responder.resourceRead(member);
    }

    @Override
    default void readProperties(RequestContext ctx, PropertySink sink) throws Exception {
        Map<String, ?> props = properties(ctx);

        if (props != null) {
            for (Map.Entry<String, ?> entry : props.entrySet() ) {
                sink.accept(entry.getKey(), entry.getValue());
            }
        }

        sink.complete();
    }

    @Override
    default void updateProperties(RequestContext ctx, ResourceState state, Responder responder) throws Exception {
        properties( state );
        responder.resourceUpdated( this );
    }
}
<commit_msg>Add synchronous initProperties() to match properties() for update on SynchronousResource<commit_after>package io.liveoak.spi.resource;

import java.util.Collection;
import java.util.Map;

import io.liveoak.spi.RequestContext;
import io.liveoak.spi.resource.async.PropertySink;
import io.liveoak.spi.resource.async.Resource;
import io.liveoak.spi.resource.async.ResourceSink;
import io.liveoak.spi.resource.async.Responder;
import io.liveoak.spi.state.ResourceState;

/**
 * @author <NAME>
 * @author <NAME>
 */
public interface SynchronousResource extends Resource {

    default Collection<? extends Resource> members(RequestContext ctx) throws Exception {
        return null;
    }

    default Resource member(RequestContext ctx, String id) throws Exception {
        Collection<? extends Resource> members = members(ctx);
        if (members == null) {
            return null;
        }
        for (Resource member : members) {
            if (id.equals(member.id())) {
                return member;
            }
        }
        return null;
    }

    default Map<String, ?> properties(RequestContext ctx) throws Exception {
        return null;
    }

    default void initProperties(ResourceState props) throws Exception {
        // nothing
    }

    default void properties(ResourceState props) throws Exception {
        // nothing
    }

    @Override
    default void readMembers(RequestContext ctx, ResourceSink sink) throws Exception {
        try {
            Collection<? extends Resource> members = members(ctx);
            if (members != null) {
                for (Resource each : members) {
                    sink.accept(each);
                }
            }
        } catch (Throwable e) {
            sink.error(e);
        } finally {
            sink.complete();
        }
    }

    @Override
    default void readMember(RequestContext ctx, String id, Responder responder) throws Exception {
        Resource member = member(ctx, id);
        if (member == null) {
            responder.noSuchResource(id);
            return;
        }

        responder.resourceRead(member);
    }

    @Override
    default void readProperties(RequestContext ctx, PropertySink sink) throws Exception {
        Map<String, ?> props = properties(ctx);

        if (props != null) {
            for (Map.Entry<String, ?> entry : props.entrySet()) {
                sink.accept(entry.getKey(), entry.getValue());
            }
        }

        sink.complete();
    }

    @Override
    default void initializeProperties(RequestContext ctx, ResourceState state, Responder responder) throws Exception {
        initProperties(state);
        responder.resourceUpdated(this);
    }

    @Override
    default void updateProperties(RequestContext ctx, ResourceState state, Responder responder) throws Exception {
        properties(state);
        responder.resourceUpdated(this);
    }
}

{'fraction_non_alphanumeric': 0.09706587931352648, 'fraction_numerical': 0.0, 'mean_word_length': 2.2769044740024182, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3318215', 'n_tokens_mistral': 1408, 'n_tokens_neox': 1385, 'n_words': 359}