com.squarespace.template.PredicateTable Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of template-core Show documentation
Show all versions of template-core Show documentation
Squarespace template compiler
/**
* Copyright (c) 2014 SQUARESPACE, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.squarespace.template;
import java.util.ArrayList;
import java.util.List;
/**
* Symbol table holding all active predicates. Uses reflection to discover and
* statically register predicate instances by container class, since they are numerous.
*/
public class PredicateTable extends SymbolTable {
private static final int NUM_BUCKETS = 128;
private final List symbolList = new ArrayList<>();
public PredicateTable() {
super(NUM_BUCKETS);
}
public PredicateTable(int numBuckets) {
super(numBuckets);
}
public String[] getSymbols() {
return symbolList.toArray(Constants.EMPTY_ARRAY_OF_STRING);
}
public void register(PredicateRegistry registry) {
registry.registerPredicates(this);
}
/**
* Store the Predicate in the symbol table.
*/
@Override
public void add(Predicate predicate) {
put(new StringView(predicate.identifier()), predicate);
symbolList.add(predicate.identifier());
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy