001package org.itsallcode.jdbc.identifier; 002 003import static java.util.Arrays.asList; 004import static java.util.stream.Collectors.joining; 005 006import java.util.List; 007 008/** 009 * A qualified identifier, e.g. table name and schema name. 010 * 011 * @param id list of identifiers 012 */ 013public record QualifiedIdentifier(List<Identifier> id) implements Identifier { 014 015 /** 016 * Create a new qualified identifier. 017 * 018 * @param ids the IDs 019 * @return a new instance 020 */ 021 @SuppressWarnings("java:S923") // Varargs required 022 public static Identifier of(final Identifier... ids) { 023 return new QualifiedIdentifier(asList(ids)); 024 } 025 026 /** 027 * Create a new qualified identifier. 028 * 029 * @param ids the simple IDs 030 * @return a new instance 031 */ 032 @SuppressWarnings("java:S923") // Varargs required 033 public static Identifier of(final String... ids) { 034 return of(asList(ids).stream().map(Identifier::simple).toArray(Identifier[]::new)); 035 } 036 037 @Override 038 public String toString() { 039 return quote(); 040 } 041 042 @Override 043 public String quote() { 044 return id.stream().map(Identifier::quote).collect(joining(".")); 045 } 046}