class CerberusMetadataLookup {

    public ArrayList<String> searchCerberusMetadata(ArrayList<Map<String, String>> sdbMetadata, String sdbName, String principalName) {

        if (sdbMetadata == null) {
            throw new NullPointerException("SDB Metadata is empty");
        }

        ArrayList<String> owner = new ArrayList<>();

        for (Map<String, String> entry : sdbMetadata) {

            if (entry.get("path").contains(sdbName) && !sdbName.isEmpty()) {
                owner.add(entry.get("owner"));
                if (entry.get("created_by").contains(EMAIL_SYMBOL)) owner.add(entry.get("created_by"));
                if (entry.get("last_updated_by").contains(EMAIL_SYMBOL)
                        && !entry.get("last_updated_by").equals(entry.get("created_by"))) {
                    owner.add(entry.get("last_updated_by"));
                }
                return owner;
            } else {
                if (entry.containsValue(principalName)) {
                    owner.add(entry.get("owner"));
                    if (entry.get("created_by").contains(EMAIL_SYMBOL)) owner.add(entry.get("created_by"));
                    if (entry.get("last_updated_by").contains(EMAIL_SYMBOL)
                            && !entry.get("last_updated_by").equals(entry.get("created_by"))) {
                        owner.add(entry.get("last_updated_by"));
                    }
                    return owner;
                }
            }
        }

        owner.add("No owner found");
        return owner;
    }

}