[ 
https://issues.apache.org/jira/browse/ZOOKEEPER-4000?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

maoling updated ZOOKEEPER-4000:
-------------------------------
    Description: 
Look at the *Leader#processSync* method:
{code:java}
public synchronized void processSync(LearnerSyncRequest r) {
    if (outstandingProposals.isEmpty()) {
        sendSync(r);
    } else {
        List<LearnerSyncRequest> l = pendingSyncs.get(lastProposed);
        if (l == null) {
            l = new ArrayList<LearnerSyncRequest>();
        }
        l.add(r);
        pendingSyncs.put(lastProposed, l);
    }
}
{code}
we can use the *computeIfAbsent* to make the code more clean and elegant. For 
example(just one line code):
{code:java}
pendingSyncs.computeIfAbsent(lastProposed, k -> new ArrayList<>()).add(r);
{code}

  was:
Look at the *Leader#processSync* method:
{code:java}
public synchronized void processSync(LearnerSyncRequest r) {
    if (outstandingProposals.isEmpty()) {
        sendSync(r);
    } else {
        List<LearnerSyncRequest> l = pendingSyncs.get(lastProposed);
        if (l == null) {
            l = new ArrayList<LearnerSyncRequest>();
        }
        l.add(r);
        pendingSyncs.put(lastProposed, l);
    }
}
{code}
we can use the *computeIfAbsent* to make the code more clean and elegant


> use the computeIfAbsent to simplify the Leader#processSync method
> -----------------------------------------------------------------
>
>                 Key: ZOOKEEPER-4000
>                 URL: https://issues.apache.org/jira/browse/ZOOKEEPER-4000
>             Project: ZooKeeper
>          Issue Type: Improvement
>          Components: server
>            Reporter: maoling
>            Priority: Minor
>              Labels: pull-request-available
>             Fix For: 3.7.0
>
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> Look at the *Leader#processSync* method:
> {code:java}
> public synchronized void processSync(LearnerSyncRequest r) {
>     if (outstandingProposals.isEmpty()) {
>         sendSync(r);
>     } else {
>         List<LearnerSyncRequest> l = pendingSyncs.get(lastProposed);
>         if (l == null) {
>             l = new ArrayList<LearnerSyncRequest>();
>         }
>         l.add(r);
>         pendingSyncs.put(lastProposed, l);
>     }
> }
> {code}
> we can use the *computeIfAbsent* to make the code more clean and elegant. For 
> example(just one line code):
> {code:java}
> pendingSyncs.computeIfAbsent(lastProposed, k -> new ArrayList<>()).add(r);
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to