ShapefileDataStore extends ContentDataStore implements FileDataStore { public long getCount(Query query) throws IOException { return getFeatureSource().getCount(query); } ShapefileDataStore(URL url); ContentFeatureSource getFeatureSource(); Charset getCharset(); void setCharset(Charset charset); TimeZone getTimeZone(); void setTimeZone(TimeZone timeZone); boolean isMemoryMapped(); void setMemoryMapped(boolean memoryMapped); boolean isBufferCachingEnabled(); void setBufferCachingEnabled(boolean bufferCachingEnabled); boolean isIndexed(); void setIndexed(boolean indexed); SimpleFeatureType getSchema(); FeatureReader<SimpleFeatureType, SimpleFeature> getFeatureReader(); long getCount(Query query); void createSchema(SimpleFeatureType featureType); void forceSchemaCRS(CoordinateReferenceSystem crs); @Override void dispose(); boolean isFidIndexed(); void setFidIndexed(boolean fidIndexed); @Override String toString(); @Override void updateSchema(SimpleFeatureType featureType); @Override FeatureWriter<SimpleFeatureType, SimpleFeature> getFeatureWriter(Filter filter,
            Transaction transaction); @Override FeatureWriter<SimpleFeatureType, SimpleFeature> getFeatureWriter(Transaction transaction); @Override FeatureWriter<SimpleFeatureType, SimpleFeature> getFeatureWriterAppend(
            Transaction transaction); boolean isIndexCreationEnabled(); void setIndexCreationEnabled(boolean indexCreationEnabled); static final String ORIGINAL_FIELD_NAME; static final String ORIGINAL_FIELD_DUPLICITY_COUNT; static final Charset DEFAULT_STRING_CHARSET; static final TimeZone DEFAULT_TIMEZONE; }
@Test public void testGetCount() throws Exception { assertTrue(copyShapefiles(STREAM).canRead()); ShapefileDataStore store = new ShapefileDataStore(TestData.url(TestCaseSupport.class, STREAM)); int count = 0; FeatureReader<SimpleFeatureType, SimpleFeature> reader = store.getFeatureReader(); try { while (reader.hasNext()) { count++; reader.next(); } assertEquals(count, store.getCount(Query.ALL)); SimpleFeatureSource featureSource = store.getFeatureSource(); SimpleFeatureCollection features = featureSource.getFeatures(); assertEquals(count, features.size()); assertFalse(features.isEmpty()); FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(null); SimpleFeatureType schema = featureSource.getSchema(); String geomName = schema.getGeometryDescriptor().getName().getLocalPart(); Query query = new Query(schema.getTypeName()); query.setPropertyNames(Query.ALL_NAMES); ReferencedEnvelope bounds = features.getBounds(); query.setFilter(ff.bbox(ff.property(geomName), bounds)); features = featureSource.getFeatures(query); assertEquals(count, features.size()); assertFalse(features.isEmpty()); query = new Query(Query.ALL); query.setStartIndex(2); features = featureSource.getFeatures(query); assertEquals(count-2, features.size()); assertEquals(count-2, featureSource.getCount(query)); query = new Query(Query.ALL); query.setMaxFeatures(count/2); features = featureSource.getFeatures(query); assertEquals(count/2, features.size()); assertEquals(count/2, featureSource.getCount(query)); query = new Query(Query.ALL); query.setMaxFeatures(count/2); query.setStartIndex(2); features = featureSource.getFeatures(query); assertEquals(Math.min(count-2, count/2), features.size()); assertEquals(Math.min(count-2, count/2), featureSource.getCount(query)); query = new Query(Query.ALL); bounds = new ReferencedEnvelope(bounds.getMaxX() + 1, bounds.getMaxX() + 2, bounds.getMaxY() + 1, bounds.getMaxY() + 2, bounds.getCoordinateReferenceSystem()); query.setFilter(ff.bbox(ff.property(geomName), bounds)); features = featureSource.getFeatures(query); assertEquals(0, features.size()); assertTrue(features.isEmpty()); } finally { reader.close(); } store.dispose(); }