Java Code Examples for java.util.List#set()
The following examples show how to use
java.util.List#set() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClassPathLoader.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * Get a copy of the collection of ClassLoaders currently in use. * * @return Collection of ClassLoaders currently in use. */ public Collection<ClassLoader> getClassLoaders() { List<ClassLoader> classLoadersCopy = new ArrayList<ClassLoader>(this.classLoaders); for (int i = 0; i < classLoadersCopy.size(); i++) { if (classLoadersCopy.get(i).equals(TCCL_PLACEHOLDER)) { if (excludeTCCL) { classLoadersCopy.remove(i); } else { classLoadersCopy.set(i, Thread.currentThread().getContextClassLoader()); } break; } } return classLoadersCopy; }
Example 2
Source File: PickaxeOfContainment.java From Slimefun4 with GNU General Public License v3.0 | 6 votes |
private ItemStack breakSpawner(Block b) { // If the spawner's BlockStorage has BlockInfo, then it's not a vanilla spawner and // should not give a broken spawner. ItemStack spawner = SlimefunItems.BROKEN_SPAWNER.clone(); if (BlockStorage.hasBlockInfo(b)) { spawner = SlimefunItems.REPAIRED_SPAWNER.clone(); } ItemMeta im = spawner.getItemMeta(); List<String> lore = im.getLore(); for (int i = 0; i < lore.size(); i++) { if (lore.get(i).contains("<Type>")) { lore.set(i, lore.get(i).replace("<Type>", ChatUtils.humanize(((CreatureSpawner) b.getState()).getSpawnedType().toString()))); } } im.setLore(lore); spawner.setItemMeta(im); return spawner; }
Example 3
Source File: RexSimplify.java From Bats with Apache License 2.0 | 6 votes |
/** Simplifies a list of terms and combines them into an OR. * Modifies the list in place. */ private RexNode simplifyOrs(List<RexNode> terms, RexUnknownAs unknownAs) { for (int i = 0; i < terms.size(); i++) { final RexNode term = terms.get(i); switch (term.getKind()) { case LITERAL: if (RexLiteral.isNullLiteral(term)) { if (unknownAs == FALSE) { terms.remove(i); --i; continue; } } else { if (RexLiteral.booleanValue(term)) { return term; // true } else { terms.remove(i); --i; continue; } } } terms.set(i, term); } return RexUtil.composeDisjunction(rexBuilder, terms); }
Example 4
Source File: InsertMethodArgument.java From rewrite with Apache License 2.0 | 6 votes |
@Override public J visitMethodInvocation(J.MethodInvocation method) { if (isScope()) { List<Expression> modifiedArgs = method.getArgs().getArgs().stream() .filter(a -> !(a instanceof J.Empty)) .collect(Collectors.toCollection(ArrayList::new)); modifiedArgs.add(pos, new J.UnparsedSource(randomId(), source, pos == 0 ? modifiedArgs.stream().findFirst().map(Tree::getFormatting).orElse(Formatting.EMPTY) : format(" ") ) ); if (pos == 0 && modifiedArgs.size() > 1) { // this argument previously did not occur after a comma, and now does, so let's introduce a bit of space modifiedArgs.set(1, modifiedArgs.get(1).withFormatting(format(" "))); } return method.withArgs(method.getArgs().withArgs(modifiedArgs)); } return super.visitMethodInvocation(method); }
Example 5
Source File: PageXmlUtils.java From TranskribusCore with GNU General Public License v3.0 | 6 votes |
private static void setTextRegion(String regId, PcGtsType pc, TextRegionType region) { if(regId == null){ throw new IllegalArgumentException("RegId is null!"); } if(!hasRegions(pc)){ throw new IllegalArgumentException("PAGE XML has no regions!"); } List<TrpRegionType> regions = pc.getPage().getTextRegionOrImageRegionOrLineDrawingRegion(); for(int i = 0; i < regions.size(); i++){ final String id = regions.get(i).getId(); if(id != null && id.equals(regId)){ logger.debug("Setting new TextRegion in PAGE region at index=" + i); regions.set(i, region); return; } } logger.error("The region to replace (ID=" + regId + ") could not be found!"); }
Example 6
Source File: RexShuttle.java From calcite with Apache License 2.0 | 5 votes |
/** * Applies this shuttle to each expression in a list. * * @return whether any of the expressions changed */ public final <T extends RexNode> boolean mutate(List<T> exprList) { int changeCount = 0; for (int i = 0; i < exprList.size(); i++) { T expr = exprList.get(i); T expr2 = (T) apply(expr); // Avoid NPE if expr is null if (expr != expr2) { ++changeCount; exprList.set(i, expr2); } } return changeCount > 0; }
Example 7
Source File: ModificationAwareListTest.java From osmapi with GNU Lesser General Public License v3.0 | 5 votes |
private void checkModificationOnSet(List<String> l) { l.set(0,"a"); assertFalse(list.isModified()); l.set(0,"c"); assertTrue(list.isModified()); }
Example 8
Source File: BlockStoragePolicy.java From hadoop with Apache License 2.0 | 5 votes |
/** * Choose the storage types for storing the remaining replicas, given the * replication number, the storage types of the chosen replicas and * the unavailable storage types. It uses fallback storage in case that * the desired storage type is unavailable. * * @param replication the replication number. * @param chosen the storage types of the chosen replicas. * @param unavailables the unavailable storage types. * @param isNewBlock Is it for new block creation? * @return a list of {@link StorageType}s for storing the replicas of a block. */ public List<StorageType> chooseStorageTypes(final short replication, final Iterable<StorageType> chosen, final EnumSet<StorageType> unavailables, final boolean isNewBlock) { final List<StorageType> excess = new LinkedList<StorageType>(); final List<StorageType> storageTypes = chooseStorageTypes( replication, chosen, excess); final int expectedSize = storageTypes.size() - excess.size(); final List<StorageType> removed = new LinkedList<StorageType>(); for(int i = storageTypes.size() - 1; i >= 0; i--) { // replace/remove unavailable storage types. final StorageType t = storageTypes.get(i); if (unavailables.contains(t)) { final StorageType fallback = isNewBlock? getCreationFallback(unavailables) : getReplicationFallback(unavailables); if (fallback == null) { removed.add(storageTypes.remove(i)); } else { storageTypes.set(i, fallback); } } } // remove excess storage types after fallback replacement. diff(storageTypes, excess, null); if (storageTypes.size() < expectedSize) { LOG.warn("Failed to place enough replicas: expected size is " + expectedSize + " but only " + storageTypes.size() + " storage types can be selected " + "(replication=" + replication + ", selected=" + storageTypes + ", unavailable=" + unavailables + ", removed=" + removed + ", policy=" + this + ")"); } return storageTypes; }
Example 9
Source File: TCastsRegistry.java From sql-layer with GNU Affero General Public License v3.0 | 5 votes |
private static void checkDag(final Map<TClass, Map<TClass, TCast>> castsBySource) { DagChecker<TClass> checker = new DagChecker<TClass>() { @Override protected Set<? extends TClass> initialNodes() { return castsBySource.keySet(); } @Override protected Set<? extends TClass> nodesFrom(TClass starting) { Set<TClass> result = new HashSet<>(castsBySource.get(starting).keySet()); result.remove(starting); return result; } }; if (!checker.isDag()) { List<TClass> badPath = checker.getBadNodePath(); // create a List<String> where everything is lowercase except for the first and last instances // of the offending node List<String> names = new ArrayList<>(badPath.size()); for (TClass tClass : badPath) names.add(tClass.toString().toLowerCase()); String lastName = names.get(names.size() - 1); String lastNameUpper = lastName.toUpperCase(); names.set(names.size() - 1, lastNameUpper); names.set(names.indexOf(lastName), lastNameUpper); throw new AkibanInternalException("non-DAG detected involving " + names); } }
Example 10
Source File: AbstractExporter.java From Design-Patterns-and-SOLID-Principles-with-Java with MIT License | 5 votes |
protected List<Integer> calcWidths(Report report) { List<Integer> widths = new ArrayList<>(); report.getLabels().forEach(l -> widths.add(l.length())); for (List<String> record : report.getRecords()) { for (int i = 0; i < widths.size(); i++) { int maxWidth = widths.get(i); int width = record.get(i).length(); if (width > maxWidth) { widths.set(i, width); } } } return widths; }
Example 11
Source File: TabModel.java From rest-client with Apache License 2.0 | 5 votes |
public void setValueAt(Object value, int row, int col) { List<Object> rowLst = this.getRow(row); if (CollectionUtils.isEmpty(rowLst)) { return; } rowLst.set(col, value); fireTableCellUpdated(row, col); }
Example 12
Source File: ProtectedNiFiRegistryProperties.java From nifi-registry with Apache License 2.0 | 5 votes |
/** * Splits a single string containing multiple property keys into a List. * * Delimited by ',' or ';' and ignores leading and trailing whitespace around delimiter. * * @param multipleProperties a single String containing multiple properties, i.e. * "nifi.registry.property.1; nifi.registry.property.2, nifi.registry.property.3" * @return a List containing the split and trimmed properties */ private static List<String> splitMultipleProperties(String multipleProperties) { if (multipleProperties == null || multipleProperties.trim().isEmpty()) { return new ArrayList<>(0); } else { List<String> properties = new ArrayList<>(asList(multipleProperties.split("\\s*[,;]\\s*"))); for (int i = 0; i < properties.size(); i++) { properties.set(i, properties.get(i).trim()); } return properties; } }
Example 13
Source File: ValidatingTableEditor.java From consulo with Apache License 2.0 | 5 votes |
@Nullable protected Pair<String, Fix> validate(List<Item> current, List<String> warnings) { String error = null; for (int i = 0; i < current.size(); i++) { Item item = current.get(i); String s = validate(item); warnings.set(i, s); if (error == null) { error = s; } } return error != null ? Pair.create(error, (Fix)null) : null; }
Example 14
Source File: LoggedTaskAttempt.java From hadoop with Apache License 2.0 | 4 votes |
public void set(List<List<Integer>> listSplits, List<Integer> newValue) { listSplits.set(this.ordinal(), newValue); }
Example 15
Source File: TestCache.java From reladomo with Apache License 2.0 | 4 votes |
public void xtestDatedPartialCacheSoftReferenceCollection() throws Exception { TinyBalanceDatabaseObject dbo = new TinyBalanceDatabaseObject(); Attribute[] primaryKeyAttributes = TinyBalanceFinder.getPrimaryKeyAttributes(); AsOfAttribute[] asOfAttributes = TinyBalanceFinder.getAsOfAttributes(); PartialDatedCache cache = new PartialDatedCache(primaryKeyAttributes, asOfAttributes, dbo, primaryKeyAttributes, 0, 0); List extractors = new ArrayList(); for(int i=0;i<primaryKeyAttributes.length;i++) { extractors.add(primaryKeyAttributes[i]); } for(int i=0;i<asOfAttributes.length;i++) { extractors.add(asOfAttributes[i]); } int indexRef = cache.getBestIndexReference(extractors).indexReference; List dataExtractors = new ArrayList(extractors); for(int i=0;i<asOfAttributes.length;i++) { dataExtractors.set(primaryKeyAttributes.length + i, asOfAttributes[i].getFromAttribute()); } Extractor[] arrayExtractors = (Extractor[]) dataExtractors.toArray(new Extractor[dataExtractors.size()]); Timestamp jan = new Timestamp(timestampFormat.parse("2003-01-15 00:00:00").getTime()); Timestamp feb = new Timestamp(timestampFormat.parse("2003-02-15 00:00:00").getTime()); Timestamp mar = new Timestamp(timestampFormat.parse("2003-03-15 00:00:00").getTime()); Timestamp in = new Timestamp(0); Timestamp[] asOfDates = new Timestamp[2]; asOfDates[0] = feb; asOfDates[1] = InfinityTimestamp.getParaInfinity(); TinyBalance febBalance = (TinyBalance) cache.getObjectFromData(createTinyBalanceData(1, jan, mar, in), asOfDates); TinyBalanceData forSearch = createTinyBalanceData(1, jan, mar, in); for(int i=0;i<100000000;i++) { if (i % 1000000 == 0) { febBalance = null; } assertNotNull(cache.get(indexRef, forSearch, arrayExtractors, false)); forSearch.setProcessingDateFrom(new Timestamp(i+1)); } }
Example 16
Source File: FisImporter.java From jfuzzylite with GNU General Public License v3.0 | 4 votes |
protected Term createInstance(String mClass, String name, List<String> parameters, Engine engine) { Map<String, String> mapping = new HashMap<String, String>(); mapping.put("gbellmf", Bell.class.getSimpleName()); mapping.put("binarymf", Binary.class.getSimpleName()); mapping.put("concavemf", Concave.class.getSimpleName()); mapping.put("constant", Constant.class.getSimpleName()); mapping.put("cosinemf", Cosine.class.getSimpleName()); mapping.put("function", Function.class.getSimpleName()); mapping.put("discretemf", Discrete.class.getSimpleName()); mapping.put("gaussmf", Gaussian.class.getSimpleName()); mapping.put("gauss2mf", GaussianProduct.class.getSimpleName()); mapping.put("linear", Linear.class.getSimpleName()); mapping.put("pimf", PiShape.class.getSimpleName()); mapping.put("rampmf", Ramp.class.getSimpleName()); mapping.put("rectmf", Rectangle.class.getSimpleName()); mapping.put("smf", SShape.class.getSimpleName()); mapping.put("sigmf", Sigmoid.class.getSimpleName()); mapping.put("dsigmf", SigmoidDifference.class.getSimpleName()); mapping.put("psigmf", SigmoidProduct.class.getSimpleName()); mapping.put("spikemf", Spike.class.getSimpleName()); mapping.put("trapmf", Trapezoid.class.getSimpleName()); mapping.put("trimf", Triangle.class.getSimpleName()); mapping.put("zmf", ZShape.class.getSimpleName()); List<String> sortedParameters = new ArrayList<String>(parameters); if ("gbellmf".equals(mClass) && parameters.size() >= 3) { sortedParameters.set(0, parameters.get(2)); sortedParameters.set(1, parameters.get(0)); sortedParameters.set(2, parameters.get(1)); } else if ("gaussmf".equals(mClass) && parameters.size() >= 2) { sortedParameters.set(0, parameters.get(1)); sortedParameters.set(1, parameters.get(0)); } else if ("gauss2mf".equals(mClass) && parameters.size() >= 4) { sortedParameters.set(0, parameters.get(1)); sortedParameters.set(1, parameters.get(0)); sortedParameters.set(2, parameters.get(3)); sortedParameters.set(3, parameters.get(2)); } else if ("sigmf".equals(mClass) && parameters.size() >= 2) { sortedParameters.set(0, parameters.get(1)); sortedParameters.set(1, parameters.get(0)); } else if ("dsigmf".equals(mClass) && parameters.size() >= 4) { sortedParameters.set(0, parameters.get(1)); sortedParameters.set(1, parameters.get(0)); sortedParameters.set(2, parameters.get(2)); sortedParameters.set(3, parameters.get(3)); } else if ("psigmf".equals(mClass) && parameters.size() >= 4) { sortedParameters.set(0, parameters.get(1)); sortedParameters.set(1, parameters.get(0)); sortedParameters.set(2, parameters.get(2)); sortedParameters.set(3, parameters.get(3)); } String flClass = mapping.get(mClass); if (flClass == null) { flClass = mClass; } Term term = FactoryManager.instance().term().constructObject(flClass); term.updateReference(engine); term.setName(Op.validName(name)); String separator = " "; if (term instanceof Function) { separator = ""; } term.configure(Op.join(sortedParameters, separator)); return term; }
Example 17
Source File: SVMConverter.java From jpmml-r with GNU Affero General Public License v3.0 | 4 votes |
private void scaleFeatures(RExpEncoder encoder){ RGenericVector svm = getObject(); RDoubleVector sv = svm.getDoubleElement("SV"); RBooleanVector scaled = svm.getBooleanElement("scaled"); RGenericVector xScale = svm.getGenericElement("x.scale"); RStringVector rowNames = sv.dimnames(0); RStringVector columnNames = sv.dimnames(1); List<Feature> features = encoder.getFeatures(); if((scaled.size() != columnNames.size()) || (scaled.size() != features.size())){ throw new IllegalArgumentException(); } RDoubleVector xScaledCenter = xScale.getDoubleElement("scaled:center"); RDoubleVector xScaledScale = xScale.getDoubleElement("scaled:scale"); for(int i = 0; i < columnNames.size(); i++){ String columnName = columnNames.getValue(i); if(!scaled.getValue(i)){ continue; } Feature feature = features.get(i); Double center = xScaledCenter.getElement(columnName); Double scale = xScaledScale.getElement(columnName); if(ValueUtil.isZero(center) && ValueUtil.isOne(scale)){ continue; } ContinuousFeature continuousFeature = feature.toContinuousFeature(); Expression expression = continuousFeature.ref(); if(!ValueUtil.isZero(center)){ expression = PMMLUtil.createApply(PMMLFunctions.SUBTRACT, expression, PMMLUtil.createConstant(center)); } // End if if(!ValueUtil.isOne(scale)){ expression = PMMLUtil.createApply(PMMLFunctions.DIVIDE, expression, PMMLUtil.createConstant(scale)); } DerivedField derivedField = encoder.createDerivedField(FeatureUtil.createName("scale", feature), OpType.CONTINUOUS, DataType.DOUBLE, expression); features.set(i, new ContinuousFeature(encoder, derivedField)); } }
Example 18
Source File: ReplacingSymbolVisitor.java From Elasticsearch with Apache License 2.0 | 4 votes |
public void processInplace(List<Symbol> symbols, C context) { for (int i = 0; i < symbols.size(); i++) { symbols.set(i, process(symbols.get(i), context)); } }
Example 19
Source File: ListResource.java From GeometricWeather with GNU Lesser General Public License v3.0 | 4 votes |
public static <T> ListResource<T> changeItem(@NonNull ListResource<T> current, @NonNull T item, int index) { List<T> list = current.dataList; list.set(index, item); return new ListResource<>(list, new ItemChanged(index)); }
Example 20
Source File: SimplifyExprentsHelper.java From JByteMod-Beta with GNU General Public License v2.0 | 4 votes |
private static boolean isConstructorInvocationRemote(List<Exprent> list, int index) { Exprent current = list.get(index); if (current.type == Exprent.EXPRENT_ASSIGNMENT) { AssignmentExprent as = (AssignmentExprent) current; if (as.getLeft().type == Exprent.EXPRENT_VAR && as.getRight().type == Exprent.EXPRENT_NEW) { NewExprent newexpr = (NewExprent) as.getRight(); VarType newtype = newexpr.getNewType(); VarVersionPair leftPaar = new VarVersionPair((VarExprent) as.getLeft()); if (newtype.type == CodeConstants.TYPE_OBJECT && newtype.arrayDim == 0 && newexpr.getConstructor() == null) { for (int i = index + 1; i < list.size(); i++) { Exprent remote = list.get(i); // <init> invocation if (remote.type == Exprent.EXPRENT_INVOCATION) { InvocationExprent in = (InvocationExprent) remote; if (in.getFunctype() == InvocationExprent.TYP_INIT && in.getInstance().type == Exprent.EXPRENT_VAR && as.getLeft().equals(in.getInstance())) { newexpr.setConstructor(in); in.setInstance(null); list.set(i, as.copy()); return true; } } // check for variable in use Set<VarVersionPair> setVars = remote.getAllVariables(); if (setVars.contains(leftPaar)) { // variable used somewhere in between -> exit, need a better reduced code return false; } } } } } return false; }