<commit_before>/**
 * Copyright 2015 DiffPlug
 *
 * 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 com.diffplug.common.rx;

import java.util.function.Consumer;

import rx.Observable;
import rx.subjects.BehaviorSubject;

import com.google.common.base.Preconditions;

import com.diffplug.common.base.GetterSetter;

/**
 * RxGetter<T> and GetterSetter<T> combined in one.
 */
public interface RxValue<T> extends RxGetter<T>, GetterSetter<T> {
	/** Returns a read-only version of this RxValue. */
	default RxGetter<T> readOnly() {
		return this;
	}

	/** Creates an RxValue with the given initial value. */
	public static <T> RxValue<T> of(T initial) {
		return new Default<T>(initial);
	}

	/** Creates an RxValue which implements the "getter" part with RxGetter, and the setter part with the given Consumer. */
	public static <T> RxValue<T> of(RxGetter<T> getter, Consumer<T> setter) {
		return new RxValue<T>() {
			@Override
			public Observable<T> asObservable() {
				return getter.asObservable();
			}

			@Override
			public T get() {
				return getter.get();
			}

			@Override
			public void set(T value) {
				setter.accept(value);
			}
		};
	}

	/** The default implementation of an RxValue. */
	public static class Default<T> implements RxValue<T> {
		private volatile T value;
		private final BehaviorSubject<T> subject;

		/** Creates a Holder which holds the given value. */
		protected Default(T initial) {
			this(initial, BehaviorSubject.create(initial));
		}

		/** The constructor for implementing these selection models. */
		private Default(T initial, BehaviorSubject<T> subject) {
			this.value = initial;
			this.subject = subject;
		}

		/** Sets the value. */
		@Override
		public void set(T newValue) {
			Preconditions.checkNotNull(newValue);
			if (!value.equals(newValue)) {
				value = newValue;
				subject.onNext(newValue);
			}
		}

		/** Returns the value. */
		@Override
		public T get() {
			return value;
		}

		@Override
		public Observable<T> asObservable() {
			return subject;
		}
	}
}
<commit_msg>RxValue.Default was missing a null-check.<commit_after>/**
 * Copyright 2015 DiffPlug
 *
 * 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 com.diffplug.common.rx;

import java.util.Objects;
import java.util.function.Consumer;

import rx.Observable;
import rx.subjects.BehaviorSubject;

import com.google.common.base.Preconditions;

import com.diffplug.common.base.GetterSetter;

/**
 * RxGetter<T> and GetterSetter<T> combined in one.
 */
public interface RxValue<T> extends RxGetter<T>, GetterSetter<T> {
	/** Returns a read-only version of this RxValue. */
	default RxGetter<T> readOnly() {
		return this;
	}

	/** Creates an RxValue with the given initial value. */
	public static <T> RxValue<T> of(T initial) {
		return new Default<T>(initial);
	}

	/** Creates an RxValue which implements the "getter" part with RxGetter, and the setter part with the given Consumer. */
	public static <T> RxValue<T> of(RxGetter<T> getter, Consumer<T> setter) {
		return new RxValue<T>() {
			@Override
			public Observable<T> asObservable() {
				return getter.asObservable();
			}

			@Override
			public T get() {
				return getter.get();
			}

			@Override
			public void set(T value) {
				setter.accept(value);
			}
		};
	}

	/** The default implementation of an RxValue. */
	public static class Default<T> implements RxValue<T> {
		private volatile T value;
		private final BehaviorSubject<T> subject;

		/** Creates a Holder which holds the given value. */
		protected Default(T initial) {
			this(initial, BehaviorSubject.create(initial));
		}

		/** The constructor for implementing these selection models. */
		private Default(T initial, BehaviorSubject<T> subject) {
			this.value = Objects.requireNonNull(initial);
			this.subject = subject;
		}

		/** Sets the value. */
		@Override
		public void set(T newValue) {
			Preconditions.checkNotNull(newValue);
			if (!value.equals(newValue)) {
				value = newValue;
				subject.onNext(newValue);
			}
		}

		/** Returns the value. */
		@Override
		public T get() {
			return value;
		}

		@Override
		public Observable<T> asObservable() {
			return subject;
		}
	}
}

{'fraction_non_alphanumeric': 0.10971847281141535, 'fraction_numerical': 0.0030852294639413806, 'mean_word_length': 3.5943312666076173, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 43, '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': '397934', 'n_tokens_mistral': 1746, 'n_tokens_neox': 1537, 'n_words': 526}