Java Code Examples for java.util.ArrayList#subList()
The following examples show how to use
java.util.ArrayList#subList() .
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: HibernateFactory.java From spacewalk with GNU General Public License v2.0 | 6 votes |
/** * Using a named query, find all the objects matching the criteria within. * Warning: This can be very expensive if the returned list is large. Use * only for small tables with static data * @param qryName Named query to use to find a list of objects. * @param qryParams Map of named bind parameters whose keys are Strings. The * map can also be null. * @param col the collection to use as an inclause * @param colLabel the label the collection will have * @return List of objects returned by named query, or null if nothing * found. */ protected List listObjectsByNamedQuery(String qryName, Map qryParams, Collection col, String colLabel) { if (col.isEmpty()) { return Collections.EMPTY_LIST; } ArrayList<Long> tmpList = new ArrayList<Long>(); List<Long> toRet = new ArrayList<Long>(); tmpList.addAll(col); for (int i = 0; i < col.size();) { int initial = i; int fin = i + 500 < col.size() ? i + 500 : col.size(); List<Long> sublist = tmpList.subList(i, fin); qryParams.put(colLabel, sublist); toRet.addAll(listObjectsByNamedQuery(qryName, qryParams, false)); i = fin; } return toRet; }
Example 2
Source File: BigArray.java From consulo with Apache License 2.0 | 6 votes |
@Override public ReadonlyList<T> cut(int idxFromIncluded) { if (idxFromIncluded >= getSize()) return ReadonlyList.EMPTY; final int itemNumber = idxFromIncluded >> mySize2Power; final int insideIdx = idxFromIncluded ^ (itemNumber << mySize2Power); final ArrayList<T> start = myList.get(itemNumber); final NotRegularReadonlyList<T> result = new NotRegularReadonlyList<T>(new ArrayList<ArrayList<T>>(myList.subList(itemNumber + 1, myList.size())), mySize2Power, start.subList(insideIdx, start.size())); myList.set(itemNumber, new ArrayList<T>(start.subList(0, insideIdx))); for (int i = myList.size() - 1; i > itemNumber; -- i) { myList.remove(i); } mySize = myList.isEmpty() ? 0 : (((myList.size() - 1) * myPack + myList.get(myList.size() - 1).size())); return result; }
Example 3
Source File: AverageColorRaster.java From cineast with MIT License | 6 votes |
private List<ScoreElement> getSimilar(float[] raster, float[] hist, ReadableQueryConfig rqc) { int limit = Config.sharedConfig().getRetriever().getMaxResultsPerModule(); QueryConfig qc = new QueryConfig(rqc).setDistanceIfEmpty(Distance.chisquared); List<Map<String, PrimitiveTypeProvider>> rows = this.selector.getNearestNeighbourRows(limit * 5, hist, "hist", qc); ArrayList<ScoreElement> scores = new ArrayList<>(rows.size()); for (Map<String, PrimitiveTypeProvider> map : rows) { String id = map.get("id").getString(); double score = register(raster, map.get("raster").getFloatArray()); scores.add(new SegmentScoreElement(id, score)); } scores.sort(ScoreElement.SCORE_COMPARATOR.reversed()); if (scores.size() > limit) { return scores.subList(0, limit); } else { return scores; } }
Example 4
Source File: PreferenceParser.java From SearchPreference with MIT License | 6 votes |
List<PreferenceItem> searchFor(final String keyword, boolean fuzzy) { if (TextUtils.isEmpty(keyword)) { return new ArrayList<>(); } ArrayList<PreferenceItem> results = new ArrayList<>(); for (PreferenceItem item : allEntries) { if ((fuzzy && item.matchesFuzzy(keyword)) || (!fuzzy && item.matches(keyword))) { results.add(item); } } Collections.sort(results, new Comparator<PreferenceItem>() { @Override public int compare(PreferenceItem i1, PreferenceItem i2) { return floatCompare(i2.getScore(keyword), i1.getScore(keyword)); } }); if (results.size() > MAX_RESULTS) { return results.subList(0, MAX_RESULTS); } else { return results; } }
Example 5
Source File: CTInboxStyleConfig.java From clevertap-android-sdk with MIT License | 6 votes |
/** * Sets the name of the optional two tabs. * The contents of the tabs are filtered based on the name of the tab. * @param tabs ArrayList of Strings */ public void setTabs(ArrayList<String>tabs) { if (tabs == null || tabs.size() <= 0) return; if (platformSupportsTabs) { ArrayList<String> toAdd; if (tabs.size() > MAX_TABS) { toAdd = new ArrayList<>(tabs.subList(0, MAX_TABS)); } else { toAdd = tabs; } this.tabs = toAdd.toArray(new String[0]); } else { Logger.d("Please upgrade com.android.support:design library to v28.0.0 to enable Tabs for App Inbox, dropping Tabs"); } }
Example 6
Source File: ConcordanceSearchDialog.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
private LinkedHashMap<MetaData, List<Integer>> getCurPageMap() { int startIndex = (curPageNum - 1) * rowNumPerPage; int endIndex = curPageNum * rowNumPerPage; if (curPageNum == amountPage) { endIndex = size; } Iterator<Entry<MetaData, ArrayList<Integer>>> it = mapGroupId.entrySet().iterator(); int index = 0; LinkedHashMap<MetaData, List<Integer>> mapSub = new LinkedHashMap<MetaData, List<Integer>>(); while (it.hasNext()) { Entry<MetaData, ArrayList<Integer>> entry = (Entry<MetaData, ArrayList<Integer>>) it.next(); ArrayList<Integer> lstGroupId = entry.getValue(); if (index <= startIndex && index + lstGroupId.size() >= startIndex) { List<Integer> subList = null; if (index + lstGroupId.size() - 1 >= endIndex) { subList = lstGroupId.subList(startIndex - index, endIndex - index); mapSub.put(entry.getKey(), subList); break; } else { subList = lstGroupId.subList(startIndex - index, lstGroupId.size()); index += lstGroupId.size(); startIndex += lstGroupId.size(); mapSub.put(entry.getKey(), subList); } } else { index += lstGroupId.size(); } } return mapSub; }
Example 7
Source File: GrahamScan2D.java From javaGeom with GNU Lesser General Public License v3.0 | 5 votes |
public Polygon2D convexHull(Collection<? extends Point2D> points) { int nbPoints = points.size(); //TODO: manage small values of n // Find point with lowest y-coord Point2D lowestPoint = null; double lowestY = Double.MAX_VALUE; for(Point2D point : points){ double y = point.y(); if(y<lowestY){ lowestPoint = point; lowestY = y; } } // build the comparator, using the lowest point Comparator<Point2D> comparator = new CompareByPseudoAngle(lowestPoint); // create a sorted set ArrayList<Point2D> sorted = new ArrayList<Point2D>(nbPoints); sorted.addAll(points); Collections.sort(sorted, comparator); // main loop // i-> current vertex of point cloud // m-> current hull vertex int m = 2; for(int i=3; i<nbPoints; i++){ while(Point2D.ccw(sorted.get(m), sorted.get(m-1), sorted.get(i))>=0) m--; m++; Collections.swap(sorted, m, i); } // Format result to return a polygon List<Point2D> hull = sorted.subList(0, Math.min(m+1, nbPoints)); return new SimplePolygon2D(hull); }
Example 8
Source File: ClassInfo.java From Akatsuki with Apache License 2.0 | 5 votes |
public ClassName toClassName() { if (enclosingClasses.isEmpty()) { return ClassName.get(fullyQualifiedPackageName, className); } else { // XXX this is just stupid, JavaPoet has a private constructor just // for this... ArrayList<String> names = new ArrayList<>(enclosingClasses); names.add(className); List<String> subList = names.subList(1, names.size()); return ClassName.get(fullyQualifiedPackageName, names.get(0), subList.toArray(new String[subList.size()])); } }
Example 9
Source File: CxxPrecompiledHeaderRuleTest.java From buck with Apache License 2.0 | 5 votes |
/** Return the sublist, starting at {@code toFind}, or empty list if not found. */ List<String> seek(List<String> immList, String toFind) { ArrayList<String> list = new ArrayList<>(immList.size()); list.addAll(immList); int i; for (i = 0; i < list.size(); i++) { if (list.get(i).equals(toFind)) { break; } } return list.subList(i, list.size()); }
Example 10
Source File: ConfigNodePath.java From PlayerVaults with GNU General Public License v3.0 | 5 votes |
protected ConfigNodePath subPath(int toRemove) { int periodCount = 0; ArrayList<Token> tokensCopy = new ArrayList<Token>(tokens); for (int i = 0; i < tokensCopy.size(); i++) { if (Tokens.isUnquotedText(tokensCopy.get(i)) && tokensCopy.get(i).tokenText().equals(".")) periodCount++; if (periodCount == toRemove) { return new ConfigNodePath(path.subPath(toRemove), tokensCopy.subList(i + 1, tokensCopy.size())); } } throw new ConfigException.BugOrBroken("Tried to remove too many elements from a Path node"); }
Example 11
Source File: AsyncDaoImpl.java From x7 with Apache License 2.0 | 5 votes |
/** * 批处理的执行<br> * 在内部线程里调用 */ @SuppressWarnings({ "rawtypes" }) private void executeCreate(final Map<Class, ArrayList<Object>> tempMap) throws Exception { for (Class clz : tempMap.keySet()) { ArrayList<Object> objList = tempMap.get(clz); String sql = MapperFactory.getSql(clz, Mapper.CREATE); List<BeanElement> eles = MapperFactory.getElementList(clz); /* * 分段批处理,每段不超过MAX_BATCH */ int size = objList.size(); int times = size / MAX_BATCH + 1; for (int i = 0; i < times; i++) { int segment = 0; if (i + 1 == times) { segment = size % MAX_BATCH; if (segment == 0){ break; } }else{ segment = MAX_BATCH; } int fromIndex = i * MAX_BATCH; List<Object> subList = objList.subList(fromIndex, fromIndex + segment); batchCreate(subList, sql, eles); } } }
Example 12
Source File: AutoCompleteProvider.java From java-n-IDE-for-Android with Apache License 2.0 | 5 votes |
private String join(ArrayList<String> items, int start, int end, String s) { List<String> strings = items.subList(start, end + 1); StringBuilder result = new StringBuilder(); for (int i = 0; i < strings.size(); i++) { result.append(strings.get(i)).append(i == strings.size() - 1 ? "" : s); } return result.toString(); }
Example 13
Source File: ConcordanceSearchDialog.java From tmxeditor8 with GNU General Public License v2.0 | 5 votes |
private LinkedHashMap<MetaData, List<Integer>> getCurPageMap() { int startIndex = (curPageNum - 1) * rowNumPerPage; int endIndex = curPageNum * rowNumPerPage; if (curPageNum == amountPage) { endIndex = size; } Iterator<Entry<MetaData, ArrayList<Integer>>> it = mapGroupId.entrySet().iterator(); int index = 0; LinkedHashMap<MetaData, List<Integer>> mapSub = new LinkedHashMap<MetaData, List<Integer>>(); while (it.hasNext()) { Entry<MetaData, ArrayList<Integer>> entry = (Entry<MetaData, ArrayList<Integer>>) it.next(); ArrayList<Integer> lstGroupId = entry.getValue(); if (index <= startIndex && index + lstGroupId.size() >= startIndex) { List<Integer> subList = null; if (index + lstGroupId.size() - 1 >= endIndex) { subList = lstGroupId.subList(startIndex - index, endIndex - index); mapSub.put(entry.getKey(), subList); break; } else { subList = lstGroupId.subList(startIndex - index, lstGroupId.size()); index += lstGroupId.size(); startIndex += lstGroupId.size(); mapSub.put(entry.getKey(), subList); } } else { index += lstGroupId.size(); } } return mapSub; }
Example 14
Source File: LiteralGenerator.java From rmlmapper-java with MIT License | 4 votes |
@Override public List<Term> generate(Record record) throws Exception { ArrayList<Term> objects = new ArrayList<>(); ArrayList<String> objectStrings = new ArrayList<>(); FunctionUtils.functionObjectToList(this.functionExecutor.execute(record), objectStrings); String dataTypeSource = null; if (this.functionExecutor instanceof ReferenceExtractor) { dataTypeSource = record.getDataType(((ReferenceExtractor) this.functionExecutor).reference); } if (objectStrings.size() > 0) { //add language tag if present String finalDataTypeSource = dataTypeSource; objectStrings.forEach(objectString -> { if (languageExecutor != null) { try { ArrayList<String> languages = new ArrayList<>(); FunctionUtils.functionObjectToList(this.languageExecutor.execute(record), languages); if (!languages.isEmpty()) { String language = languages.get(0); if (! isValidrrLanguage(language)) { throw new RuntimeException(String.format("Language tag \"%s\" does not conform to BCP 47 standards", language)); } objects.add(new Literal(objectString, language)); } } catch (Exception e) { // TODO print error message e.printStackTrace(); } } else if (datatype != null) { //add datatype if present; language and datatype can't be combined because the language tag implies langString as datatype objects.add(new Literal(objectString, datatype)); } else if (finalDataTypeSource != null) { if (this.functionExecutor instanceof ReferenceExtractor) { objectString = Utils.transformDatatypeString(objectString, finalDataTypeSource); } objects.add(new Literal(objectString, new NamedNode(finalDataTypeSource))); } else { objects.add(new Literal(objectString)); } }); } if (maxNumberOfTerms != 0) { return objects.subList(0, maxNumberOfTerms); } else { return objects; } }
Example 15
Source File: Words.java From DeskChan with GNU Lesser General Public License v3.0 | 4 votes |
public Words(ArrayList<String> words, int start, int end){ this.words = new ArrayList<>(words.subList(start, end)); this.used = new boolean[end - start]; for(int i=0;i<this.used.length;i++) this.used[i] = false; }
Example 16
Source File: GeneralSettingsFragment.java From rcloneExplorer with MIT License | 4 votes |
private void setAppShortcuts(ArrayList<RemoteItem> remoteItems, ArrayList<String> appShortcuts) { if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.N_MR1) { return; } if (appShortcuts.size() > 4) { appShortcuts = new ArrayList<>(appShortcuts.subList(0, 4)); } SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences.Editor editor = sharedPreferences.edit(); Set<String> savedAppShortcutIds = sharedPreferences.getStringSet(getString(R.string.shared_preferences_app_shortcuts), new HashSet<String>()); Set<String> updatedAppShortcutIDds = new HashSet<>(savedAppShortcutIds); // Remove app shortcuts first ArrayList<String> appShortcutIds= new ArrayList<>(); for (String s : appShortcuts) { appShortcutIds.add(AppShortcutsHelper.getUniqueIdFromString(s)); } List<String> removedIds = new ArrayList<>(savedAppShortcutIds); removedIds.removeAll(appShortcutIds); if (!removedIds.isEmpty()) { AppShortcutsHelper.removeAppShortcutIds(context, removedIds); } updatedAppShortcutIDds.removeAll(removedIds); // add new app shortcuts for (String appShortcut : appShortcuts) { String id = AppShortcutsHelper.getUniqueIdFromString(appShortcut); if (updatedAppShortcutIDds.contains(id)) { continue; } RemoteItem remoteItem = null; for (RemoteItem item : remoteItems) { if (item.getName().equals(appShortcut)) { remoteItem = item; break; } } if (remoteItem == null) { continue; } AppShortcutsHelper.addRemoteToAppShortcuts(context, remoteItem, id); updatedAppShortcutIDds.add(id); } editor.putStringSet(getString(R.string.shared_preferences_app_shortcuts), updatedAppShortcutIDds); editor.apply(); }
Example 17
Source File: ServiceDiscovery.java From fabric-sdk-java with Apache License 2.0 | 4 votes |
private static List<SDEndorser> topNbyHeight(int required, List<SDEndorser> endorsers) { ArrayList<SDEndorser> ret = new ArrayList<>(endorsers); ret.sort(Comparator.comparingLong(SDEndorser::getLedgerHeight)); return ret.subList(Math.max(ret.size() - required, 0), ret.size()); }
Example 18
Source File: AbstractDataSet.java From JZAndroidChart with Apache License 2.0 | 4 votes |
public List<T> getVisiblePoints(Viewport viewport) { //生成一个拷贝,利用不可变的思想保证这里不存在并发问题 ArrayList<T> backUpList = new ArrayList<>(getValues()); //防止多次调用 int listSize = backUpList.size(); int from = Math.round(viewport.left * listSize); int to = Math.round(viewport.right * listSize); if (Float.compare(viewport.width(), 1f) == 0 && defaultVisibleEntryCount > 0 && defaultVisibleEntryCount < listSize) { from = to - defaultVisibleEntryCount; viewport.left = from / (float) listSize; } else { if (maxVisibleEntryCount > 0 && to - from > maxVisibleEntryCount) { from = to - maxVisibleEntryCount; viewport.left = from / (float) listSize; } if (minVisibleEntryCount > 0 && minVisibleEntryCount < listSize && to - from < minVisibleEntryCount) { if (to >= minVisibleEntryCount) { from = to - minVisibleEntryCount; //防止越界 if (from < 0) { from = 0; } viewport.left = from / (float) listSize; } else { to = from + minVisibleEntryCount; //防止越界 if (to >= listSize) { to = listSize - 1; } viewport.right = to / (float) listSize; } } } return backUpList.subList(from, to); }
Example 19
Source File: CompiledClassUtils.java From Concurnas with MIT License | 4 votes |
public static com.concurnas.compiler.ast.Type convertGenType(java.lang.reflect.Type type, Map<String, GenericType> nameToGenericMap, boolean dontSetupInterfaceGenerics){ if(type instanceof TypeVariable){//generic return nameToGenericMap.get(((TypeVariable<?>)type).getName()); } com.concurnas.compiler.ast.Type ret; if(type instanceof ParameterizedType) { ParameterizedType asParType = (ParameterizedType)type; Class<?> classDef = (java.lang.Class<?>)asParType.getRawType(); ArrayList<Type> QualifiedgenTypes = extracQualifiedGenTypes(asParType, nameToGenericMap, false); ret = new NamedType(0,0, new ClassDefJava(dontSetupInterfaceGenerics, classDef), (ArrayList<Type>)QualifiedgenTypes); } /*else if(type instanceof Class<?> && !((Class<?>) type).isPrimitive()){ ret = new NamedType(new ClassDefJava((Class<?>)type)); }*/ //TODO: wildcard type should really be covered here else if(type instanceof GenericArrayType){ GenericArrayType asGenAt = (GenericArrayType)type; ret = convertGenType(asGenAt.getGenericComponentType(), nameToGenericMap, dontSetupInterfaceGenerics); ret = (Type) ret.copy(); ret.setArrayLevels(ret.getArrayLevels() + 1); //HERE IS THE PROBLEOMO } else{//not generic ret= CompiledClassUtils.ConvertCompiledClassToType((java.lang.Class<?>)type, dontSetupInterfaceGenerics); } if(ret instanceof NamedType){ NamedType asNamed= ((NamedType)ret); ClassDef set = asNamed.getSetClassDef(); if(set instanceof ClassDefJava){ Class<?> clsHeld = ((ClassDefJava)set).getClassHeld() ; if(refCls.isAssignableFrom(clsHeld)){ asNamed.setIsRef(true); } else if(localArrCls.isAssignableFrom(clsHeld) ){ ret = (Type)asNamed.getGenTypes().get(0).copy(); ret.setArrayLevels(ret.getArrayLevels()+1); } else if(lambdaClass.equals(set.getSuperclass())){//convert to FuncType if possible ArrayList<Type> gens = asNamed.getGenericTypeElements(); if(gens != null && !gens.isEmpty()){ for(Type gt : gens){ if(gt instanceof NamedType){ NamedType asNamedg = (NamedType)gt; if(asNamedg.isWildCardAny){ return new ModuleType(asNamedg.getLine(), asNamedg.getColumn(), "Constructor, Method or Class references cannot return or take as an input wildcards parameters"); } } } } boolean retVoid = set.toString().endsWith("v"); FuncType ft = retVoid?new FuncType(gens, ScopeAndTypeChecker.const_void):new FuncType(new ArrayList<Type>(gens.subList(0, gens.size()-1)), gens.get(gens.size()-1)); //no ? allowed String owwnerelambda; if(set.equals(classRefClass)){ ft.isClassRefType=true; ft.inputs = null; owwnerelambda = ft.retType.getBytecodeType(); owwnerelambda = FuncType.classRefIfacePrefix + owwnerelambda.substring(1, owwnerelambda.length()-1) + FuncType.classRefIfacePostfix; } else{ owwnerelambda = asNamed.getBytecodeType();//lambdaDetails.getA();//"com/concurnas/bootstrap/lang/Lambda$ClassRef"; owwnerelambda = owwnerelambda.substring(1, owwnerelambda.length()-1); } ClassFunctionLocation cflloc = new ClassFunctionLocation(owwnerelambda, asNamed, false); cflloc.setLambdaOwner(owwnerelambda); TypeAndLocation lambdaTal = new TypeAndLocation(asNamed, cflloc);//doesnt resolve to anything, dummy value ft.setLambdaDetails(lambdaTal); ret = ft; } } } ret.setNullStatus(NullStatus.UNKNOWN); return ret; //TODO: need to deal with wildcard case and generic array case }
Example 20
Source File: Words.java From DeskChan with GNU Lesser General Public License v3.0 | 4 votes |
public Words(ArrayList<String> words, boolean[] used, int start, int end){ this.words = new ArrayList<>(words.subList(start, end)); this.used = arrayCopy(used, start, end - start); }