Add TableSchema.getColumnList()
[ovsdb.git] / library / impl / src / main / java / org / opendaylight / ovsdb / lib / schema / TableSchema.java
index e63ecef6b5c815b3a12c7e9e9ec1fb3162e2b796..325815b045851b7dc8ea74e1b3cc295922896aea 100644 (file)
@@ -25,6 +25,7 @@ import org.opendaylight.ovsdb.lib.notation.Column;
 import org.opendaylight.ovsdb.lib.notation.Row;
 import org.opendaylight.ovsdb.lib.notation.UUID;
 import org.opendaylight.ovsdb.lib.operations.Insert;
+import org.opendaylight.yangtools.util.CollectionWrappers;
 
 public abstract class TableSchema<E extends TableSchema<E>> {
     private static final AtomicColumnType UUID_COLUMN_TYPE = new AtomicColumnType(UuidBaseType.SINGLETON);
@@ -34,6 +35,8 @@ public abstract class TableSchema<E extends TableSchema<E>> {
     private final String name;
     private final ImmutableMap<String, ColumnSchema> columns;
 
+    private volatile List<String> columnList;
+
     protected TableSchema(final String name) {
         this(name, ImmutableMap.of());
     }
@@ -47,6 +50,19 @@ public abstract class TableSchema<E extends TableSchema<E>> {
         return columns.keySet();
     }
 
+    public List<String> getColumnList() {
+        final List<String> local = columnList;
+        return local != null ? local : populateColumnList();
+    }
+
+    private synchronized List<String> populateColumnList() {
+        List<String> local = columnList;
+        if (local == null) {
+            columnList = local = CollectionWrappers.wrapAsList(columns.keySet());
+        }
+        return local;
+    }
+
     public Map<String, ColumnSchema> getColumnSchemas() {
         return columns;
     }