com.intellij.openapi.util.text.StringHash Java Examples

The following examples show how to use com.intellij.openapi.util.text.StringHash. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StringsPool.java    From consulo with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #2
Source File: GeneratedParserUtilBase.java    From Intellij-Dust with MIT License 5 votes vote down vote up
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;
}
 
Example #3
Source File: GeneratedParserUtilBase.java    From intellij-latte with MIT License 4 votes vote down vote up
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;
}
 
Example #4
Source File: GeneratedParserUtilBase.java    From intellij-xquery with Apache License 2.0 4 votes vote down vote up
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;
}
 
Example #5
Source File: TreeState.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
private static String calcType(@Nullable Object userObject) {
  if (userObject == null) return "";
  String name = userObject.getClass().getName();
  return Integer.toHexString(StringHash.murmur(name, 31)) + ":" + StringUtil.getShortName(name);
}
 
Example #6
Source File: UsedColors.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static int hashColor(@Nonnull String name, int colorsCount) {
  return Math.abs(StringHash.murmur(name, 0x55AA)) % colorsCount;
}
 
Example #7
Source File: PatternCompilerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
public LazyPresentablePattern(final Node node) {
  myNode = node;
  myHashCode = StringHash.calc(toString());
}
 
Example #8
Source File: ConsoleRootType.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public String getContentPathName(@Nonnull String id) {
  return Long.toHexString(StringHash.calc(id));
}
 
Example #9
Source File: ConsoleRootType.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public String getHistoryPathName(@Nonnull String id) {
  return Long.toHexString(StringHash.calc(id));
}
 
Example #10
Source File: ConsoleHistoryController.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
private String getOldHistoryFilePath(final String id) {
  String pathName = myRootType.getConsoleTypeId() + Long.toHexString(StringHash.calc(id));
  return ContainerPathManager.get().getSystemPath() + File.separator + "userHistory" + File.separator + pathName + ".hist.xml";
}
 
Example #11
Source File: GeneratedParserUtilBase.java    From consulo with Apache License 2.0 4 votes vote down vote up
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;
}