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

com.sap.cloud.mt.subscription.DbIdentifiersSql Maven / Gradle / Ivy

There is a newer version: 3.3.1
Show newest version
/*******************************************************************************
 *   © 2019-2024 SAP SE or an SAP affiliate company. All rights reserved.
 ******************************************************************************/

package com.sap.cloud.mt.subscription;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;

public class DbIdentifiersSql implements DbIdentifiers {
	private final List credentials;

	public DbIdentifiersSql(List credentials) {
		this.credentials = credentials;
	}

	public DbIdentifiersSql(DbIdentifiersSql dbIdentifiersSql) {
		credentials = new ArrayList<>();
		dbIdentifiersSql.credentials.stream().forEach(c -> credentials.add(c.createCopy()));
	}

	@Override
	public boolean areSet() {
		return credentials != null && !credentials.isEmpty();
	}

	@Override
	public DB getDB() {
		if (!credentials.isEmpty()) {
			return credentials.get(0).getDB();
		} else {
			return DB.NONE;
		}
	}

	public Optional getCredentials(String databaseId) {
		return credentials.stream().filter(c -> c.getDatabaseId().equals(databaseId)).findFirst();
	}

	public Optional getLast() {
		if (credentials == null || credentials.isEmpty()) {
			return Optional.empty();
		} else {
			return Optional.of(credentials.get(credentials.size() - 1));
		}
	}

	public Stream asStream() {
		return credentials.stream();
	}

	@Override
	public DbIdentifiers createCopy() {
		return new DbIdentifiersSql(this);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy