This method keeps the highest scoring features of the provided feature map
and removes all the others.

@param featureScores
@param maxFeatures
973229
protected void keepTopFeatures(Map<Object, Double> featureScores, int maxFeatures) {
        logger.debug("keepTopFeatures()");

        logger.debug("Estimating the minPermittedScore");
        Double minPermittedScore = SelectKth.largest(featureScores.values().iterator(), maxFeatures);

        //remove any entry with score less than the minimum permitted one
        logger.debug("Removing features with scores less than threshold");
        Iterator<Map.Entry<Object, Double>> it = featureScores.entrySet().iterator();
        while(it.hasNext()) {
            Map.Entry<Object, Double> entry = it.next();
            if(entry.getValue()<minPermittedScore) {
                it.remove();
            }
        }

        //if some extra features still exist (due to ties on the scores) remove some of those extra features
        int numOfExtraFeatures = featureScores.size()-maxFeatures;
        if(numOfExtraFeatures>0) {
            logger.debug("Removing extra features caused by ties");
            it = featureScores.entrySet().iterator();
            while(it.hasNext() && numOfExtraFeatures>0) {
                Map.Entry<Object, Double> entry = it.next();
                if(entry.getValue()-minPermittedScore<=0.0) { //DO NOT COMPARE THEM DIRECTLY USE SUBTRACTION!
                    it.remove();
                    --numOfExtraFeatures;
                }
            }
        }
    }
205523
public void createFeatures(List<String> features, String[] tokens) {

    for (DocumentFeatureGenerator generator : generators) {
      generator.createFeatures(features, tokens);
    }
  }
398556
public void applyFeatureCountThreshold(int k) {
    float[] counts = getFeatureCounts();
    Index<F> newFeatureIndex = new HashIndex<F>();

    int[] featMap = new int[featureIndex.size()];
    for (int i = 0; i < featMap.length; i++) {
      F feat = featureIndex.get(i);
      if (counts[i] >= k) {
        int newIndex = newFeatureIndex.size();
        newFeatureIndex.add(feat);
        featMap[i] = newIndex;
      } else {
        featMap[i] = -1;
      }
      // featureIndex.remove(feat);
    }

    featureIndex = newFeatureIndex;
    // counts = null; // This is unnecessary; JVM can clean it up

    for (int i = 0; i < size; i++) {
      List<Integer> featList = new ArrayList<Integer>(data[i].length);
      for (int j = 0; j < data[i].length; j++) {
        if (featMap[data[i][j]] >= 0) {
          featList.add(featMap[data[i][j]]);
        }
      }
      data[i] = new int[featList.size()];
      for (int j = 0; j < data[i].length; j++) {
        data[i][j] = featList.get(j);
      }
    }
  }
1284017
public void applyFeatureCountThreshold(List<Pair<Pattern, Integer>> thresholds) {

    // get feature counts
    float[] counts = getFeatureCounts();

    // build a new featureIndex
    Index<F> newFeatureIndex = new HashIndex<F>();
    LOOP: for (F f : featureIndex) {
      for (Pair<Pattern, Integer> threshold : thresholds) {
        Pattern p = threshold.first();
        Matcher m = p.matcher(f.toString());
        if (m.matches()) {
          if (counts[featureIndex.indexOf(f)] >= threshold.second) {
            newFeatureIndex.add(f);
          }
          continue LOOP;
        }
      }
      // we only get here if it didn't match anything on the list
      newFeatureIndex.add(f);
    }

    counts = null;

    int[] featMap = new int[featureIndex.size()];
    for (int i = 0; i < featMap.length; i++) {
      featMap[i] = newFeatureIndex.indexOf(featureIndex.get(i));
    }

    featureIndex = null;

    for (int i = 0; i < size; i++) {
      List<Integer> featList = new ArrayList<Integer>(data[i].length);
      for (int j = 0; j < data[i].length; j++) {
        if (featMap[data[i][j]] >= 0) {
          featList.add(featMap[data[i][j]]);
        }
      }
      data[i] = new int[featList.size()];
      for (int j = 0; j < data[i].length; j++) {
        data[i][j] = featList.get(j);
      }
    }

    //TODO: continuation of hack from above... hope those features are really strings
    //if you call this function. ~Sarah
    featureIndex = newFeatureIndex;
  }
68978
private void saveFeatures(List<Feature> features, FeatureCollector collector) {
        features.forEach(f -> {
            f.setCollectorId(collector.getId());
            Feature existing = featureRepository.findByCollectorIdAndSIdAndSTeamID(collector.getId(), f.getsId(), f.getsTeamID());
            if (existing != null) {
                f.setId(existing.getId());
            }
            featureRepository.save(f);
        });
    }
