diff --git a/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/builder/SystemBuilder.java b/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/builder/SystemBuilder.java index dc9320626d4c..e5ca10d0fe30 100644 --- a/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/builder/SystemBuilder.java +++ b/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/builder/SystemBuilder.java @@ -123,9 +123,7 @@ public class SystemBuilder { Boolean good = myMethodCache.get(method); if (good != null && good.booleanValue()) { - if (myMethods.get(method) == null) { - myMethods.put(method, method); - } + myMethods.putIfAbsent(method, method); if (parameter != null && myParameters.get(parameter) == null) { myParameters.put(parameter, parameter); diff --git a/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/KeyStrokeMap.java b/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/KeyStrokeMap.java index 81fa01441b16..b2406df8d00c 100644 --- a/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/KeyStrokeMap.java +++ b/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/KeyStrokeMap.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -55,7 +55,7 @@ public class KeyStrokeMap { String symbol = null; int beforeSymbol = -1; - boolean haveSymbol = false; + boolean haveSymbol; KeyStroke symbolStroke = null; if (hasModifiers) { @@ -102,7 +102,7 @@ public class KeyStrokeMap { return KeyStroke.getKeyStroke(symbolStroke.getKeyCode(), modifiers, false); } - private KeyStroke throwUnrecognized(String symbol) { + private static KeyStroke throwUnrecognized(String symbol) { throw new IllegalArgumentException("Unrecoginzed symbol: " + symbol); } @@ -136,8 +136,7 @@ public class KeyStrokeMap { {'\'', KeyEvent.VK_QUOTE, 0,}, {'"', KeyEvent.VK_QUOTE, shift,},}; HashMap map = new HashMap<>(); // Universal mappings - for (int i = 0; i < universalMappings.length; i++) { - int[] entry = universalMappings[i]; + for (int[] entry : universalMappings) { KeyStroke stroke = KeyStroke.getKeyStroke(entry[1], entry[2]); map.put(new Character((char)entry[0]), stroke); } @@ -151,8 +150,7 @@ public class KeyStrokeMap { //} // Basic symbol/punctuation mappings - for (int i = 0; i < mappings.length; i++) { - int[] entry = mappings[i]; + for (int[] entry : mappings) { KeyStroke stroke = KeyStroke.getKeyStroke(entry[1], entry[2]); map.put(new Character((char)entry[0]), stroke); } @@ -164,9 +162,7 @@ public class KeyStrokeMap { stroke = KeyStroke.getKeyStroke(KeyEvent.VK_A + i - 'a', ctrl); Character key = new Character((char)(i - 'a' + 1)); // Make sure we don't overwrite something already there - if (map.get(key) == null) { - map.put(key, stroke); - } + map.putIfAbsent(key, stroke); } // Capitals for (int i = 'A'; i <= 'Z'; i++) { diff --git a/platform/structuralsearch/source/com/intellij/structuralsearch/plugin/replace/impl/ReplacementBuilder.java b/platform/structuralsearch/source/com/intellij/structuralsearch/plugin/replace/impl/ReplacementBuilder.java index 096beb5c3e8d..1161224229fe 100644 --- a/platform/structuralsearch/source/com/intellij/structuralsearch/plugin/replace/impl/ReplacementBuilder.java +++ b/platform/structuralsearch/source/com/intellij/structuralsearch/plugin/replace/impl/ReplacementBuilder.java @@ -1,3 +1,18 @@ +/* + * Copyright 2000-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.intellij.structuralsearch.plugin.replace.impl; import com.intellij.codeInsight.template.Template; @@ -127,9 +142,7 @@ public final class ReplacementBuilder { private static void fill(MatchResult r,Map m) { if (r.getName()!=null) { - if (m.get(r.getName()) == null) { - m.put(r.getName(), r); - } + m.putIfAbsent(r.getName(), r); } if (!r.isScopeMatch() || !r.isMultipleMatch()) { diff --git a/plugins/git4idea/src/git4idea/attributes/GitCheckAttrParser.java b/plugins/git4idea/src/git4idea/attributes/GitCheckAttrParser.java index e7b31b77a5d9..54bd2c66f9c2 100644 --- a/plugins/git4idea/src/git4idea/attributes/GitCheckAttrParser.java +++ b/plugins/git4idea/src/git4idea/attributes/GitCheckAttrParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -55,10 +55,7 @@ public class GitCheckAttrParser { continue; } - if (myAttributes.get(file) == null) { - myAttributes.put(file, new ArrayList<>()); - } - myAttributes.get(file).add(attr); + myAttributes.computeIfAbsent(file, f -> new ArrayList<>()).add(attr); } } diff --git a/plugins/testng/src/com/theoryinpractice/testng/util/TestNGUtil.java b/plugins/testng/src/com/theoryinpractice/testng/util/TestNGUtil.java index 487ddd3706d8..f18214ac5287 100644 --- a/plugins/testng/src/com/theoryinpractice/testng/util/TestNGUtil.java +++ b/plugins/testng/src/com/theoryinpractice/testng/util/TestNGUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -309,8 +309,7 @@ public class TestNGUtil { annotation = AnnotationUtil.findAnnotation(method, test); if (annotation != null) { if (isAnnotatedWithParameter(annotation, parameter, values)) { - if (results.get(psiClass) == null) results.put(psiClass, new LinkedHashSet<>()); - results.get(psiClass).add(method); + results.computeIfAbsent(psiClass, c -> new LinkedHashSet<>()).add(method); } } else { diff --git a/xml/dom-impl/src/com/intellij/util/xml/tree/actions/DomElementsToggleAction.java b/xml/dom-impl/src/com/intellij/util/xml/tree/actions/DomElementsToggleAction.java index 2c442ab2e93c..94c656f4a280 100644 --- a/xml/dom-impl/src/com/intellij/util/xml/tree/actions/DomElementsToggleAction.java +++ b/xml/dom-impl/src/com/intellij/util/xml/tree/actions/DomElementsToggleAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -55,7 +55,7 @@ public class DomElementsToggleAction extends ToggleAction { if(getHiders() == null) DomUtil.getFile(myTreeView.getRootElement()).putUserData(AbstractDomElementNode.TREE_NODES_HIDERS_KEY, new HashMap<>()); - if(getHiders().get(myClass) == null) getHiders().put(myClass, true); + getHiders().putIfAbsent(myClass, true); } @Override