Java 类com.intellij.openapi.util.text.StringHash 实例源码

项目:intellij-ce-playground    文件:ClasspathCache.java   
private static int hashFromNameAndLoader(String name, Loader loader, int n) {
  int hash = StringHash.murmur(name, n);
  int i = loader.getIndex();
  while (i > 0) {
    hash = hash * n + ((i % 10) + '0');
    i /= 10;
  }
  return hash;
}
项目:tools-idea    文件:ClasspathCache.java   
private static int hashFromNameAndLoader(String name, Loader loader, int n) {
  int hash = StringHash.murmur(name, n);
  int i = loader.getIndex();
  while (i > 0) {
    hash = hash * n + ((i % 10) + '0');
    i /= 10;
  }
  return hash;
}
项目:DeftIDEA    文件:GeneratedParserUtilBase.java   
private boolean addExpected(StringBuilder sb, int offset, boolean expected) {
    String[] strings = new String[variants.size()];
    long[] hashes = new long[strings.length];
    Arrays.fill(strings, "");
    int count = 0;
    loop: for (Variant variant : expected? variants : unexpected) {
        if (offset == variant.offset) {
            String text = variant.object.toString();
            long hash = StringHash.calc(text);
            for (int i=0; i<count; i++) {
                if (hashes[i] == hash) continue loop;
            }
            hashes[count] = hash;
            strings[count] = text;
            count++;
        }
    }
    Arrays.sort(strings);
    count = 0;
    for (String s : strings) {
        if (s == "") continue;
        if (count++ > 0) {
            if (count > MAX_VARIANTS_TO_DISPLAY) {
                sb.append(" and ...");
                break;
            }
            else {
                sb.append(", ");
            }
        }
        char c = s.charAt(0);
        String displayText = c == '<' || StringUtil.isJavaIdentifierStart(c) ? s : '\'' + s + '\'';
        sb.append(displayText);
    }
    if (count > 1 && count < MAX_VARIANTS_TO_DISPLAY) {
        int idx = sb.lastIndexOf(", ");
        sb.replace(idx, idx + 1, " or");
    }
    return count > 0;
}
项目:consulo    文件:StringsPool.java   
public static String getFromPool(String value) {
  if (value == null) return null;
  if (value.length() == 0) return EMPTY;

  final long hash = StringHash.calc(value);
  String reused = (String) myReusableStrings.get(hash);
  if (reused != null) return reused;
  // new String() is required because value often is passed as substring which has a reference to original char array
  // see {@link String.substring(int, int} method implementation.
  //noinspection RedundantStringConstructorCall
  reused = new String(value);
  myReusableStrings.put(hash, reused);
  return reused;
}
项目:consulo    文件:ClasspathCache.java   
private static int hashFromNameAndLoader(String name, Loader loader, int n) {
  int hash = StringHash.murmur(name, n);
  int i = loader.getIndex();
  while (i > 0) {
    hash = hash * n + ((i % 10) + '0');
    i /= 10;
  }
  return hash;
}
项目:Intellij-Dust    文件:GeneratedParserUtilBase.java   
private boolean addExpected(StringBuilder sb, int offset, boolean expected) {
    String[] strings = new String[variants.size()];
    long[] hashes = new long[strings.length];
    Arrays.fill(strings, "");
    int count = 0;
    loop: for (Variant variant : expected? variants : unexpected) {
        if (offset == variant.offset) {
            String text = variant.object.toString();
            long hash = StringHash.calc(text);
            for (int i=0; i<count; i++) {
                if (hashes[i] == hash) continue loop;
            }
            hashes[count] = hash;
            strings[count] = text;
            count++;
        }
    }
    Arrays.sort(strings);
    count = 0;
    for (String s : strings) {
        if (s == "") continue;
        if (count++ > 0) {
            if (count > MAX_VARIANTS_TO_DISPLAY) {
                sb.append(" and ...");
                break;
            }
            else {
                sb.append(", ");
            }
        }
        char c = s.charAt(0);
        String displayText = c == '<' || StringUtil.isJavaIdentifierStart(c) ? s : '\'' + s + '\'';
        sb.append(displayText);
    }
    if (count > 1 && count < MAX_VARIANTS_TO_DISPLAY) {
        int idx = sb.lastIndexOf(", ");
        sb.replace(idx, idx + 1, " or");
    }
    return count > 0;
}
项目:coqidea    文件:GeneratedParserUtilBase.java   
private boolean addExpected(StringBuilder sb, int offset, boolean expected) {
    String[] strings = new String[variants.size()];
    long[] hashes = new long[strings.length];
    Arrays.fill(strings, "");
    int count = 0;
    loop: for (Variant variant : expected? variants : unexpected) {
        if (offset == variant.offset) {
            String text = variant.object.toString();
            long hash = StringHash.calc(text);
            for (int i=0; i<count; i++) {
                if (hashes[i] == hash) continue loop;
            }
            hashes[count] = hash;
            strings[count] = text;
            count++;
        }
    }
    Arrays.sort(strings);
    count = 0;
    for (String s : strings) {
        if (s == "") continue;
        if (count++ > 0) {
            if (count > MAX_VARIANTS_TO_DISPLAY) {
                sb.append(" and ...");
                break;
            }
            else {
                sb.append(", ");
            }
        }
        char c = s.charAt(0);
        String displayText = c == '<' || StringUtil.isJavaIdentifierStart(c) ? s : '\'' + s + '\'';
        sb.append(displayText);
    }
    if (count > 1 && count < MAX_VARIANTS_TO_DISPLAY) {
        int idx = sb.lastIndexOf(", ");
        sb.replace(idx, idx + 1, " or");
    }
    return count > 0;
}
项目:IntelliFrog    文件:GeneratedParserUtilBase.java   
private boolean addExpected(StringBuilder sb, int offset, boolean expected) {
  String[] strings = new String[variants.size()];
  long[] hashes = new long[strings.length];
  Arrays.fill(strings, "");
  int count = 0;
  loop: for (Variant variant : expected? variants : unexpected) {
    if (offset == variant.offset) {
      String text = variant.object.toString();
      long hash = StringHash.calc(text);
      for (int i=0; i<count; i++) {
        if (hashes[i] == hash) continue loop;
      }
      hashes[count] = hash;
      strings[count] = text;
      count++;
    }
  }
  Arrays.sort(strings);
  count = 0;
  for (String s : strings) {
    if (s == "") continue;
    if (count++ > 0) {
      if (count > MAX_VARIANTS_TO_DISPLAY) {
        sb.append(" and ...");
        break;
      }
      else {
        sb.append(", ");
      }
    }
    char c = s.charAt(0);
    String displayText = c == '<' || StringUtil.isJavaIdentifierStart(c) ? s : '\'' + s + '\'';
    sb.append(displayText);
  }
  if (count > 1 && count < MAX_VARIANTS_TO_DISPLAY) {
    int idx = sb.lastIndexOf(", ");
    sb.replace(idx, idx + 1, " or");
  }
  return count > 0;
}
项目:intellij-ce-playground    文件:PatternCompilerImpl.java   
public LazyPresentablePattern(@NotNull Node node) {
  myNode = node;
  myHashCode = StringHash.calc(toString());
}
项目:intellij-ce-playground    文件:ClasspathCache.java   
private boolean maybeContains(String name, Loader loader) {
  int hash = hashFromNameAndLoader(name, loader, StringHash.murmur(name, SEED));
  int hash2 = hashFromNameAndLoader(name, loader, hash);

  return maybeContains(hash, hash2);
}
项目:intellij-ce-playground    文件:ClasspathCache.java   
private void add(String name, Loader loader) {
  int hash = hashFromNameAndLoader(name, loader, StringHash.murmur(name, SEED));
  int hash2 = hashFromNameAndLoader(name, loader, hash);

  addIt(hash, hash2);
}
项目:intellij-ce-playground    文件:ConsoleRootType.java   
@NotNull
public String getContentPathName(@NotNull String id) {
  return Long.toHexString(StringHash.calc(id));
}
项目:intellij-ce-playground    文件:ConsoleRootType.java   
@NotNull
public String getHistoryPathName(@NotNull String id) {
  return Long.toHexString(StringHash.calc(id));
}
项目:intellij-ce-playground    文件:ConsoleHistoryController.java   
@NotNull
private String getOldHistoryFilePath(final String id) {
  String pathName = myRootType.getConsoleTypeId() + Long.toHexString(StringHash.calc(id));
  return PathManager.getSystemPath() + File.separator + "userHistory" + File.separator + pathName + ".hist.xml";
}
项目:intellij-ce-playground    文件:GeneratedParserUtilBase.java   
private boolean addExpected(StringBuilder sb, int position, boolean expected) {
  MyList<Variant> list = expected ? variants : unexpected;
  String[] strings = new String[list.size()];
  long[] hashes = new long[strings.length];
  Arrays.fill(strings, "");
  int count = 0;
  loop: for (Variant variant : list) {
    if (position == variant.position) {
      String text = variant.object.toString();
      long hash = StringHash.calc(text);
      for (int i=0; i<count; i++) {
        if (hashes[i] == hash) continue loop;
      }
      hashes[count] = hash;
      strings[count] = text;
      count++;
    }
  }
  Arrays.sort(strings);
  count = 0;
  for (String s : strings) {
    if (s.length() == 0) continue;
    if (count++ > 0) {
      if (count > MAX_VARIANTS_TO_DISPLAY) {
        sb.append(" and ...");
        break;
      }
      else {
        sb.append(", ");
      }
    }
    char c = s.charAt(0);
    String displayText = c == '<' || StringUtil.isJavaIdentifierStart(c) ? s : '\'' + s + '\'';
    sb.append(displayText);
  }
  if (count > 1 && count < MAX_VARIANTS_TO_DISPLAY) {
    int idx = sb.lastIndexOf(", ");
    sb.replace(idx, idx + 1, " or");
  }
  return count > 0;
}
项目:coocoo-idea-plugin    文件:GeneratedParserUtilBase.java   
private boolean addExpected(StringBuilder sb, int offset, boolean expected) {
  MyList<Variant> list = expected ? variants : unexpected;
  String[] strings = new String[list.size()];
  long[] hashes = new long[strings.length];
  Arrays.fill(strings, "");
  int count = 0;
  loop: for (Variant variant : list) {
    if (offset == variant.offset) {
      String text = variant.object.toString();
      long hash = StringHash.calc(text);
      for (int i=0; i<count; i++) {
        if (hashes[i] == hash) continue loop;
      }
      hashes[count] = hash;
      strings[count] = text;
      count++;
    }
  }
  Arrays.sort(strings);
  count = 0;
  for (String s : strings) {
    if (s.length() == 0) continue;
    if (count++ > 0) {
      if (count > MAX_VARIANTS_TO_DISPLAY) {
        sb.append(" and ...");
        break;
      }
      else {
        sb.append(", ");
      }
    }
    char c = s.charAt(0);
    String displayText = c == '<' || StringUtil.isJavaIdentifierStart(c) ? s : '\'' + s + '\'';
    sb.append(displayText);
  }
  if (count > 1 && count < MAX_VARIANTS_TO_DISPLAY) {
    int idx = sb.lastIndexOf(", ");
    sb.replace(idx, idx + 1, " or");
  }
  return count > 0;
}
项目:firstspiritlanguagesupport    文件:GeneratedParserUtilBase.java   
private boolean addExpected(StringBuilder sb, int position, boolean expected) {
    MyList<Variant> list = expected ? variants : unexpected;
    String[] strings = new String[list.size()];
    long[] hashes = new long[strings.length];
    Arrays.fill(strings, "");
    int count = 0;
    loop: for (Variant variant : list) {
        if (position == variant.position) {
            String text = variant.object.toString();
            long hash = StringHash.calc(text);
            for (int i=0; i<count; i++) {
                if (hashes[i] == hash) continue loop;
            }
            hashes[count] = hash;
            strings[count] = text;
            count++;
        }
    }
    Arrays.sort(strings);
    count = 0;
    for (String s : strings) {
        if (s.length() == 0) continue;
        if (count++ > 0) {
            if (count > MAX_VARIANTS_TO_DISPLAY) {
                sb.append(" and ...");
                break;
            }
            else {
                sb.append(", ");
            }
        }
        char c = s.charAt(0);
        String displayText = c == '<' || StringUtil.isJavaIdentifierStart(c) ? s : '\'' + s + '\'';
        sb.append(displayText);
    }
    if (count > 1 && count < MAX_VARIANTS_TO_DISPLAY) {
        int idx = sb.lastIndexOf(", ");
        sb.replace(idx, idx + 1, " or");
    }
    return count > 0;
}
项目:tools-idea    文件:PatternCompilerImpl.java   
public LazyPresentablePattern(final Node node) {
  myNode = node;
  myHashCode = StringHash.calc(toString());
}
项目:tools-idea    文件:ClasspathCache.java   
private boolean maybeContains(String name, Loader loader) {
  int hash = hashFromNameAndLoader(name, loader, StringHash.murmur(name, SEED));
  int hash2 = hashFromNameAndLoader(name, loader, hash);

  return maybeContains(hash, hash2);
}
项目:tools-idea    文件:ClasspathCache.java   
private void add(String name, Loader loader) {
  int hash = hashFromNameAndLoader(name, loader, StringHash.murmur(name, SEED));
  int hash2 = hashFromNameAndLoader(name, loader, hash);

  addIt(hash, hash2);
}
项目:tools-idea    文件:ConsoleHistoryController.java   
private String getHistoryFilePath(final String id) {
  return PathManager.getSystemPath() + File.separator +
         "userHistory" + File.separator +
         myType + Long.toHexString(StringHash.calc(id)) + ".hist.xml";
}
项目:tools-idea    文件:GeneratedParserUtilBase.java   
private boolean addExpected(StringBuilder sb, int offset, boolean expected) {
  MyList<Variant> list = expected ? variants : unexpected;
  String[] strings = new String[list.size()];
  long[] hashes = new long[strings.length];
  Arrays.fill(strings, "");
  int count = 0;
  loop: for (Variant variant : list) {
    if (offset == variant.offset) {
      String text = variant.object.toString();
      long hash = StringHash.calc(text);
      for (int i=0; i<count; i++) {
        if (hashes[i] == hash) continue loop;
      }
      hashes[count] = hash;
      strings[count] = text;
      count++;
    }
  }
  Arrays.sort(strings);
  count = 0;
  for (String s : strings) {
    if (s.length() == 0) continue;
    if (count++ > 0) {
      if (count > MAX_VARIANTS_TO_DISPLAY) {
        sb.append(" and ...");
        break;
      }
      else {
        sb.append(", ");
      }
    }
    char c = s.charAt(0);
    String displayText = c == '<' || StringUtil.isJavaIdentifierStart(c) ? s : '\'' + s + '\'';
    sb.append(displayText);
  }
  if (count > 1 && count < MAX_VARIANTS_TO_DISPLAY) {
    int idx = sb.lastIndexOf(", ");
    sb.replace(idx, idx + 1, " or");
  }
  return count > 0;
}
项目:intellij-latte    文件:GeneratedParserUtilBase.java   
private boolean addExpected(StringBuilder sb, int position, boolean expected) {
    MyList<Variant> list = expected ? variants : unexpected;
    String[] strings = new String[list.size()];
    long[] hashes = new long[strings.length];
    Arrays.fill(strings, "");
    int count = 0;
    loop: for (Variant variant : list) {
        if (position == variant.position) {
            String text = variant.object.toString();
            long hash = StringHash.calc(text);
            for (int i=0; i<count; i++) {
                if (hashes[i] == hash) continue loop;
            }
            hashes[count] = hash;
            strings[count] = text;
            count++;
        }
    }
    Arrays.sort(strings);
    count = 0;
    for (String s : strings) {
        if (s.length() == 0) continue;
        if (count++ > 0) {
            if (count > MAX_VARIANTS_TO_DISPLAY) {
                sb.append(" and ...");
                break;
            }
            else {
                sb.append(", ");
            }
        }
        char c = s.charAt(0);
        String displayText = c == '<' || StringUtil.isJavaIdentifierStart(c) ? s : '\'' + s + '\'';
        sb.append(displayText);
    }
    if (count > 1 && count < MAX_VARIANTS_TO_DISPLAY) {
        int idx = sb.lastIndexOf(", ");
        sb.replace(idx, idx + 1, " or");
    }
    return count > 0;
}
项目:intellij-xquery    文件:GeneratedParserUtilBase.java   
private boolean addExpected(StringBuilder sb, int position, boolean expected) {
    MyList<Variant> list = expected ? variants : unexpected;
    String[] strings = new String[list.size()];
    long[] hashes = new long[strings.length];
    Arrays.fill(strings, "");
    int count = 0;
    loop: for (Variant variant : list) {
        if (position == variant.position) {
            String text = variant.object.toString();
            long hash = StringHash.calc(text);
            for (int i=0; i<count; i++) {
                if (hashes[i] == hash) continue loop;
            }
            hashes[count] = hash;
            strings[count] = text;
            count++;
        }
    }
    Arrays.sort(strings);
    count = 0;
    for (String s : strings) {
        if (s.length() == 0) continue;
        if (count++ > 0) {
            if (count > MAX_VARIANTS_TO_DISPLAY) {
                sb.append(" and ...");
                break;
            }
            else {
                sb.append(", ");
            }
        }
        char c = s.charAt(0);
        String displayText = c == '<' || isJavaIdentifierStart(c) ? s : '\'' + s + '\'';
        sb.append(displayText);
    }
    if (count > 1 && count < MAX_VARIANTS_TO_DISPLAY) {
        int idx = sb.lastIndexOf(", ");
        sb.replace(idx, idx + 1, " or");
    }
    return count > 0;
}
项目:consulo    文件:TreeState.java   
private static String calcType(Object userObject) {
  String name = userObject.getClass().getName();
  return Integer.toHexString(StringHash.murmur(name, 31)) + ":" + StringUtil.getShortName(name);
}
项目:consulo    文件:UsedColors.java   
private static int hashColor(@Nonnull String name, int colorsCount) {
  return Math.abs(StringHash.murmur(name, 0x55AA)) % colorsCount;
}
项目:consulo    文件:PatternCompilerImpl.java   
public LazyPresentablePattern(final Node node) {
  myNode = node;
  myHashCode = StringHash.calc(toString());
}
项目:consulo    文件:ClasspathCache.java   
private boolean maybeContains(String name, Loader loader) {
  int hash = hashFromNameAndLoader(name, loader, StringHash.murmur(name, SEED));
  int hash2 = hashFromNameAndLoader(name, loader, hash);

  return maybeContains(hash, hash2);
}
项目:consulo    文件:ClasspathCache.java   
private void add(String name, Loader loader) {
  int hash = hashFromNameAndLoader(name, loader, StringHash.murmur(name, SEED));
  int hash2 = hashFromNameAndLoader(name, loader, hash);

  addIt(hash, hash2);
}
项目:consulo    文件:ConsoleRootType.java   
@Nonnull
public String getContentPathName(@Nonnull String id) {
  return Long.toHexString(StringHash.calc(id));
}
项目:consulo    文件:ConsoleRootType.java   
@Nonnull
public String getHistoryPathName(@Nonnull String id) {
  return Long.toHexString(StringHash.calc(id));
}
项目:consulo    文件:ConsoleHistoryController.java   
@Nonnull
private String getOldHistoryFilePath(final String id) {
  String pathName = myRootType.getConsoleTypeId() + Long.toHexString(StringHash.calc(id));
  return PathManager.getSystemPath() + File.separator + "userHistory" + File.separator + pathName + ".hist.xml";
}
项目:consulo    文件:GeneratedParserUtilBase.java   
private boolean addExpected(StringBuilder sb, int position, boolean expected) {
  MyList<Variant> list = expected ? variants : unexpected;
  String[] strings = new String[list.size()];
  long[] hashes = new long[strings.length];
  Arrays.fill(strings, "");
  int count = 0;
  loop: for (Variant variant : list) {
    if (position == variant.position) {
      String text = variant.object.toString();
      long hash = StringHash.calc(text);
      for (int i=0; i<count; i++) {
        if (hashes[i] == hash) continue loop;
      }
      hashes[count] = hash;
      strings[count] = text;
      count++;
    }
  }
  Arrays.sort(strings);
  count = 0;
  for (String s : strings) {
    if (s.length() == 0) continue;
    if (count++ > 0) {
      if (count > MAX_VARIANTS_TO_DISPLAY) {
        sb.append(" and ...");
        break;
      }
      else {
        sb.append(", ");
      }
    }
    char c = s.charAt(0);
    String displayText = c == '<' || isJavaIdentifierStart(c) ? s : '\'' + s + '\'';
    sb.append(displayText);
  }
  if (count > 1 && count < MAX_VARIANTS_TO_DISPLAY) {
    int idx = sb.lastIndexOf(", ");
    sb.replace(idx, idx + 1, " or");
  }
  return count > 0;
}