From 23adaaa2feb548fa2028f7209d0e95c4cf1c21c8 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Tue, 20 Aug 2013 08:19:55 +0200 Subject: [PATCH] + findKeyByName --- .../util/src/com/intellij/openapi/util/Key.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/platform/util/src/com/intellij/openapi/util/Key.java b/platform/util/src/com/intellij/openapi/util/Key.java index f2b25dbc25b0..2c3be898fcc0 100644 --- a/platform/util/src/com/intellij/openapi/util/Key.java +++ b/platform/util/src/com/intellij/openapi/util/Key.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2010 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -16,6 +16,7 @@ package com.intellij.openapi.util; import com.intellij.util.containers.ConcurrentWeakValueIntObjectHashMap; +import com.intellij.util.containers.StripedLockIntObjectConcurrentHashMap; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -33,7 +34,7 @@ import java.util.concurrent.atomic.AtomicInteger; public class Key { private static final AtomicInteger ourKeysCounter = new AtomicInteger(); private final int myIndex = ourKeysCounter.getAndIncrement(); - private final String myName; // for debug purposes only + private final String myName; private static final ConcurrentWeakValueIntObjectHashMap allKeys = new ConcurrentWeakValueIntObjectHashMap(); public Key(@NotNull @NonNls String name) { @@ -102,4 +103,15 @@ public class Key { //noinspection unchecked return (Key)allKeys.get(index); } + + @Nullable + public static Key findKeyByName(String name) { + for (StripedLockIntObjectConcurrentHashMap.IntEntry key : allKeys.entries()) { + if (name.equals(key.getValue().myName)) { + //noinspection unchecked + return key.getValue(); + } + } + return null; + } } \ No newline at end of file