All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.networknt.oas.jsonoverlay.SerializationOptions Maven / Gradle / Ivy

There is a newer version: 2.1.38
Show newest version
/*******************************************************************************
 *  Copyright (c) 2017 ModelSolv, Inc. and others.
 *  All rights reserved. This program and the accompanying materials
 *  are made available under the terms of the Eclipse Public License v1.0
 *  which accompanies this distribution, and is available at
 *  http://www.eclipse.org/legal/epl-v10.html
 *
 *  Contributors:
 *     ModelSolv, Inc. - initial API and implementation and/or initial documentation
 *******************************************************************************/
package com.networknt.oas.jsonoverlay;

import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

public class SerializationOptions {
	public enum Option {
		KEEP_EMPTY, KEEP_ONE_EMPTY, FOLLOW_REFS;
	}

	private final Set options;

	public SerializationOptions(SerializationOptions.Option... options) {
		this.options = new HashSet<>();
		for(int i = 0; i < options.length; i++) {
			this.options.add(options[i]);
		}
	}

	public SerializationOptions(Collection options) {
		this.options = new HashSet<>(options);
	}

	public SerializationOptions plus(Collection addOptions) {
		Set newOptions = new HashSet<>(this.options);
		newOptions.addAll(addOptions);
		return new SerializationOptions(newOptions);
	}

	public SerializationOptions plus(SerializationOptions.Option... addOptions) {
		return plus(Arrays.asList(addOptions));
	}

	public SerializationOptions minus(Collection removeOptions) {
		Set newOptions = new HashSet<>(this.options);
		newOptions.removeAll(removeOptions);
		return new SerializationOptions(newOptions);
	}

	public SerializationOptions minus(SerializationOptions.Option... removeOptions) {
		return minus(Arrays.asList(removeOptions));
	}

	public boolean isKeepEmpty() {
		return options.contains(Option.KEEP_EMPTY);
	}

	public boolean isKeepOneEmpty() {
		return options.contains(Option.KEEP_ONE_EMPTY);
	}

	public boolean isKeepThisEmpty() {
		return isKeepEmpty() || isKeepOneEmpty();
	}

	public boolean isFollowRefs() {
		return options.contains(Option.FOLLOW_REFS);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy