Categories:
Audio (13)
Biotech (29)
Bytecode (36)
Database (77)
Framework (7)
Game (7)
General (507)
Graphics (53)
I/O (35)
IDE (2)
JAR Tools (101)
JavaBeans (21)
JDBC (121)
JDK (426)
JSP (20)
Logging (108)
Mail (58)
Messaging (8)
Network (84)
PDF (97)
Report (7)
Scripting (84)
Security (32)
Server (121)
Servlet (26)
SOAP (24)
Testing (54)
Web (15)
XML (309)
Collections:
Other Resources:
commons-collections4-4.2-sources.jar - Apache Commons Collections
commons-collections4-4.2-sources.jar is the source JAR file for Apache Commons Collections 4.2, which provides additional collection handling functionalities on top of JDK library.
JAR File Size and Download Location:
JAR name: commons-collections4-4.2-sources.jar Target JDK version: 1.7 Dependency: None File size: 708,599 bytes Release date: 08-Jul-2018 Download: Apache Commons Collections
✍: FYIcenter.com
⏎ org/apache/commons/collections4/list/LazyList.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.collections4.list; import java.util.List; import org.apache.commons.collections4.Factory; /** * Decorates another <code>List</code> to create objects in the list on demand. * <p> * When the {@link #get(int)} method is called with an index greater than * the size of the list, the list will automatically grow in size and return * a new object from the specified factory. The gaps will be filled by null. * If a get method call encounters a null, it will be replaced with a new * object from the factory. Thus this list is unsuitable for storing null * objects. * <p> * For instance: * * <pre> * Factory<Date> factory = new Factory<Date>() { * public Date create() { * return new Date(); * } * } * List<Date> lazy = LazyList.decorate(new ArrayList<Date>(), factory); * Date date = lazy.get(3); * </pre> * * After the above code is executed, <code>date</code> will contain * a new <code>Date</code> instance. Furthermore, that <code>Date</code> * instance is the fourth element in the list. The first, second, * and third element are all set to <code>null</code>. * <p> * This class differs from {@link GrowthList} because here growth occurs on * get, where <code>GrowthList</code> grows on set and add. However, they * could easily be used together by decorating twice. * <p> * This class is Serializable from Commons Collections 3.1. * * @see GrowthList * @since 3.0 */ public class LazyList<E> extends AbstractSerializableListDecorator<E> { /** Serialization version */ private static final long serialVersionUID = -1708388017160694542L; /** The factory to use to lazily instantiate the objects */ private final Factory<? extends E> factory; /** * Factory method to create a lazily instantiating list. * * @param <E> the type of the elements in the list * @param list the list to decorate, must not be null * @param factory the factory to use for creation, must not be null * @return a new lazy list * @throws NullPointerException if list or factory is null * @since 4.0 */ public static <E> LazyList<E> lazyList(final List<E> list, final Factory<? extends E> factory) { return new LazyList<>(list, factory); } //----------------------------------------------------------------------- /** * Constructor that wraps (not copies). * * @param list the list to decorate, must not be null * @param factory the factory to use for creation, must not be null * @throws NullPointerException if list or factory is null */ protected LazyList(final List<E> list, final Factory<? extends E> factory) { super(list); if (factory == null) { throw new IllegalArgumentException("Factory must not be null"); } this.factory = factory; } //----------------------------------------------------------------------- /** * Decorate the get method to perform the lazy behaviour. * <p> * If the requested index is greater than the current size, the list will * grow to the new size and a new object will be returned from the factory. * Indexes in-between the old size and the requested size are left with a * placeholder that is replaced with a factory object when requested. * * @param index the index to retrieve * @return the element at the given index */ @Override public E get(final int index) { final int size = decorated().size(); if (index < size) { // within bounds, get the object E object = decorated().get(index); if (object == null) { // item is a place holder, create new one, set and return object = factory.create(); decorated().set(index, object); return object; } // good and ready to go return object; } // we have to grow the list for (int i = size; i < index; i++) { decorated().add(null); } // create our last object, set and return final E object = factory.create(); decorated().add(object); return object; } @Override public List<E> subList(final int fromIndex, final int toIndex) { final List<E> sub = decorated().subList(fromIndex, toIndex); return new LazyList<>(sub, factory); } }
⏎ org/apache/commons/collections4/list/LazyList.java
Or download all of them as a single archive file:
File name: commons-collections4-4.2-sources.jar File size: 708599 bytes Release date: 2018-07-08 Download
⇒ Download and Install commons-collections4-4.1-bin.zip
⇐ What Is commons-collections4-4.2.jar
2023-03-28, 27686👍, 0💬
Popular Posts:
How to download and install Apache XMLBeans Source Package? The source package contains Java source ...
JRE 8 rt.jar is the JAR file for JRE 8 RT (Runtime) libraries. JRE (Java Runtime) 8 is the runtime e...
Where to find answers to frequently asked questions on Downloading and Installing ojdbc.jar - JDBC D...
Saxon is an open source product available under the Mozilla Public License. It provides implementati...
commons-collections4-4.4 -sources.jaris the source JAR file for Apache Commons Collections 4.2, whic...