List of usage examples for java.util AbstractList AbstractList
protected AbstractList()
From source file:FastArray.java
public List toList() { return new AbstractList() { public Object get(int index) { return FastArray.this.get(index); }//from www.ja v a 2 s .com public int size() { return size; } }; }
From source file:edu.dfci.cccb.mev.hcl.domain.contract.Metric.java
protected List<Double> correlate(final List<Double> from, final List<Double> to) { return new AbstractList<Double>() { @Override/*from w w w. j a v a 2 s. c o m*/ public Double get(int index) { return correlate(from.get(index), to.get(index)); } @Override public int size() { return from.size(); } }; }
From source file:org.chromium.sdk.internal.v8native.protocol.V8ProtocolUtil.java
public static List<DataWithRef> extractAllPropertyRefs(ObjectValueHandle handle) { final List<PropertyReference> properties = new ArrayList<PropertyReference>(); properties.addAll(extractObjectProperties(handle)); properties.addAll(extractObjectInternalProperties(handle)); return new AbstractList<DataWithRef>() { @Override/*ww w . j ava 2 s. co m*/ public int size() { return properties.size(); } @Override public DataWithRef get(int index) { return properties.get(index).getValueObject(); } }; }
From source file:MainDocumentationExamples.java
@Test public void parsesJsonAndGetsElementsWithJsonNodeSelector() throws Exception { final String jsonText = FileUtils .readFileToString(new File(this.getClass().getResource("SimpleExample.json").getFile())); final JsonRootNode json = JDOM_PARSER.parse(jsonText); String secondSingle = SECOND_SINGLE.getValue(json); List<String> singles = new AbstractList<String>() { public String get(int index) { return SINGLE_NAME.getValue(SINGLES.getValue(json).get(index)); }// w w w .ja v a2 s .c o m public int size() { return SINGLES.getValue(json).size(); } }; BigDecimal totalRoyalties = asBigDecimal(json.getNumberValue("totalRoyalties")); assertThat(secondSingle, equalTo("Agadoo")); assertThat(singles, equalTo(Arrays.asList("Superman", "Agadoo"))); assertThat(totalRoyalties, equalTo(new BigDecimal("10223.82"))); }
From source file:MicroMap.java
/** * @see java.util.Map#values()//from w w w .j a va 2 s . com */ public Collection values() { return new AbstractList() { public Object get(final int index) { return value; } public int size() { return MicroMap.this.size(); } }; }
From source file:org.alfresco.rest.api.impl.FavouritesImpl.java
private CollectionWithPagingInfo<Favourite> wrap(Paging paging, PagingResults<PersonFavourite> personFavourites) { final List<PersonFavourite> page = personFavourites.getPage(); final List<Favourite> list = new AbstractList<Favourite>() { @Override/*from w ww . j a va 2s .c om*/ public Favourite get(int index) { PersonFavourite personFavourite = page.get(index); Favourite fav = getFavourite(personFavourite); return fav; } @Override public int size() { return page.size(); } }; Pair<Integer, Integer> pair = personFavourites.getTotalResultCount(); Integer total = null; if (pair.getFirst().equals(pair.getSecond())) { total = pair.getFirst(); } return CollectionWithPagingInfo.asPaged(paging, list, personFavourites.hasMoreItems(), total); }
From source file:MicroMap.java
/** * @see java.util.Map#values()//from w ww .j a v a2 s. co m */ public Collection<V> values() { return new AbstractList<V>() { @Override public V get(final int index) { if (index > size() - 1) { throw new IndexOutOfBoundsException(); } return value; } @Override public int size() { return MicroMap.this.size(); } }; }
From source file:org.alfresco.rm.rest.api.recordcategories.RecordCategoryChildrenRelation.java
@Override @WebApiDescription(title = "Return a paged list of record category children for the container identified by 'recordCategoryId'") public CollectionWithPagingInfo<RecordCategoryChild> readAll(String recordCategoryId, Parameters parameters) { checkNotBlank("recordCategoryId", recordCategoryId); mandatory("parameters", parameters); String relativePath = parameters.getParameter(Nodes.PARAM_RELATIVE_PATH); NodeRef parentNodeRef = apiUtils.lookupAndValidateNodeType(recordCategoryId, RecordsManagementModel.TYPE_RECORD_CATEGORY, relativePath, true); // list record categories and record folders Set<QName> searchTypeQNames = searchTypesFactory.buildSearchTypesCategoriesEndpoint(parameters, LIST_RECORD_CATEGORY_CHILDREN_EQUALS_QUERY_PROPERTIES); List<FilterProp> filterProps = apiUtils.getListChildrenFilterProps(parameters, LIST_RECORD_CATEGORY_CHILDREN_EQUALS_QUERY_PROPERTIES); final PagingResults<FileInfo> pagingResults = fileFolderService.list(parentNodeRef, null, searchTypeQNames, null, apiUtils.getSortProperties(parameters), filterProps, Util.getPagingRequest(parameters.getPaging())); final List<FileInfo> page = pagingResults.getPage(); Map<String, UserInfo> mapUserInfo = new HashMap<>(); List<RecordCategoryChild> nodes = new AbstractList<RecordCategoryChild>() { @Override// ww w .j a v a2 s .c o m public RecordCategoryChild get(int index) { FileInfo info = page.get(index); return nodesModelFactory.createRecordCategoryChild(info, parameters, mapUserInfo, true); } @Override public int size() { return page.size(); } }; RecordCategory sourceEntity = null; if (parameters.includeSource()) { FileInfo info = fileFolderService.getFileInfo(parentNodeRef); sourceEntity = nodesModelFactory.createRecordCategory(info, parameters, mapUserInfo, true); } return CollectionWithPagingInfo.asPaged(parameters.getPaging(), nodes, pagingResults.hasMoreItems(), pagingResults.getTotalResultCount().getFirst(), sourceEntity); }
From source file:edu.dfci.cccb.mev.hcl.domain.simple.SimpleTwoDimensionalHclBuilder.java
private Node cluster(final Dataset dataset, Dimension dimension, Metric metric, Linkage linkage) throws DatasetException { final Type dimensionType = dimension.type(); final RealMatrix original = toRealMatrix(dataset); final int size = dimensionType == ROW ? original.getRowDimension() : original.getColumnDimension(); final int other = dimensionType == COLUMN ? original.getRowDimension() : original.getColumnDimension(); Iterator<Integer> enumerator = new Iterator<Integer>() { private int counter = -1; @Override/* w w w .ja v a 2 s . co m*/ public boolean hasNext() { return true; } @Override public Integer next() { counter--; if (counter > 0) counter = -1; return counter; } @Override public void remove() { throw new UnsupportedOperationException(); } }; final double[][] distances = new double[size][size]; log.debug("Populating node hash"); final Map<Integer, Node> genehash = new HashMap<Integer, Node>() { private static final long serialVersionUID = 1L; { for (int index = size; --index >= 0; put(index, nodeBuilder().leaf(dataset.dimension(dimensionType).keys().get(index)))) ; } }; TreeMap<Double, int[]> sorted = new TreeMap<>(); log.debug("Populating distance matrix"); for (int i = 0; i < size; i++) { for (int j = i + 1; j < size; j++) { double distance = metric.distance(new AbstractList<Double>() { private int i; @Override public Double get(int index) { return dimensionType == ROW ? original.getEntry(i, index) : original.getEntry(index, i); } @Override public int size() { return other; } private List<Double> initializeProjection(int i) { this.i = i; return this; } }.initializeProjection(i), new AbstractList<Double>() { private int j; @Override public Double get(int index) { return dimensionType == ROW ? original.getEntry(j, index) : original.getEntry(index, j); } @Override public int size() { return other; } private List<Double> initializeProjection(int j) { this.j = j; return this; } }.initializeProjection(j)); distances[i][j] = distance; distances[j][i] = distance; int[] genePair = { i, j }; // Enter the distance calculated and the genes measured into a // treemap. Will be automatically sorted. sorted.put(distance, genePair); } } log.debug("Aggregating"); while (true) { // Get the first key of the TreeMap. Will be the shortest distance de // facto. final double minkey = (Double) sorted.firstKey(); int[] minValues = (int[]) sorted.firstEntry().getValue(); final int value1 = minValues[0], value2 = minValues[1]; // find Node cluster = nodeBuilder().branch(minkey, genehash.get(value1), genehash.get(value2)); int id = enumerator.next(); genehash.put(id, cluster); genehash.remove(value1); genehash.remove(value2); if (genehash.size() <= 1) break; // Iterate over all the current clusters to remeasure distance with the // previously clustered group. for (Entry<Integer, Node> e : genehash.entrySet()) { Node c = e.getValue(); // Skip measuring the new cluster with itself. if (c == cluster) continue; List<Double> aggregation = new ArrayList<>(); // Get genes from each cluster. Distance is measured from each element // to every element. for (int current : traverse(dimension.keys(), c)) for (int created : traverse(dimension.keys(), cluster)) aggregation.add(distances[current][created]); int[] valuePair = { e.getKey(), id }; sorted.put(linkage.aggregate(aggregation), valuePair); } // Get the shortest distance. // Check to make sure shortest distance does not include a gene pair // that // has already had its elements clustered. boolean minimized = false; while (!minimized) { double mk = sorted.firstKey(); minValues = sorted.firstEntry().getValue(); // If the gene pair is not present in the current gene set, remove // this distance. if (!genehash.containsKey(minValues[0]) || !genehash.containsKey(minValues[1])) sorted.remove(mk); else minimized = true; } } Node result = genehash.entrySet().iterator().next().getValue(); log.debug("Clustered " + result); return result; }
From source file:org.alfresco.rm.rest.api.unfiledrecordfolders.UnfiledRecordFolderChildrenRelation.java
@Override @WebApiDescription(title = "Return a paged list of unfiled container children for the container identified by 'unfiledContainerId'") public CollectionWithPagingInfo<UnfiledRecordFolderChild> readAll(String unfileRecordFolderId, Parameters parameters) {/*w w w .ja v a 2 s . c om*/ checkNotBlank("unfileRecordFolderId", unfileRecordFolderId); mandatory("parameters", parameters); String relativePath = parameters.getParameter(Nodes.PARAM_RELATIVE_PATH); NodeRef parentNodeRef = apiUtils.lookupAndValidateNodeType(unfileRecordFolderId, RecordsManagementModel.TYPE_UNFILED_RECORD_FOLDER, relativePath, true); // list unfiled record folders and records Set<QName> searchTypeQNames = searchTypesFactory.buildSearchTypesForUnfiledEndpoint(parameters, LIST_UNFILED_RECORD_FOLDER_CHILDREN_EQUALS_QUERY_PROPERTIES); final PagingResults<FileInfo> pagingResults = fileFolderService.list(parentNodeRef, null, searchTypeQNames, null, apiUtils.getSortProperties(parameters), null, Util.getPagingRequest(parameters.getPaging())); final List<FileInfo> page = pagingResults.getPage(); Map<String, UserInfo> mapUserInfo = new HashMap<>(); List<UnfiledRecordFolderChild> nodes = new AbstractList<UnfiledRecordFolderChild>() { @Override public UnfiledRecordFolderChild get(int index) { FileInfo info = page.get(index); return nodesModelFactory.createUnfiledRecordFolderChild(info, parameters, mapUserInfo, true); } @Override public int size() { return page.size(); } }; UnfiledRecordFolder sourceEntity = null; if (parameters.includeSource()) { FileInfo info = fileFolderService.getFileInfo(parentNodeRef); sourceEntity = nodesModelFactory.createUnfiledRecordFolder(info, parameters, mapUserInfo, true); } return CollectionWithPagingInfo.asPaged(parameters.getPaging(), nodes, pagingResults.hasMoreItems(), pagingResults.getTotalResultCount().getFirst(), sourceEntity); }