659 Star 2.2K Fork 804

GVPShardingSphere / Apache ShardingSphere

 / 详情

[初级] 代码重构:使用Lambda表达式重构For循环

Done
Opened this issue  
2021-05-15 16:16

目标

GovernanceMetaDataContexts

简介

使用Java Lambda 表达式重构代码中的For循环,提高代码整洁度

步骤

  1. 找到 GovernanceMetaDataContexts.class
  2. 找到以下代码块:
@Subscribe
    public synchronized void renew(final DisabledStateChangedEvent event) {
        GovernanceSchema governanceSchema = event.getGovernanceSchema();
        Collection<ShardingSphereRule> rules = metaDataContexts.getMetaDataMap().get(governanceSchema.getSchemaName()).getRuleMetaData().getRules();
        for (ShardingSphereRule each : rules) {
            if (each instanceof StatusContainedRule) {
                ((StatusContainedRule) each).updateRuleStatus(new DataSourceNameDisabledEvent(governanceSchema.getDataSourceName(), event.isDisabled()));
            }
        }
    }
@Subscribe
    public synchronized void renew(final PrimaryStateChangedEvent event) {
        GovernanceSchema governanceSchema = event.getGovernanceSchema();
        Collection<ShardingSphereRule> rules = metaDataContexts.getMetaDataMap().get(governanceSchema.getSchemaName()).getRuleMetaData().getRules();
        for (ShardingSphereRule each : rules) {
            if (each instanceof StatusContainedRule) {
                ((StatusContainedRule) each).updateRuleStatus(new PrimaryDataSourceEvent(governanceSchema.getSchemaName(), governanceSchema.getDataSourceName(), event.getPrimaryDataSourceName()));
            }
        }
    }
  1. 使用Lambda表达式替换代码块中的For循环

Comments (0)

Sign in to comment

Status
Assignees
Milestones
Pull Requests
Successfully merging a pull request will close this issue.
Branches
Planed to start   -   Planed to end
-
Top level
Priority
参与者(1)
Java
1
https://gitee.com/Sharding-Sphere/sharding-sphere.git
git@gitee.com:Sharding-Sphere/sharding-sphere.git
Sharding-Sphere
sharding-sphere
Apache ShardingSphere

Search