Removes instances from containers during scaling down

@param packingPlanBuilder packing plan builder
@param componentsToScaleDown scale down factor for the components.
964793
private void removeInstancesFromContainers(PackingPlanBuilder packingPlanBuilder,
      Map<String, Integer> componentsToScaleDown) {
    for (String componentName : componentsToScaleDown.keySet()) {
      int numInstancesToRemove = -componentsToScaleDown.get(componentName);
      for (int j = 0; j < numInstancesToRemove; j++) {
        removeRRInstance(packingPlanBuilder, componentName);
      }
    }
  }
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;
    }
988510
@Deprecated
    public static void finalizeForDeletion(UIComponent component)
    {
        // remove any existing marks of deletion
        component.getAttributes().remove(MARK_DELETED);

        // finally remove any children marked as deleted
        if (component.getChildCount() > 0)
        {
            for (Iterator<UIComponent> iter = component.getChildren().iterator(); iter.hasNext();)
            {
                UIComponent child = iter.next();
                if (child.getAttributes().containsKey(MARK_DELETED))
                {
                    iter.remove();
                }
            }
        }

        // remove any facets marked as deleted
        if (component.getFacetCount() > 0)
        {
            Map<String, UIComponent> facets = component.getFacets();
            Collection<UIComponent> col = facets.values();
            for (Iterator<UIComponent> itr = col.iterator(); itr.hasNext();)
            {
                UIComponent fc = itr.next();
                if (fc.getAttributes().containsKey(MARK_DELETED))
                {
                    itr.remove();
                }
            }
        }
    }
566038
public void deleteComponent(String componentName) throws IOException {
    String path = RegistryUtils.componentPath(
        user, jstormServiceClass, instanceName,
        componentName);
    registryOperations.delete(path, false);
  }
518097
@Override
  public PackingPlan repack(PackingPlan currentPackingPlan, Map<String, Integer> componentChanges) {
    this.numContainers = currentPackingPlan.getContainers().size();
    resetToFirstContainer();

    int additionalContainers = computeNumAdditionalContainers(componentChanges, currentPackingPlan);
    if (additionalContainers > 0) {
      increaseNumContainers(additionalContainers);
      LOG.info(String.format(
          "Allocated %s additional containers for repack bring the number of containers to %s.",
          additionalContainers, this.numContainers));
    }

    while (true) {
      try {
        PackingPlanBuilder planBuilder = newPackingPlanBuilder(currentPackingPlan);
        planBuilder.updateNumContainers(numContainers);
        planBuilder = getResourceCompliantRRAllocation(planBuilder, componentChanges);

        return planBuilder.build();

      } catch (ConstraintViolationException e) {
        //Not enough containers. Adjust the number of containers.
        LOG.info(String.format(
            "%s Increasing the number of containers to %s and attempting to repack again.",
            e.getMessage(), this.numContainers + 1));
        retryWithAdditionalContainer();
      }
    }
  }
920795
public void remove(JDesktopPaneLayout child)
    {
        if (child.parent != this)
        {
            throw new IllegalArgumentException(
                "Layout is not a child of this layout");
        }
        container.remove(child.container);
    }
716350
private PackingPlanBuilder getFFDAllocation(PackingPlanBuilder packingPlanBuilder,
                                              PackingPlan currentPackingPlan,
                                              Map<String, Integer> componentChanges)
      throws ConstraintViolationException {
    this.numContainers = currentPackingPlan.getContainers().size();

    Map<String, Integer> componentsToScaleDown =
        PackingUtils.getComponentsToScale(componentChanges, PackingUtils.ScalingDirection.DOWN);
    Map<String, Integer> componentsToScaleUp =
        PackingUtils.getComponentsToScale(componentChanges, PackingUtils.ScalingDirection.UP);

    if (!componentsToScaleDown.isEmpty()) {
      removeInstancesFromContainers(packingPlanBuilder, componentsToScaleDown);
    }

    if (!componentsToScaleUp.isEmpty()) {
      assignInstancesToContainers(packingPlanBuilder, componentsToScaleUp);
    }

    return packingPlanBuilder;
  }