635033
public void setFeature(Feature feature) {
		if (feature != null) {
			this.feature = feature;
			copyToForm(this.feature);
		} else {
			this.feature = null;
			featureForm.clear();
		}
	}
1338270
function(features) {
        if(!(OpenLayers.Util.isArray(features))) {
            features = [features];
        }
        for(var i=0, len=features.length; i<len; ++i) {
            var feature = features[i];
            this.eraseGeometry(feature.geometry, feature.id);
            this.removeText(feature.id);
        }
    }
787872
public int getFeaturePosition(AbstractFeature feature) {
        AbstractFeature result = feature;
        if (!featurePositions.containsKey(feature)) {
            if (feature instanceof FeatureGroup) {
                FeatureGroup featureGroup = (FeatureGroup) feature;
                List<Feature> features = featureGroup.getConcreteFeatures();
                if (!features.isEmpty()) {
                    Collections.sort(features, new Comparator<Feature>() {
                        @Override
                        public int compare(Feature feat1, Feature feat2) {
                            return getFeaturePosition(feat1) - getFeaturePosition(feat2);
                        }
                    });
                    result = features.get(0);
                }
            }
        }
        return featurePositions.getOrDefault(result, 0);
    }
1066955
def clear_all(self):
        """"""
        logger.info("Clearing ALL Features and FeatureKeys.")
        self.session.query(Feature).delete(synchronize_session="fetch")
        self.session.query(FeatureKey).delete(synchronize_session="fetch")
603645
public FeatureIndexResults queryFeatures(BoundingBox boundingBox) {
        FeatureIndexResults results = queryFeatures(boundingBox, null);
        return results;
    }
344679
protected List<Feature> convertFeatures(FeatureCollection<SimpleFeatureType, SimpleFeature> features,
			int maxCoordinates, double startDistance) throws IOException, GeomajasException {
		FeatureIterator<SimpleFeature> iterator = features.features();
		List<Feature> dtoFeatures = new ArrayList<Feature>();
		FeatureConverter converter = new FeatureConverter();
		while (iterator.hasNext()) {
			try {
				SimpleFeature feature = iterator.next();
				dtoFeatures.add(converter.toDto(feature, maxCoordinates));
			} catch (Exception e) {
				continue;
			}
		}
		iterator.close();
		return dtoFeatures;
	}
640895
@SuppressWarnings("static-method")
	public void getImportedFeatures(List<Class<?>> features) {
		features.add(AtomicIntegerArithmeticExtensions.class);
		features.add(AtomicLongArithmeticExtensions.class);
		features.add(ByteArithmeticExtensions.class);
		features.add(DoubleArithmeticExtensions.class);
		features.add(FloatArithmeticExtensions.class);
		features.add(IntegerArithmeticExtensions.class);
		features.add(LongArithmeticExtensions.class);
		features.add(NumberArithmeticExtensions.class);
		features.add(PrimitiveByteArithmeticExtensions.class);
		features.add(PrimitiveDoubleArithmeticExtensions.class);
		features.add(PrimitiveFloatArithmeticExtensions.class);
		features.add(PrimitiveIntArithmeticExtensions.class);
		features.add(PrimitiveLongArithmeticExtensions.class);
		features.add(PrimitiveShortArithmeticExtensions.class);
		features.add(ShortArithmeticExtensions.class);
	}
176614
public float[] getFeatureCounts() {
    float[] counts = new float[featureIndex.size()];
    for (int i = 0, m = size; i < m; i++) {
      for (int j = 0, n = data[i].length; j < n; j++) {
        counts[data[i][j]] += 1.0;
      }
    }
    return counts;
  }
142093
private double maxScore(List<InetAddress> endpoints)
    {
        double maxScore = -1.0;
        for (InetAddress endpoint : endpoints)
        {
            Double score = scores.get(endpoint);
            if (score == null)
                continue;

            if (score > maxScore)
                maxScore = score;
        }
        return maxScore;
    }
793800
public static SimpleFeatureCollection createFeatureCollection( SimpleFeature... features ) {
        DefaultFeatureCollection fcollection = new DefaultFeatureCollection();

        for( SimpleFeature feature : features ) {
            fcollection.add(feature);
        }
        return fcollection;
    }
