<commit_before>/*
 * Copyright 2022 interactive instruments GmbH
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
package de.ii.ogcapi.features.geojson.app;

import com.fasterxml.jackson.core.JsonGenerator;
import com.github.azahnen.dagger.annotations.AutoBind;
import de.ii.ogcapi.features.geojson.domain.EncodingAwareContextGeoJson;
import de.ii.ogcapi.features.geojson.domain.FeatureTransformationContextGeoJson;
import de.ii.ogcapi.features.geojson.domain.GeoJsonWriter;
import de.ii.xtraplatform.features.domain.FeatureSchema;
import de.ii.xtraplatform.features.domain.SchemaBase.Type;
import java.io.IOException;
import java.util.Objects;
import java.util.function.Consumer;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author zahnen
 */
@Singleton
@AutoBind
public class GeoJsonWriterProperties implements GeoJsonWriter {

  private static final Logger LOGGER = LoggerFactory.getLogger(GeoJsonWriterProperties.class);

  private boolean currentStarted;

  @Inject
  public GeoJsonWriterProperties() {}

  @Override
  public GeoJsonWriterProperties create() {
    return new GeoJsonWriterProperties();
  }

  @Override
  public int getSortPriority() {
    return 40;
  }

  @Override
  public void onPropertiesEnd(
      EncodingAwareContextGeoJson context, Consumer<EncodingAwareContextGeoJson> next)
      throws IOException {

    if (currentStarted) {
      this.currentStarted = false;

      // end of "properties"
      context.encoding().getJson().writeEndObject();
    }

    next.accept(context);
  }

  @Override<commit_msg>GeoJSON: always write a 'properties' member (#702)<commit_after>/*
 * Copyright 2022 interactive instruments GmbH
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
package de.ii.ogcapi.features.geojson.app;

import com.fasterxml.jackson.core.JsonGenerator;
import com.github.azahnen.dagger.annotations.AutoBind;
import de.ii.ogcapi.features.geojson.domain.EncodingAwareContextGeoJson;
import de.ii.ogcapi.features.geojson.domain.FeatureTransformationContextGeoJson;
import de.ii.ogcapi.features.geojson.domain.GeoJsonWriter;
import de.ii.xtraplatform.features.domain.FeatureSchema;
import de.ii.xtraplatform.features.domain.SchemaBase.Type;
import java.io.IOException;
import java.util.Objects;
import java.util.function.Consumer;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author zahnen
 */
@Singleton
@AutoBind
public class GeoJsonWriterProperties implements GeoJsonWriter {

  private static final Logger LOGGER = LoggerFactory.getLogger(GeoJsonWriterProperties.class);

  private boolean currentStarted;

  @Inject
  public GeoJsonWriterProperties() {}

  @Override
  public GeoJsonWriterProperties create() {
    return new GeoJsonWriterProperties();
  }

  @Override
  public int getSortPriority() {
    return 40;
  }

  @Override
  public void onPropertiesEnd(
      EncodingAwareContextGeoJson context, Consumer<EncodingAwareContextGeoJson> next)
      throws IOException {

    if (currentStarted) {
      this.currentStarted = false;

      // end of "properties"
      context.encoding().getJson().writeEndObject();
    } else {

      // no properties, write null member
      context.encoding().getJson().writeNullField(getPropertiesFieldName());
    }

    next.accept(context);
  }

  @Override
{'fraction_non_alphanumeric': 0.09673097534833869, 'fraction_numerical': 0.007234726688102894, 'mean_word_length': 4.41799709724238, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '4746226', 'n_tokens_mistral': 1164, 'n_tokens_neox': 1094, 'n_words': 260}