Removes instances from containers during scaling down

@param packingPlanBuilder existing packing plan
@param componentsToScaleDown scale down factor for the components.
557862
private void removeInstancesFromContainers(PackingPlanBuilder packingPlanBuilder,
                                             Map<String, Integer> componentsToScaleDown) {

    List<ResourceRequirement> resourceRequirements =
        getSortedInstances(componentsToScaleDown.keySet());

    InstanceCountScorer instanceCountScorer = new InstanceCountScorer();
    ContainerIdScorer containerIdScorer = new ContainerIdScorer(false);

    for (ResourceRequirement resourceRequirement : resourceRequirements) {
      String componentName = resourceRequirement.getComponentName();
      int numInstancesToRemove = -componentsToScaleDown.get(componentName);
      List<Scorer<Container>> scorers = new ArrayList<>();

      scorers.add(new HomogeneityScorer(componentName, true));  // all-same-component containers
      scorers.add(instanceCountScorer);                         // then fewest instances
      scorers.add(new HomogeneityScorer(componentName, false)); // then most homogeneous
      scorers.add(containerIdScorer);                           // then highest container id

      for (int j = 0; j < numInstancesToRemove; j++) {
        packingPlanBuilder.removeInstance(scorers, componentName);
      }
    }
  }
816476
public void unregisterComponentBindingsProvider(ServiceReference reference) {
		log.info("unregisterComponentBindingsProvider");
		String[] resourceTypes = OsgiUtil.toStringArray(reference
				.getProperty(ComponentBindingsProvider.RESOURCE_TYPE_PROP),
				new String[0]);
		for (String resourceType : resourceTypes) {
			if (!this.containsKey(resourceType)) {
				continue;
			}
			get(resourceType).remove(reference);
		}
	}
388739
public PackingPlan repack(PackingPlan currentPackingPlan, Map<String, Integer> componentChanges) {
    PackingPlanBuilder planBuilder = newPackingPlanBuilder(currentPackingPlan);

    // Get the instances using FFD allocation
    try {
      planBuilder = getFFDAllocation(planBuilder, currentPackingPlan, componentChanges);
    } catch (ConstraintViolationException e) {
      throw new PackingException("Could not repack instances into existing packing plan", e);
    }

    return planBuilder.build();
  }
809896
public void removeFeatureTypeStyle(FeatureTypeStyleWrapper ftsW) {
        FeatureTypeStyle fts = ftsW.getFeatureTypeStyle();
        style.featureTypeStyles().remove(fts);
        featureTypeStylesWrapperList.remove(ftsW);
    }
765180
public void removeComponent(Object screenField)
    { // Set up the dependencies

        if (m_iNamePrefix != null)
            m_recThis.getField(m_iNamePrefix).removeComponent(screenField);
        m_recThis.getField(m_iNameFirst).removeComponent(screenField);
        if (m_iNameMiddle != null)
            m_recThis.getField(m_iNameMiddle).removeComponent(screenField);
        m_recThis.getField(m_iNameSur).removeComponent(screenField);
        if (m_iNameSuffix != null)
            m_recThis.getField(m_iNameSuffix).removeComponent(screenField);
        if (m_iNameTitle != null)
            m_recThis.getField(m_iNameTitle).removeComponent(screenField);

        super.removeComponent(screenField);
    }
452065
public void setScalingPlanResources(java.util.Collection<ScalingPlanResource> scalingPlanResources) {
        if (scalingPlanResources == null) {
            this.scalingPlanResources = null;
            return;
        }

        this.scalingPlanResources = new java.util.ArrayList<ScalingPlanResource>(scalingPlanResources);
    }
517674
function destroyComponent(instance) {
            if (util.isFn(instance.destroy) && !instance._destroyed) {
                instance.destroy();
                instance._destroyed = true;
            }
        }
449018
public void removeComponent (BaseComponent comp)
    {
        if (_initers != null && comp instanceof InitComponent) {
            _initers.remove((InitComponent)comp);
        }
        if (_downers != null  && comp instanceof ShutdownComponent) {
            _downers.remove((ShutdownComponent)comp);
        }
    }
434369
public static function cleanComponents()
    {
        foreach (self::$components as $name => $component)
        {
            if ( ! $component->persistence)
            {
                self::$components[$name] = null;
                unset(self::$components[$name]);
            }
        }
    }
830210
protected void destroyOldEngineComponent(ComponentList component) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            SibTr.entry(tc, "destroyOldEngineComponent", component);
        }

        boolean removed = jmeComponents.remove(component);
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            SibTr.debug(tc, "destroyOldEngineComponent, component removed from jmeComponents?", removed);
        }

        JsEngineComponent engineComponent = component.getRef();

        if (_state == STATE_STARTING || _state == STATE_STARTED || _state == STATE_STOPPING || _state == STATE_STOPPING_MEMBER || _state == STATE_FAILED) {
            // Stop engine component
            engineComponent.stop(JsConstants.ME_STOP_IMMEDIATE);
        }

        if (_state != STATE_UNINITIALIZED && _state != STATE_DESTROYED) {
            // Destroy
            engineComponent.destroy();
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            SibTr.exit(tc, "destroyOldEngineComponent");
        }
    }
705376
public void setScalingPolicies(java.util.Collection<AutoScalingPolicyDescription> scalingPolicies) {
        if (scalingPolicies == null) {
            this.scalingPolicies = null;
            return;
        }

        this.scalingPolicies = new java.util.ArrayList<AutoScalingPolicyDescription>(scalingPolicies);
    }
644461
private Optional<PackingPlan.InstancePlan> getAnyInstanceOfComponent(String componentName) {
    for (PackingPlan.InstancePlan instancePlan : this.instances) {
      if (instancePlan.getComponentName().equals(componentName)) {
        return Optional.of(instancePlan);
      }
    }
    return Optional.absent();
  }