127002
private DefaultFeatureCollection sharedCreateFeatures(
            final LabelPositionCollector labels,
            final SimpleFeatureBuilder featureBuilder,
            final GridParam layerData,
            final MapfishMapContext mapContext,
            final double xSpace, final double ySpace,
            final double minX, final double minY) {
        // CSON: ParameterNumber
        GeometryFactory geometryFactory = new GeometryFactory();

        ReferencedEnvelope bounds = mapContext.toReferencedEnvelope();

        CoordinateReferenceSystem mapCrs = bounds.getCoordinateReferenceSystem();
        String unit = layerData.calculateLabelUnit(mapCrs);
        MathTransform labelTransform = layerData.calculateLabelTransform(mapCrs);

        final AxisDirection direction =
                bounds.getCoordinateReferenceSystem().getCoordinateSystem().getAxis(0).getDirection();
        int numDimensions = bounds.getCoordinateReferenceSystem().getCoordinateSystem().getDimension();
        Polygon rotatedBounds = GridUtils.calculateBounds(mapContext);
        AffineTransform worldToScreenTransform = GridUtils.getWorldToScreenTransform(mapContext);

        DefaultFeatureCollection features = new DefaultFeatureCollection();

        double pointSpacing = bounds.getSpan(1) / layerData.pointsInLine;
        int i = 0;
        for (double x = minX; x < bounds.getMaxX(); x += xSpace) {
            i++;
            final SimpleFeature feature = createFeature(featureBuilder, geometryFactory, layerData,
                                                        direction, numDimensions, pointSpacing, x,
                                                        bounds.getMinimum(1), i, 1);
            features.add(feature);
            GridUtils.topBorderLabel(labels, geometryFactory, rotatedBounds, unit, x,
                                     worldToScreenTransform, labelTransform, layerData.getGridLabelFormat());
            GridUtils.bottomBorderLabel(labels, geometryFactory, rotatedBounds, unit, x,
                                        worldToScreenTransform, labelTransform,
                                        layerData.getGridLabelFormat());
        }

        pointSpacing = bounds.getSpan(0) / layerData.pointsInLine;
        int j = 0;
        for (double y = minY; y < bounds.getMaxY(); y += ySpace) {
            j++;
            final SimpleFeature feature = createFeature(featureBuilder, geometryFactory, layerData,
                                                        direction, numDimensions, pointSpacing,
                                                        bounds.getMinimum(0), y, j, 0);
            features.add(feature);
            GridUtils.rightBorderLabel(labels, geometryFactory, rotatedBounds, unit, y,
                                       worldToScreenTransform, labelTransform,
                                       layerData.getGridLabelFormat());
            GridUtils.leftBorderLabel(labels, geometryFactory, rotatedBounds, unit, y,
                                      worldToScreenTransform, labelTransform, layerData.getGridLabelFormat());

        }

        return features;
    }
1299912
@PostConstruct
	protected void initFeatures() throws LayerException {
		crs = geoService.getCrs2(layerInfo.getCrs());
		try {
			setFeatureSourceName(layerInfo.getFeatureInfo().getDataSourceName());
			featureModel = new ShapeInMemFeatureModel(getDataStore(), layerInfo.getFeatureInfo().getDataSourceName(),
					geoService.getSridFromCrs(layerInfo.getCrs()), converterService);
			featureModel.setLayerInfo(layerInfo);
			FeatureCollection<SimpleFeatureType, SimpleFeature> col = getFeatureSource().getFeatures();
			FeatureIterator<SimpleFeature> iterator = col.features();
			int lastIndex = 0;
			while (iterator.hasNext()) {
				SimpleFeature feature = iterator.next();
				String id = featureModel.getId(feature);
				features.put(id, feature);
				int intId = Integer.parseInt(id.substring(id.lastIndexOf('.') + 1));
				if (intId > lastIndex) {
					lastIndex = intId;
				}
			}
			iterator.close();
			((ShapeInMemFeatureModel) featureModel).setNextId(++lastIndex);
		} catch (NumberFormatException nfe) {
			throw new LayerException(nfe, ExceptionCode.FEATURE_MODEL_PROBLEM, url);
		} catch (MalformedURLException e) {
			throw new LayerException(e, ExceptionCode.INVALID_SHAPE_FILE_URL, url);
		} catch (IOException ioe) {
			throw new LayerException(ioe, ExceptionCode.CANNOT_CREATE_LAYER_MODEL, url);
		} catch (GeomajasException ge) {
			throw new LayerException(ge, ExceptionCode.CANNOT_CREATE_LAYER_MODEL, url);
		}
	}