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; }
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; }
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; }
public LazyPresentablePattern(@NotNull Node node) { myNode = node; myHashCode = StringHash.calc(toString()); }
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); }
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); }
@NotNull public String getContentPathName(@NotNull String id) { return Long.toHexString(StringHash.calc(id)); }
@NotNull public String getHistoryPathName(@NotNull String id) { return Long.toHexString(StringHash.calc(id)); }
@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"; }
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; }
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; }
public LazyPresentablePattern(final Node node) { myNode = node; myHashCode = StringHash.calc(toString()); }
private String getHistoryFilePath(final String id) { return PathManager.getSystemPath() + File.separator + "userHistory" + File.separator + myType + Long.toHexString(StringHash.calc(id)) + ".hist.xml"; }
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; }
private static String calcType(Object userObject) { String name = userObject.getClass().getName(); return Integer.toHexString(StringHash.murmur(name, 31)) + ":" + StringUtil.getShortName(name); }
private static int hashColor(@Nonnull String name, int colorsCount) { return Math.abs(StringHash.murmur(name, 0x55AA)) % colorsCount; }
@Nonnull public String getContentPathName(@Nonnull String id) { return Long.toHexString(StringHash.calc(id)); }
@Nonnull public String getHistoryPathName(@Nonnull String id) { return Long.toHexString(StringHash.calc(id)); }
@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"; }