34059
public ComponentBuilder moveComponent(final ComponentBuilder builder) {
        if (builder.getAnalysisJobBuilder() != this) {
            builder.getAnalysisJobBuilder().removeComponent(builder);

            // when moving the component to a different scope we need to first
            // reset
            // the prior input
            builder.clearInputColumns();

            addComponent(builder);
            builder.setAnalysisJobBuilder(this);
        }

        return builder;
    }
700815
public void removeOutsideCornerFeatures() {
		if( pairs2D.size() != storagePairs2D.size )
			throw new RuntimeException("This can only be called when all the features have been added");

		pairs2D.remove(11);
		pairs2D.remove(5);
		pairs2D.remove(0);
	}
571587
protected static void removeChildAndPrevious( JComponent root , JComponent target ) {
		int N = root.getComponentCount();

		for (int i = 0; i < N; i++) {
			if( root.getComponent(i) == target ) {
				root.remove(i);
				root.remove(i-1);
				return;
			}
		}
		throw new RuntimeException("Can't find component");
	}
920479
protected void prunePlanAlternatives(List<PlanNode> plans) {
		if (plans.isEmpty()) {
			throw new CompilerException("No plan meeting the requirements could be created @ " + this + ". Most likely reason: Too restrictive plan hints.");
		}
		// shortcut for the simple case
		if (plans.size() == 1) {
			return;
		}
		
		// we can only compare plan candidates that made equal choices
		// at the branching points. for each choice at a branching point,
		// we need to keep the cheapest (wrt. interesting properties).
		// if we do not keep candidates for each branch choice, we might not
		// find branch compatible candidates when joining the branches back.
		
		// for pruning, we are quasi AFTER the node, so in the presence of
		// branches, we need form the per-branch-choice groups by the choice
		// they made at the latest un-joined branching node. Note that this is
		// different from the check for branch compatibility of candidates, as
		// this happens on the input sub-plans and hence BEFORE the node (therefore
		// it is relevant to find the latest (partially) joined branch point.
		
		if (this.openBranches == null || this.openBranches.isEmpty()) {
			prunePlanAlternativesWithCommonBranching(plans);
		} else {
			// partition the candidates into groups that made the same sub-plan candidate
			// choice at the latest unclosed branch point
			
			final OptimizerNode[] branchDeterminers = new OptimizerNode[this.openBranches.size()];
			
			for (int i = 0; i < branchDeterminers.length; i++) {
				branchDeterminers[i] = this.openBranches.get(this.openBranches.size() - 1 - i).getBranchingNode();
			}
			
			// this sorter sorts by the candidate choice at the branch point
			Comparator<PlanNode> sorter = new Comparator<PlanNode>() {
				
				@Override
				public int compare(PlanNode o1, PlanNode o2) {
					for (OptimizerNode branchDeterminer : branchDeterminers) {
						PlanNode n1 = o1.getCandidateAtBranchPoint(branchDeterminer);
						PlanNode n2 = o2.getCandidateAtBranchPoint(branchDeterminer);
						int hash1 = System.identityHashCode(n1);
						int hash2 = System.identityHashCode(n2);

						if (hash1 != hash2) {
							return hash1 - hash2;
						}
					}
					return 0;
				}
			};
			Collections.sort(plans, sorter);
			
			List<PlanNode> result = new ArrayList<PlanNode>();
			List<PlanNode> turn = new ArrayList<PlanNode>();
			
			final PlanNode[] determinerChoice = new PlanNode[branchDeterminers.length];

			while (!plans.isEmpty()) {
				// take one as the determiner
				turn.clear();
				PlanNode determiner = plans.remove(plans.size() - 1);
				turn.add(determiner);
				
				for (int i = 0; i < determinerChoice.length; i++) {
					determinerChoice[i] = determiner.getCandidateAtBranchPoint(branchDeterminers[i]);
				}

				// go backwards through the plans and find all that are equal
				boolean stillEqual = true;
				for (int k = plans.size() - 1; k >= 0 && stillEqual; k--) {
					PlanNode toCheck = plans.get(k);
					
					for (int i = 0; i < branchDeterminers.length; i++) {
						PlanNode checkerChoice = toCheck.getCandidateAtBranchPoint(branchDeterminers[i]);
					
						if (checkerChoice != determinerChoice[i]) {
							// not the same anymore
							stillEqual = false;
							break;
						}
					}
					
					if (stillEqual) {
						// the same
						plans.remove(k);
						turn.add(toCheck);
					}
				}

				// now that we have only plans with the same branch alternatives, prune!
				if (turn.size() > 1) {
					prunePlanAlternativesWithCommonBranching(turn);
				}
				result.addAll(turn);
			}

			// after all turns are complete
			plans.clear();
			plans.addAll(result);
		}
	}
1344176
@SuppressWarnings("unchecked")
    private void removeFormerFacets(UIComponent component)
    {
        List<String> formerFacetNames = (List<String>)component.getAttributes().get(FORMER_FACET_NAMES_SET_ATTR);
        if (formerFacetNames != null)
        {
            for (String facetName : formerFacetNames)
            {
                if (_facetsAdded == null || !_facetsAdded.contains(facetName))
                {
                    component.getFacets().remove(facetName);
                }
            }
            if (_facetsAdded == null)
            {
                component.getAttributes().remove(FORMER_FACET_NAMES_SET_ATTR);
            }
            else
            {
                component.getAttributes().put(FORMER_FACET_NAMES_SET_ATTR, _facetsAdded);
            }
        }
        else
        {
            if (_facetsAdded != null)
            {
                component.getAttributes().put(FORMER_FACET_NAMES_SET_ATTR, _facetsAdded);
            }
        }
    }