com.sap.cloud.mt.subscription.DbIdentifiersSql Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of multi-tenant-subscription Show documentation
Show all versions of multi-tenant-subscription Show documentation
Spring Boot Enablement Parent
/*
* *************************************************************************
* * (C) 2019-2021 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);
}
}