本文整理匯總了Java中com.google.common.collect.ImmutableList.Builder.build方法的典型用法代碼示例。如果您正苦於以下問題:Java Builder.build方法的具體用法?Java Builder.build怎麽用?Java Builder.build使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.common.collect.ImmutableList.Builder
的用法示例。
在下文中一共展示了Builder.build方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: readAllNames
import com.google.common.collect.ImmutableList.Builder; //導入方法依賴的package包/類
public static ImmutableList<String> readAllNames(Path path) {
if (path != null) {
Builder<String> namesBuilder = new ImmutableList.Builder<String>();
try (DictionaryReader reader = new DictionaryReader(path);) {
String name = reader.readName();
while (!name.isEmpty()) {
namesBuilder.add(name);
name = reader.readName();
}
} catch (IOException e) {
System.err.println("Unable to create dictionary from file " + path.toString());
}
return namesBuilder.build();
} else {
return ImmutableList.of();
}
}
示例2: convertRequest
import com.google.common.collect.ImmutableList.Builder; //導入方法依賴的package包/類
@Override
public Object convertRequest(ServiceRequestContext ctx, AggregatedHttpMessage request,
Class<?> expectedResultType) throws Exception {
final JsonNode node = (JsonNode) super.convertRequest(ctx, request, JsonNode.class);
if (node.get("changes") != null) {
// have one entry or more than one entry
final JsonNode changeNode = node.get("changes");
final Builder<Change<?>> builder = ImmutableList.builder();
for (JsonNode change : changeNode) {
builder.add(readChange(change));
}
final ImmutableList<Change<?>> changes = builder.build();
checkArgument(!changes.isEmpty(), "should have at least one change.");
return changes;
}
// have only one entry
return ImmutableList.of(readChange(node));
}
示例3: getTaskFilters
import com.google.common.collect.ImmutableList.Builder; //導入方法依賴的package包/類
@SuppressWarnings("nls")
@Override
public List<TaskListSubsearch> getTaskFilters()
{
Builder<TaskListSubsearch> notificationFilters = ImmutableList.builder();
notificationFilters.add(factory.create(NotifcationPortalConstants.ID_ALL, "", false));
notificationFilters.add(factory.create("notewentlive", Notification.REASON_WENTLIVE, true));
notificationFilters.add(factory.create("notewentlive2", Notification.REASON_WENTLIVE2, true));
notificationFilters.add(factory.create("notemylive", Notification.REASON_MYLIVE, true));
notificationFilters.add(factory.create("noterejected", Notification.REASON_REJECTED, true));
notificationFilters.add(factory.create("notebadurl", Notification.REASON_BADURL, true));
notificationFilters.add(factory.create("noteoverdue", Notification.REASON_OVERDUE, true));
notificationFilters.add(factory.create("noteerror", Notification.REASON_SCRIPT_ERROR, true));
notificationFilters.add(factory.create("noteexecuted", Notification.REASON_SCRIPT_EXECUTED, true));
return notificationFilters.build();
}
示例4: testVectorData
import com.google.common.collect.ImmutableList.Builder; //導入方法依賴的package包/類
/**
* Loads a list of tests based on the json-encoded test vector files.
*/
@Parameters(name = "Test Vector {index}: {0}")
public static Collection<TestVector> testVectorData() throws Exception {
final URI baseUri =
ValidVectorTest.class.getResource(ValidVectorTest.class.getSimpleName() + ".class").toURI();
final File baseDirectoryFile = new File(baseUri).getParentFile();
final File validTestVectorDir = new File(baseDirectoryFile, "/vectors/valid");
final Builder<TestVector> vectors = ImmutableList.builder();
final ObjectMapper mapper = new ObjectMapper();
Arrays.stream(validTestVectorDir.listFiles()).forEach(file -> {
try {
if (file.getName().endsWith(".json")) {
TestVector vector = mapper.readValue(file, TestVector.class);
vector.setName(file.getName().substring(0, file.getName().length() - 5));
vectors.add(vector);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
});
return vectors.build();
}
示例5: renameTableStatements
import com.google.common.collect.ImmutableList.Builder; //導入方法依賴的package包/類
/**
* @see org.alfasoftware.morf.jdbc.SqlDialect#renameTableStatements(java.lang.String, java.lang.String)
*/
@Override
public Collection<String> renameTableStatements(Table from, Table to) {
Builder<String> builder = ImmutableList.<String>builder();
if (!primaryKeysForTable(from).isEmpty()) {
builder.add(dropPrimaryKeyConstraintStatement(from));
}
builder.add("ALTER TABLE " + from.getName() + " RENAME TO " + to.getName());
if (!primaryKeysForTable(to).isEmpty()) {
builder.add(addPrimaryKeyConstraintStatement(to, namesOfColumns(primaryKeysForTable(to))));
}
return builder.build();
}
示例6: shouldExecuteParametrisedQuery
import com.google.common.collect.ImmutableList.Builder; //導入方法依賴的package包/類
/**
* Checks if parametrised query execution is working correctly.
*/
@Test
public void shouldExecuteParametrisedQuery() {
SqlScriptExecutor executor = sqlScriptExecutorProvider.get(new LoggingSqlScriptVisitor());
SelectStatement testSelect = select(field("alfaDate1"), field("alfaDate2"), literal(123))
.from(tableRef("DateTable")).where(eq(field("alfaDate1"), parameter("firstDateParam").type(DataType.BIG_INTEGER)));;
Iterable<SqlParameter> parameterMetadata = ImmutableList.of(parameter(column("firstDateParam", DataType.STRING)));
RecordBuilder parameterData = DataSetUtils.record().setString("firstDateParam", "20040609");
ResultSetProcessor<List<List<String>>> resultSetProcessor = new ResultSetProcessor<List<List<String>>>() {
/**
* Takes all rows and puts into two-dimension String array.
*/
@Override
public List<List<String>> process(ResultSet resultSet) throws SQLException {
Builder<List<String>> builder = ImmutableList.<List<String>>builder();
ResultSetMetaData metaData = resultSet.getMetaData();
int columnCount = metaData.getColumnCount();
while (resultSet.next()) {
List<String> rowBuilder = new LinkedList<>();
for (int columnNumber = 1; columnNumber < columnCount + 1; columnNumber++) {
String stringifiezedCell = resultSet.getString(columnNumber);
rowBuilder.add(stringifiezedCell);
}
builder.add(rowBuilder);
}
return builder.build();
}
};
List<List<String>> result = executor.executeQuery(testSelect, parameterMetadata, parameterData, connection, resultSetProcessor);
assertEquals(ImmutableList.of(ImmutableList.of("20040609","20040813", "123"), ImmutableList.of("20040609","20040609", "123") , ImmutableList.of("20040609","20040610", "123")), result);
}
示例7: renameTableStatements
import com.google.common.collect.ImmutableList.Builder; //導入方法依賴的package包/類
/**
* @see org.alfasoftware.morf.jdbc.SqlDialect#renameTableStatements(java.lang.String, java.lang.String)
*/
@Override
public Collection<String> renameTableStatements(Table from, Table to) {
Builder<String> builder = ImmutableList.<String>builder();
if (!primaryKeysForTable(from).isEmpty()) {
builder.add(dropPrimaryKeyConstraintStatement(from));
}
builder.add("ALTER TABLE " + qualifiedTableName(from) + " RENAME TO " + qualifiedTableName(to));
if (!primaryKeysForTable(to).isEmpty()) {
builder.add(addPrimaryKeyConstraintStatement(to, namesOfColumns(primaryKeysForTable(to))));
}
return builder.build();
}
示例8: keywordPairs
import com.google.common.collect.ImmutableList.Builder; //導入方法依賴的package包/類
@Override
public List<Pair<ISemanticRegion, ISemanticRegion>> keywordPairs(Keyword kw1, Keyword kw2) {
Preconditions.checkNotNull(kw1);
Preconditions.checkNotNull(kw2);
Preconditions.checkArgument(kw1 != kw2);
Predicate<ISemanticRegion> p1 = createPredicate(kw1);
Predicate<ISemanticRegion> p2 = createPredicate(kw2);
List<ISemanticRegion> all = findAll(Predicates.or(p1, p2));
Builder<Pair<ISemanticRegion, ISemanticRegion>> result = ImmutableList.builder();
LinkedList<ISemanticRegion> stack = new LinkedList<ISemanticRegion>();
for (ISemanticRegion region : all) {
if (p1.apply(region))
stack.push(region);
else if (!stack.isEmpty())
result.add(Pair.of(stack.pop(), region));
}
return result.build();
}
示例9: collectMappings
import com.google.common.collect.ImmutableList.Builder; //導入方法依賴的package包/類
private static Collection<SearchMapping> collectMappings(final Map<String, SearchMappings> searchMappings) {
final Builder<SearchMapping> builder = ImmutableList.builder();
// put the default mappings in first
final SearchMappings defaultMappings = searchMappings.get(DEFAULT);
if (defaultMappings != null) {
builder.addAll(defaultMappings.get());
}
// add the rest of the mappings
searchMappings.keySet().stream()
.filter(key -> !DEFAULT.equals(key))
.sorted()
.forEach(key -> builder.addAll(searchMappings.get(key).get()));
return builder.build();
}
示例10: generateCoveredPaths
import com.google.common.collect.ImmutableList.Builder; //導入方法依賴的package包/類
/**
* Generate the covered paths, reducing to the lowest depth.
*
* @param structureHierarchy
* the structure hierarchy
* @param coveredStructures
* the covered structures
* @param depth
* the maximum depth
* @return list of paths for the covered structures
*/
private List<String> generateCoveredPaths(ItemHierarchy<Structure> structureHierarchy,
List<Structure> coveredStructures, int depth) {
LinkedHashSet<String> collect = coveredStructures.stream()
.map(s -> structureHierarchy.getSelectorPath(s).toDepth(depth).toString())
.collect(Collectors.toCollection(LinkedHashSet::new));
Builder<String> builder = ImmutableList.<String>builder();
String parent = collect.iterator().next();
builder.add(parent);
for (String path : collect) {
if (!path.startsWith(parent)) {
builder.add(path);
parent = path;
}
}
return builder.build();
}
示例11: dirList
import com.google.common.collect.ImmutableList.Builder; //導入方法依賴的package包/類
public static List<String> dirList(String path){
Builder<String> builder = ImmutableList.builder();
File folder = new File(path);
File[] files = folder.listFiles();
if(files == null) {
throw new NullPointerException();
}
for (File entry : files) {
if (entry.isFile()) {
builder.add("File : " + entry.getName());
} else if (entry.isDirectory()) {
builder.add("Directory : " + entry.getName());
}
}
return builder.build();
}
示例12: modelToList
import com.google.common.collect.ImmutableList.Builder; //導入方法依賴的package包/類
@Override
protected ImmutableList<ValueAssignment> modelToList() {
Builder<ValueAssignment> out = ImmutableList.builder();
// Iterate through constants.
for (int constIdx = 0; constIdx < Native.modelGetNumConsts(z3context, model); constIdx++) {
long keyDecl = Native.modelGetConstDecl(z3context, model, constIdx);
Native.incRef(z3context, keyDecl);
out.addAll(getConstAssignments(keyDecl));
Native.decRef(z3context, keyDecl);
}
// Iterate through function applications.
for (int funcIdx = 0; funcIdx < Native.modelGetNumFuncs(z3context, model); funcIdx++) {
long funcDecl = Native.modelGetFuncDecl(z3context, model, funcIdx);
Native.incRef(z3context, funcDecl);
if (!isInternalSymbol(funcDecl)) {
String functionName = z3creator.symbolToString(Native.getDeclName(z3context, funcDecl));
out.addAll(getFunctionAssignments(funcDecl, funcDecl, functionName));
}
Native.decRef(z3context, funcDecl);
}
return out.build();
}
示例13: read
import com.google.common.collect.ImmutableList.Builder; //導入方法依賴的package包/類
@NonNull
private List<Definition> read(@NonNull BitBuffer input, IDefinitionScope definitionScope, String fieldName) throws CTFReaderException {
Builder<Definition> definitions = new ImmutableList.Builder<>();
if (!fChildrenNames.containsKey(fieldName)) {
for (int i = 0; i < fLength; i++) {
fChildrenNames.put(fieldName, fieldName + '[' + i + ']');
}
}
List<String> elemNames = (List<String>) fChildrenNames.get(fieldName);
for (int i = 0; i < fLength; i++) {
String name = elemNames.get(i);
if (name == null) {
throw new IllegalStateException();
}
definitions.add(fElemType.createDefinition(definitionScope, name, input));
}
@SuppressWarnings("null")
@NonNull ImmutableList<Definition> ret = definitions.build();
return ret;
}
示例14: params
import com.google.common.collect.ImmutableList.Builder; //導入方法依賴的package包/類
@Override
public List<String> params(final String name) {
Builder<String> builder = ImmutableList.builder();
// query params
Deque<String> query = exchange.getQueryParameters().get(name);
if (query != null) {
query.stream().forEach(builder::add);
}
// form params
Optional.ofNullable(parseForm().get(name)).ifPresent(values -> {
values.stream().forEach(value -> {
if (!value.isFile()) {
builder.add(value.getValue());
}
});
});
return builder.build();
}
示例15: getBucketCds
import com.google.common.collect.ImmutableList.Builder; //導入方法依賴的package包/類
private ImmutableList<ResolvedCdsTrade> getBucketCds(ResolvedCds product, CreditRatesProvider ratesProvider) {
CreditDiscountFactors creditCurve =
ratesProvider.survivalProbabilities(product.getLegalEntityId(), product.getCurrency()).getSurvivalProbabilities();
int nNodes = creditCurve.getParameterCount();
Builder<ResolvedCdsTrade> builder = ImmutableList.builder();
for (int i = 0; i < nNodes; ++i) {
ParameterMetadata metadata = creditCurve.getParameterMetadata(i);
ArgChecker.isTrue(metadata instanceof ResolvedTradeParameterMetadata,
"ParameterMetadata of credit curve must be ResolvedTradeParameterMetadata");
ResolvedTradeParameterMetadata tradeMetadata = (ResolvedTradeParameterMetadata) metadata;
ResolvedTrade trade = tradeMetadata.getTrade();
ArgChecker.isTrue(trade instanceof ResolvedCdsTrade, "ResolvedTrade must be ResolvedCdsTrade");
builder.add((ResolvedCdsTrade) trade);
}
return builder.build();
}