246500
private static void doLayout(
            final Graphics2D graphics2d, final ScalebarAttributeValues scalebarParams,
            final ScaleBarRenderSettings settings) {
        final Dimension maxLabelSize = getMaxLabelSize(settings);

        int numSubIntervals = 1;
        if (scalebarParams.subIntervals) {
            numSubIntervals = getNbSubIntervals(
                    settings.getScaleUnit(), settings.getIntervalLengthInWorldUnits(),
                    settings.getIntervalUnit());
        }

        settings.setBarSize(getBarSize(settings));
        settings.setLabelDistance(getLabelDistance(settings));
        settings.setLineWidth(getLineWidth(settings));
        settings.setSize(getSize(scalebarParams, settings, maxLabelSize));
        settings.setMaxLabelSize(maxLabelSize);
        settings.setNumSubIntervals(numSubIntervals);

        ScalebarDrawer drawer = scalebarParams.getType().createDrawer(graphics2d, settings);
        drawer.draw();
    }
705376
public void setScalingPolicies(java.util.Collection<AutoScalingPolicyDescription> scalingPolicies) {
        if (scalingPolicies == null) {
            this.scalingPolicies = null;
            return;
        }

        this.scalingPolicies = new java.util.ArrayList<AutoScalingPolicyDescription>(scalingPolicies);
    }
862093
public void setComponents(java.util.Collection<ResourcePathComponent> components) {
        if (components == null) {
            this.components = null;
            return;
        }

        this.components = new java.util.ArrayList<ResourcePathComponent>(components);
    }
185096
public void setScalingPolicies(java.util.Collection<ScalingPolicy> scalingPolicies) {
        if (scalingPolicies == null) {
            this.scalingPolicies = null;
            return;
        }

        this.scalingPolicies = new java.util.ArrayList<ScalingPolicy>(scalingPolicies);
    }
138943
private void removeRRInstance(PackingPlanBuilder packingPlanBuilder,
                                String componentName) throws RuntimeException {
    List<Scorer<Container>> scorers = new ArrayList<>();
    scorers.add(new HomogeneityScorer(componentName, true));  // all-same-component containers first
    scorers.add(new InstanceCountScorer());                   // then fewest instances
    scorers.add(new HomogeneityScorer(componentName, false)); // then most homogeneous
    scorers.add(new ContainerIdScorer(false));                // then highest container id

    this.containerId = nextContainerId(packingPlanBuilder.removeInstance(scorers, componentName));
  }
1148205
private PackingPlanBuilder getFFDAllocation(PackingPlanBuilder planBuilder)
      throws ConstraintViolationException {
    Map<String, Integer> parallelismMap = TopologyUtils.getComponentParallelism(topology);
    assignInstancesToContainers(planBuilder, parallelismMap);
    return planBuilder;
  }
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);
	}
494386
protected static void removeChildInsidePanel( JComponent root , JComponent target ) {
		int N = root.getComponentCount();

		for (int i = 0; i < N; i++) {
			try {
				JPanel p = (JPanel)root.getComponent(i);
				Component[] children = p.getComponents();
				for (int j = 0; j < children.length; j++) {
					if( children[j] == target ) {
						root.remove(i);
						return;
					}
				}
			}catch( ClassCastException ignore){}
		}
	}
409500
public void removeControlComponent(IControlComponent component)
	{
		if (component.getParent() != this)
			return;

		controlComponents.remove(component);
		component.setParent(null);
	}
255842
protected void removeFromBuildSpec(String builderID) throws CoreException {
        MarkerUtil.removeMarkers(getProject());
        IProjectDescription description = getProject().getDescription();
        ICommand[] commands = description.getBuildSpec();
        for (int i = 0; i < commands.length; ++i) {
            if (commands[i].getBuilderName().equals(builderID)) {
                ICommand[] newCommands = new ICommand[commands.length - 1];
                System.arraycopy(commands, 0, newCommands, 0, i);
                System.arraycopy(commands, i + 1, newCommands, i, commands.length - i - 1);
                description.setBuildSpec(newCommands);
                getProject().setDescription(description, null);
                return;
            }
        }
    }