Source:
<code>private boolean internalValidateAndSetQuota() { if (isInternalExecution()) { return true; } List<QuotaConsumptionParameter> consumptionParameters = new ArrayList<QuotaConsumptionParameter>(); try { switch (this.getActionType().getQuotaDependency()) { case NONE: return true; case STORAGE: addInternalStorageParameters(consumptionParameters); break; case VDS: addInternalVdsParameters(consumptionParameters); break; case BOTH: addInternalStorageParameters(consumptionParameters); addInternalVdsParameters(consumptionParameters); break; } } catch (ClassCastException e) { log.error("Command: " + this.getClass().getName() + ". Quota handling was expected - class does not implement the expected interface"); } QuotaConsumptionParametersWrapper quotaConsumptionParametersWrapper; if (getStoragePool() != null) { quotaConsumptionParametersWrapper = new QuotaConsumptionParametersWrapper( this.getStoragePool(), this.getReturnValue().getCanDoActionMessages(), this); quotaConsumptionParametersWrapper.setParameters(consumptionParameters); } else { quotaConsumptionParametersWrapper = new QuotaConsumptionParametersWrapper( null,this.getReturnValue().getCanDoActionMessages(), this); quotaConsumptionParametersWrapper.setParameters(consumptionParameters); log.error("Command: " + this.getClass().getName() + ". Storage pool is not available for quota calculation. "); } if (!consumptionParameters.isEmpty()) { <START> return QuotaManager.getInstance().consume(quotaConsumptionParametersWrapper); <END> } else { return true; } }</code><technical_language>In general, I prefer singletons a method of getSingleton this method (and MySingleton.getInstance() ) Reason - easier for unit-tests (mocks) if get extend besides canDoAction phase</technical_language>

Target:
private boolean internalValidateAndSetQuota() { if (isInternalExecution()) { return true; } List<QuotaConsumptionParameter> consumptionParameters = new ArrayList<QuotaConsumptionParameter>(); switch (this.getActionType().getQuotaDependency()) { case NONE: return true; case STORAGE: consumptionParameters.addAll(((QuotaStorageDependent) this).getQuotaStorageConsumptionParameters()); break; case VDS: consumptionParameters.addAll(((QuotaVdsDependent) this).getQuotaVdsConsumptionParameters()); break; case BOTH: consumptionParameters.addAll(((QuotaStorageDependent) this).getQuotaStorageConsumptionParameters()); consumptionParameters.addAll(((QuotaVdsDependent) this).getQuotaVdsConsumptionParameters()); break; } QuotaConsumptionParametersWrapper quotaConsumptionParametersWrapper; if (getStoragePool() != null) { quotaConsumptionParametersWrapper = new QuotaConsumptionParametersWrapper( this.getStoragePool(), this.getReturnValue().getCanDoActionMessages(), this); quotaConsumptionParametersWrapper.setParameters(consumptionParameters); } else { quotaConsumptionParametersWrapper = new QuotaConsumptionParametersWrapper( null,this.getReturnValue().getCanDoActionMessages(), this); quotaConsumptionParametersWrapper.setParameters(consumptionParameters); log.error("Command: " + this.getClass().getName() + ". Storage pool is not available for quota calculation. "); } return consumptionParameters.isEmpty() || getQuotaManager().consume(quotaConsumptionParametersWrapper); }