List of usage examples for com.google.common.collect ImmutableList get
E get(int index);
From source file:org.trnltk.morphology.morphotactics.SuffixFormSequenceApplier.java
public boolean isApplicable(final SuffixFormSequence suffixFormSequence, final Set<PhoneticAttribute> phoneticAttributesOfSurface) { final ImmutableList<SuffixFormSequence.SuffixFormSequenceRule> rules = suffixFormSequence.getRules(); if (CollectionUtils.isEmpty(rules)) return true; // the only case where the suffix form is not applicable is, having two vowels together // following code (unfortunately) assumes, in the suffix form, there are no 2 vowels in a row! final boolean lastSurfaceLetterIsVowel = phoneticAttributesOfSurface .contains(PhoneticAttribute.LastLetterVowel); if (!lastSurfaceLetterIsVowel) return true; final SuffixFormSequence.SuffixFormSequenceRule firstRule = rules.get(0); return !firstRule.getRuleType() .equals(SuffixFormSequence.SuffixFormSequenceRuleType.INSERT_VOWEL_WITHOUT_HARMONY) && !firstRule.getRuleType() .equals(SuffixFormSequence.SuffixFormSequenceRuleType.INSERT_VOWEL_A_WITH_HARMONY) && !firstRule.getRuleType() .equals(SuffixFormSequence.SuffixFormSequenceRuleType.INSERT_VOWEL_I_WITH_HARMONY) && !firstRule.getRuleType().equals( SuffixFormSequence.SuffixFormSequenceRuleType.INSERT_VOWEL_I_WITH_HARMONY_AND_NO_ROUNDING); }
From source file:com.google.googlejavaformat.OpsBuilder.java
/** Return the text of an upcoming {@link Input.Token}, or absent if there is none. */ public final Optional<String> peekToken(int skip) { ImmutableList<? extends Input.Token> tokens = input.getTokens(); int idx = tokenI + skip; return idx < tokens.size() ? Optional.of(tokens.get(idx).getTok().getOriginalText()) : Optional.empty(); }
From source file:org.geogit.geotools.plumbing.ImportOp.java
/** * Translates a feature pointed by a node from its original feature type to a given one, using * values from those attributes that exist in both original and destination feature type. New * attributes are populated with null values * /*from w w w .j av a 2 s. co m*/ * @param node The node that points to the feature. No checking is performed to ensure the node * points to a feature instead of other type * @param featureType the destination feature type * @return a feature with the passed feature type and data taken from the input feature */ private Feature alter(NodeRef node, RevFeatureType featureType) { RevFeature oldFeature = command(RevObjectParse.class).setObjectId(node.objectId()).call(RevFeature.class) .get(); RevFeatureType oldFeatureType; oldFeatureType = command(RevObjectParse.class).setObjectId(node.getMetadataId()).call(RevFeatureType.class) .get(); ImmutableList<PropertyDescriptor> oldAttributes = oldFeatureType.sortedDescriptors(); ImmutableList<PropertyDescriptor> newAttributes = featureType.sortedDescriptors(); ImmutableList<Optional<Object>> oldValues = oldFeature.getValues(); List<Optional<Object>> newValues = Lists.newArrayList(); for (int i = 0; i < newAttributes.size(); i++) { int idx = oldAttributes.indexOf(newAttributes.get(i)); if (idx != -1) { Optional<Object> oldValue = oldValues.get(idx); newValues.add(oldValue); } else { newValues.add(Optional.absent()); } } RevFeature newFeature = RevFeature.build(ImmutableList.copyOf(newValues)); FeatureBuilder featureBuilder = new FeatureBuilder(featureType); Feature feature = featureBuilder.build(node.name(), newFeature); return feature; }
From source file:org.xlrnet.tibaija.commands.math.BinaryCommand.java
/** * Apply the internal function if they both operands are lists and have the same length. Each i-th element of the * left list will be applied to the i-th element of the right list to build the i-th element of the result list. * * @param lhs//from www . j a va 2s . c o m * Left side of the expression * @param rhs * Right side of the expression. * @return A new Value object with the internal function applied to it. */ @NotNull private Value applyOnBothList(@NotNull Value lhs, @NotNull Value rhs) { final ImmutableList<Complex> leftList = lhs.list(); final ImmutableList<Complex> rightList = rhs.list(); if (leftList.size() != rightList.size()) throw new TIArgumentException("Mismatching dimensions: " + leftList.size() + " - " + rightList.size(), lhs, rhs); List<Complex> resultList = new ArrayList<>(leftList.size()); for (int i = 0; i < leftList.size(); i++) resultList .add(evaluationFunction.apply(Value.of(leftList.get(i)), Value.of(rightList.get(i))).complex()); return Value.of(resultList); }
From source file:com.facebook.presto.cli.AlignedTuplePrinter.java
@Override public void printRows(List<List<?>> rows, boolean complete) throws IOException { rowCount += rows.size();/*from ww w.j a v a 2 s. c o m*/ int columns = fieldNames.size(); int[] maxWidth = new int[columns]; for (int i = 0; i < columns; i++) { maxWidth[i] = max(1, fieldNames.get(i).length()); } for (List<?> row : rows) { for (int i = 0; i < row.size(); i++) { String s = formatValue(row.get(i)); maxWidth[i] = max(maxWidth[i], maxLineLength(s)); } } if (!headerOutput) { headerOutput = true; for (int i = 0; i < columns; i++) { if (i > 0) { writer.append('|'); } String name = fieldNames.get(i); writer.append(center(name, maxWidth[i], 1)); } writer.append('\n'); for (int i = 0; i < columns; i++) { if (i > 0) { writer.append('+'); } writer.append(repeat("-", maxWidth[i] + 2)); } writer.append('\n'); } for (List<?> row : rows) { List<List<String>> columnLines = new ArrayList<>(columns); int maxLines = 1; for (int i = 0; i < columns; i++) { String s = formatValue(row.get(i)); ImmutableList<String> lines = ImmutableList.copyOf(LINE_SPLITTER.split(s)); columnLines.add(lines); maxLines = max(maxLines, lines.size()); } for (int line = 0; line < maxLines; line++) { for (int column = 0; column < columns; column++) { if (column > 0) { writer.append('|'); } List<String> lines = columnLines.get(column); String s = (line < lines.size()) ? lines.get(line) : ""; boolean numeric = row.get(column) instanceof Number; String out = align(s, maxWidth[column], 1, numeric); if ((!complete || (rowCount > 1)) && ((line + 1) < lines.size())) { out = out.substring(0, out.length() - 1) + "+"; } writer.append(out); } writer.append('\n'); } } writer.flush(); }
From source file:IO.FilePairer.java
public void pairFiles() { ImmutableList<UnpairedFile> sortedRequests = Ordering.natural().nullsFirst() .onResultOf(new Function<UnpairedFile, String>() { @Override//from w ww . ja v a 2 s . c om public String apply(UnpairedFile unpairedFile) { return unpairedFile.getDescriptor(); } }).immutableSortedCopy(listoffiles); for (int i = 0; i < sortedRequests.size(); i++) { for (int j = i + 1; j < sortedRequests.size(); j++) { UnpairedFile f1 = sortedRequests.get(i); UnpairedFile f2 = sortedRequests.get(j); if (!(f1.isPaired() || f2.isPaired())) { checkForMate(f1, f2); } } } }
From source file:org.geogit.cli.porcelain.Show.java
private void printRaw(GeogitCLI cli) throws IOException { ConsoleReader console = cli.getConsole(); GeoGIT geogit = cli.getGeogit();//w w w . java 2s . co m for (String ref : refs) { Optional<RevObject> obj = geogit.command(RevObjectParse.class).setRefSpec(ref).call(); checkParameter(obj.isPresent(), "refspec did not resolve to any object."); RevObject revObject = obj.get(); if (revObject instanceof RevFeature) { RevFeatureType ft = geogit.command(ResolveFeatureType.class).setRefSpec(ref).call().get(); ImmutableList<PropertyDescriptor> attribs = ft.sortedDescriptors(); RevFeature feature = (RevFeature) revObject; Ansi ansi = super.newAnsi(console.getTerminal()); ansi.a(ref).newline(); ansi.a(feature.getId().toString()).newline(); ImmutableList<Optional<Object>> values = feature.getValues(); int i = 0; for (Optional<Object> value : values) { ansi.a(attribs.get(i).getName()).newline(); ansi.a(value.or("[NULL]").toString()).newline(); i++; } console.println(ansi.toString()); } else { CharSequence s = geogit.command(CatObject.class).setObject(Suppliers.ofInstance(revObject)).call(); console.println(s); } } }
From source file:buildcraft.builders.tile.TileBuilder_Neptune.java
private void setPath(ImmutableList<BlockPos> path) { this.path = path; if (path != null) { int max = path.size() - 1; // Create a list of all the possible block positions on the path that could be used ImmutableList.Builder<BlockPos> interp = ImmutableList.builder(); interp.add(path.get(0)); for (int i = 1; i <= max; i++) { final BlockPos from = path.get(i - 1); final BlockPos to = path.get(i); interp.addAll(PositionUtil.getAllOnPath(from, to)); }// w w w. j ava 2 s .c om pathInterpCache = interp.build(); } else { pathInterpCache = null; } }
From source file:com.google.devtools.build.lib.syntax.BaseFunction.java
protected boolean hasSelfArgument() { Class<?> clazz = getObjectType(); if (clazz == null) { return false; }// w ww . j a va 2s . c om List<SkylarkType> types = signature.getTypes(); ImmutableList<String> names = signature.getSignature().getNames(); return (!types.isEmpty() && types.get(0).canBeCastTo(clazz)) || (!names.isEmpty() && names.get(0).equals("self")); }
From source file:org.apache.drill.exec.store.mapr.db.json.JsonConditionBuilder.java
@Override public JsonScanSpec visitFunctionCall(FunctionCall call, Void value) throws RuntimeException { JsonScanSpec nodeScanSpec = null;//from w w w .j a va 2 s. com String functionName = call.getName(); ImmutableList<LogicalExpression> args = call.args; if (CompareFunctionsProcessor.isCompareFunction(functionName)) { CompareFunctionsProcessor processor = CompareFunctionsProcessor.process(call); if (processor.isSuccess()) { nodeScanSpec = createJsonScanSpec(call, processor); } } else { switch (functionName) { case "booleanAnd": case "booleanOr": nodeScanSpec = args.get(0).accept(this, null); for (int i = 1; i < args.size(); ++i) { JsonScanSpec nextScanSpec = args.get(i).accept(this, null); if (nodeScanSpec != null && nextScanSpec != null) { nodeScanSpec.mergeScanSpec(functionName, nextScanSpec); } else { allExpressionsConverted = false; if ("booleanAnd".equals(functionName)) { nodeScanSpec = nodeScanSpec == null ? nextScanSpec : nodeScanSpec; } } } break; } } if (nodeScanSpec == null) { allExpressionsConverted = false; } return nodeScanSpec; }