/** * Returns all known factories specialized in the creation of coordinate operations between some particular * pairs of CRS. */ final SpecializedOperationFactory[] getSpecializedFactories() { SpecializedOperationFactory[] factories = specializedFactories; if (factories == null) { final LazySet<SpecializedOperationFactory> set = new LazySet<>(ServiceLoader.load(SpecializedOperationFactory.class).iterator()); specializedFactories = factories = set.toArray(new SpecializedOperationFactory[set.size()]); } return factories; }
/** * Returns the number of elements in this set. Invoking this method * forces the set to immediately iterates through all remaining elements. * * @return number of elements in the iterator. */ @Override public final int size() { if (canPullMore()) { while (sourceIterator.hasNext()) { cache(next(sourceIterator)); } sourceIterator = null; } return numCached; }
c = new LazySet<>(registry.getServiceProviders(DummyFactory.class, null, hints, key)); assertTrue(c.contains(factory1)); assertTrue(c.contains(factory2)); assertTrue(c.contains(factory3)); assertEquals(3, c.size()); c = new LazySet<>(registry.getServiceProviders(DummyFactory.class, null, hints, key)); assertTrue(c.contains(factory1)); assertTrue(c.contains(factory2)); assertTrue(c.contains(factory3)); assertEquals(3, c.size()); c = new LazySet<>(registry.getServiceProviders(DummyFactory.class, null, hints, key)); assertFalse(c.contains(factory1)); assertTrue (c.contains(factory2)); assertFalse(c.contains(factory3)); assertEquals(1, c.size()); c = new LazySet<>(registry.getServiceProviders(DummyFactory.class, null, hints, key)); assertTrue (c.contains(factory1)); assertTrue (c.contains(factory2)); assertFalse(c.contains(factory3)); assertEquals(2, c.size()); c = new LazySet<>(registry.getServiceProviders(DummyFactory.class, null, hints, key)); assertFalse(c.contains(factory1)); assertFalse(c.contains(factory2)); assertTrue (c.contains(factory3)); assertEquals(1, c.size());
/** * Returns the list of data store providers available at this method invocation time. * More providers may be added later if new modules are added on the classpath. * * @return descriptions of available data stores. * * @since 0.8 */ public Set<DataStoreProvider> providers() { synchronized (loader) { final Iterator<DataStoreProvider> providers = loader.iterator(); return new LazySet<>(new Iterator<DataStoreProvider>() { @Override public boolean hasNext() { synchronized (loader) { return providers.hasNext(); } } @Override public DataStoreProvider next() { synchronized (loader) { return providers.next(); } } }); } }
final LazySet<String> set = create(); final Iterator<String> it1 = set.iterator(); assertTrue(it1.hasNext()); assertEquals("one", it1.next()); final Iterator<String> it2 = set.iterator(); assertTrue (it2.hasNext()); assertEquals("one", it2.next()); assertFalse (it1.hasNext()); assertEquals(LABELS.length, set.size());
/** * Returns {@code true} if an element exists at the given index. * The element is not loaded immediately. * * <p><strong>NOTE: This method is for use by iterators only.</strong> * It is not suited for more general usage since it does not check for * negative index and for skipped elements.</p> */ final boolean exists(final int index) { assert index <= numCached : index; return (index < numCached) || canPullMore(); }
/** * Caches a new element, possibly substituting the created instance by a previously created instance. * * @param element the element to add to the cache. */ @Override protected void cache(OperationMethod element) { if (element instanceof GeodeticOperation) { final Class<?> variant3D = ((GeodeticOperation) element).variant3D(); if (variant3D != null) { final List<OperationMethod> cached = cached(); for (int i=cached.size(); --i >= 0;) { final OperationMethod m = cached.get(i); if (m.getClass() == variant3D) { for (final GeodeticOperation candidate : ((GeodeticOperation) m).redimensioned) { if (candidate != null && candidate.getClass() == element.getClass()) { element = candidate; break; } } } } } } super.cache(element); } }
/** * Returns the list of data store providers available at this method invocation time. * More providers may be added later if new modules are added on the classpath. * * @return descriptions of available data stores. * * @since 0.8 */ public Collection<DataStoreProvider> providers() { synchronized (loader) { final Iterator<DataStoreProvider> providers = loader.iterator(); return new LazySet<>(new Iterator<DataStoreProvider>() { @Override public boolean hasNext() { synchronized (loader) { return providers.hasNext(); } } @Override public DataStoreProvider next() { synchronized (loader) { return providers.next(); } } @Override public void remove() { throw new UnsupportedOperationException(); } }); } }
/** * Tests {@link LazySet#size()} followed by {@link LazySet#isEmpty()}. */ @Test @DependsOnMethod("testIsEmptyAndSize") public void testSizeAndIsEmpty() { final LazySet<String> set = create(); assertEquals(LABELS.length, set.size()); assertFalse(set.isEmpty()); assertEquals(LABELS.length, set.size()); }
/** * Tests if this set has no element. * * @return {@code true} if this set has no element. */ @Override public final boolean isEmpty() { return (numCached == 0) && !canPullMore(); }
/** * Caches a new element, possibly substituting the created instance by a previously created instance. * * @param element the element to add to the cache. */ @Override protected void cache(OperationMethod element) { if (element instanceof GeodeticOperation) { final Class<?> variant3D = ((GeodeticOperation) element).variant3D(); if (variant3D != null) { final List<OperationMethod> cached = cached(); for (int i=cached.size(); --i >= 0;) { final OperationMethod m = cached.get(i); if (m.getClass() == variant3D) { for (final GeodeticOperation candidate : ((GeodeticOperation) m).redimensioned) { if (candidate != null && candidate.getClass() == element.getClass()) { element = candidate; break; } } } } } } super.cache(element); } }
/** * Returns all known factories specialized in the creation of coordinate operations between some particular * pairs of CRS. */ final SpecializedOperationFactory[] getSpecializedFactories() { SpecializedOperationFactory[] factories = specializedFactories; if (factories == null) { final LazySet<SpecializedOperationFactory> set = new LazySet<>(ServiceLoader.load(SpecializedOperationFactory.class).iterator()); specializedFactories = factories = set.toArray(new SpecializedOperationFactory[set.size()]); } return factories; }
/** * Creates the set to use for testing purpose. */ private static LazySet<String> create() { return new LazySet<>(Arrays.asList(LABELS).iterator()); }
/** * Returns the number of elements in this set. Invoking this method * forces the set to immediately iterates through all remaining elements. * * @return number of elements in the iterator. */ @Override public final int size() { if (canPullMore()) { while (sourceIterator.hasNext()) { cache(next(sourceIterator)); } sourceIterator = null; } return numCached; }
/** * Tests if this set has no element. * * @return {@code true} if this set has no element. */ @Override public final boolean isEmpty() { return (numCached == 0) && !canPullMore(); }
/** * Returns some map projection methods supported by {@literal Proj.4}. * Current implementation can not return the complete list of Proj.4 method, but returns the main ones. * For each operation method in the returned set, the Proj.4 projection name can be obtained as below: * * {@preformat java * String proj = IdentifiedObjects.getName(method, Citations.PROJ4); * } * * The {@code proj} names obtained as above can be given in argument to the * {@link #getOperationMethod(String)} and {@link #getDefaultParameters(String)} methods. * * @param type <code>{@linkplain SingleOperation}.class</code> for fetching all operation methods, or * <code>{@linkplain Projection}.class</code> for fetching only map projection methods. * @return methods available in this factory for coordinate operations of the given type. * * @see org.apache.sis.referencing.operation.transform.DefaultMathTransformFactory#getAvailableMethods(Class) */ public Set<OperationMethod> getAvailableMethods(final Class<? extends SingleOperation> type) { return new LazySet<>(CollectionsExt.filter(mtFactory.getAvailableMethods(type).iterator(), Proj4Factory::isSupported)); }
/** * Returns the element at the specified position in this set. * * @param index the index at which to get an element. * @return the element at the requested index. */ final E get(final int index) { assert numCached <= cachedElements.length : numCached; assert index <= numCached : index; if (index >= numCached) { if (canPullMore()) { cache(next(sourceIterator)); } else { throw new NoSuchElementException(); } } return cachedElements[index]; }
/** * Returns {@code true} if an element exists at the given index. * The element is not loaded immediately. * * <p><strong>NOTE: This method is for use by iterators only.</strong> * It is not suited for more general usage since it does not check for * negative index and for skipped elements.</p> */ final boolean exists(final int index) { assert index <= numCached : index; return (index < numCached) || canPullMore(); }