Java Code Examples for org.jetbrains.annotations.Contract

The following examples show how to use org.jetbrains.annotations.Contract. These examples are extracted from open source projects. 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 Project: markdown-image-kit   Source File: MarkdownUtils.java    License: MIT License 6 votes vote down vote up
/**
 * 从 mark 中获取图片名称
 *
 * @param mark the mark     必须是正确的 markdown image 标签
 * @return the string
 */
@NotNull
@Contract(pure = true)
public static String getImageName(String mark) {
    String path = getImagePath(mark);
    if(StringUtils.isBlank(path)){
        return "";
    }
    String imageName = "";
    // 设置图片位置类型
    try{
        if (path.startsWith(ImageContents.IMAGE_LOCATION)) {
            imageName = path.substring(path.lastIndexOf("/") + 1);
        } else {
            imageName = path.substring(path.lastIndexOf(File.separator) + 1);
        }
    }catch (Exception e){
        log.trace("get iamge name from path error. path = {}", path);
    }
    return imageName;
}
 
Example 2
Source Project: MineTinker   Source File: ModManager.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * register a new modifier to the list
 *
 * @param mod the modifier instance
 */
@Contract("null -> false")
public boolean register(Modifier mod) {
	if (mod == null) return false;
	if (!allMods.contains(mod)) {
		mod.reload();
		allMods.add(mod);
		if (mod.isAllowed()) {
			mods.add(mod);
			mods.sort(Comparator.comparing(Modifier::getName));
			mod.registerCraftingRecipe();
		}
		if (mod instanceof Listener) { //Enable Events
			Bukkit.getPluginManager().registerEvents((Listener) mod, MineTinker.getPlugin());
		}
		reloadIncompatibilities();
		if (!mod.getSource().equals(MineTinker.getPlugin())) {
			GUIs.reload();
		}
		ChatWriter.logColor(LanguageManager.getString("ModManager.RegisterModifier")
				.replace("%mod", mod.getColor() + mod.getName())
				.replace("%plugin", mod.getSource().getName()));
		return true;
	}
	return false;
}
 
Example 3
Source Project: jimgui   Source File: JImGui.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @param background shouldn't be closed, will close automatically
 */
@Contract
public void setBackground(@NotNull JImVec4 background) {
	if (this.background == background) return;
	this.background.close();
	this.background = background;
}
 
Example 4
Source Project: markdown-image-kit   Source File: SmmsClient.java    License: MIT License 5 votes vote down vote up
/**
 * Gets instance.
 *
 * @return the instance
 */
@Contract(pure = true)
public static SmmsClient getInstance() {
    SmmsClient client = (SmmsClient)OssClient.INSTANCES.get(CloudEnum.SM_MS_CLOUD);
    if(client == null){
        client = SingletonHandler.singleton;
        OssClient.INSTANCES.put(CloudEnum.SM_MS_CLOUD, client);
    }
    return client;
}
 
Example 5
Source Project: markdown-image-kit   Source File: BaiduOssClient.java    License: MIT License 5 votes vote down vote up
/**
 * Gets instance.
 *
 * @return the instance
 */
@Contract(pure = true)
public static BaiduOssClient getInstance() {
    BaiduOssClient client = (BaiduOssClient)OssClient.INSTANCES.get(CloudEnum.BAIDU_CLOUD);
    if(client == null){
        client = BaiduOssClient.SingletonHandler.singleton;
        OssClient.INSTANCES.put(CloudEnum.BAIDU_CLOUD, client);
    }
    return client;
}
 
Example 6
Source Project: evt4j   Source File: Symbol.java    License: MIT License 5 votes vote down vote up
@NotNull
@Contract("_, _ -> new")
public static Symbol of(int id, int precision) {
    if (precision >= 18) {
        throw new IllegalArgumentException("Precision of symbol must be less than 18");
    }

    return new Symbol(id, precision);
}
 
Example 7
Source Project: markdown-image-kit   Source File: TencentOssClient.java    License: MIT License 5 votes vote down vote up
/**
 * Gets instance.
 *
 * @return the instance
 */
@Contract(pure = true)
public static TencentOssClient getInstance() {
    TencentOssClient client = (TencentOssClient) OssClient.INSTANCES.get(CloudEnum.TENCENT_CLOUD);
    if (client == null) {
        client = SingletonHandler.singleton;
        OssClient.INSTANCES.put(CloudEnum.TENCENT_CLOUD, client);
    }
    return client;
}
 
Example 8
Source Project: markdown-image-kit   Source File: WeiboOssClient.java    License: MIT License 5 votes vote down vote up
/**
 * Gets instance.
 *
 * @return the instance
 */
@Contract(pure = true)
public static WeiboOssClient getInstance() {
    WeiboOssClient client = (WeiboOssClient)OssClient.INSTANCES.get(CloudEnum.WEIBO_CLOUD);
    if(client == null){
        client = WeiboOssClient.SingletonHandler.singleton;
        OssClient.INSTANCES.put(CloudEnum.WEIBO_CLOUD, client);
    }
    return client;
}
 
Example 9
Source Project: markdown-image-kit   Source File: OssState.java    License: MIT License 5 votes vote down vote up
/**
 * 获取当前图床的可用状态
 *
 * @param cloudIndex the cloud index
 * @return the boolean
 */
@Contract(pure = true)
public static boolean getStatus(int cloudIndex) {
    if(cloudIndex == CloudEnum.SM_MS_CLOUD.index){
        return true;
    }
    return getStatus(getCloudType(cloudIndex));
}
 
Example 10
Source Project: markdown-image-kit   Source File: OssState.java    License: MIT License 5 votes vote down vote up
/**
 * Gets status.
 *
 * @param cloudEnum the cloud enum
 * @return the status
 */
@Contract(pure = true)
public static boolean getStatus(CloudEnum cloudEnum) {
    MikState state = MikPersistenComponent.getInstance().getState();
    if (cloudEnum == null) {
        return false;
    }

    switch (cloudEnum) {
        case WEIBO_CLOUD:
            return getStatus(state.getWeiboOssState());
        case ALIYUN_CLOUD:
            return getStatus(state.getAliyunOssState());
        case QINIU_CLOUD:
            return getStatus(state.getQiniuOssState());
        case TENCENT_CLOUD:
            return getStatus(state.getTencentOssState());
        case WANGYI_CLOUD:
            return false;
        case BAIDU_CLOUD:
            return false;
        case JINGDONG_CLOUD:
            return false;
        case YOUPAI_CLOUD:
            return false;
        case SM_MS_CLOUD:
            return true;
        case IMGUR_CLOUD:
            return false;
        case U_CLOUD:
            return false;
        case QING_CLOUD:
            return false;
        case CUSTOMIZE:
            return false;
        default:
            return false;
    }
}
 
Example 11
Source Project: evt4j   Source File: EveriPayAction.java    License: MIT License 5 votes vote down vote up
@Contract("_, _, _ -> new")
@NotNull
public static EveriPayAction of(String link, String asset, String payee) {
    EvtLink.ParsedLink parsedLink = EvtLink.parseLink(link, false);

    // sanity control to make sure the link is for everipay
    if (!EvtLink.ParsedLink.isEveriPay(parsedLink)) {
        throw new IllegalArgumentException("Invalid EvtLink: This link is not for everiPay");
    }

    // get symbol from link
    EvtLink.Segment symbolIdSegment = EvtLink.findSegmentByType(parsedLink.getSegments(), 44);

    if (symbolIdSegment == null) {
        throw new IllegalArgumentException("Failed to parse EveriPay link to extract symbolId");
    }

    int symbolId = ByteBuffer.allocate(4).put(symbolIdSegment.getContent()).getInt(0);

    EvtLink.Segment linkId = EvtLink.findSegmentByType(parsedLink.getSegments(), 156);

    if (linkId == null) {
        throw new IllegalArgumentException("Failed to parse EveriPay link to extract linkId");
    }

    return new EveriPayAction(link, Integer.toString(symbolId), Asset.parseFromRawBalance(asset), Address.of(payee),
            Utils.HEX.encode(linkId.getContent()));
}
 
Example 12
Source Project: markdown-image-kit   Source File: ParserUtils.java    License: MIT License 5 votes vote down vote up
/**
 * 解析 ![xxx](yyy)
 *
 * @param text the text
 * @return the map describe = xxx; file = yyy
 */
@NotNull
@Contract("_ -> new")
public static Map<String, String> parseImageTag(String text) {
    int start = text.indexOf("![");
    int end = text.indexOf("]");

    String describe = text.substring(start + 2, end);
    String file = text.substring(text.indexOf("(") + 1, text.indexOf(")"));
    return new HashMap<String, String>(1) {
        {
            put(describe, file);
        }
    };
}
 
Example 13
Source Project: markdown-image-kit   Source File: MarkdownUtils.java    License: MIT License 5 votes vote down vote up
/**
 * 通过文件验证是否为 markdown 且是否可写
 *
 * @param file the file
 * @return the boolean
 */
@Contract("null -> false")
static boolean isValidForFile(PsiFile file) {
    if (file == null) {
        return false;
    }

    if (!isMardownFile(file)) {
        return false;
    }
    // 不可写时按钮不可用
    return file.isWritable();
}
 
Example 14
Source Project: markdown-image-kit   Source File: PasteImageAction.java    License: MIT License 5 votes vote down vote up
@Contract(pure = true)
private Map<Document, List<MarkdownImage>> buildWaitingProcessMap(@NotNull Map.Entry<DataFlavor, Object> entry,
                                                                  Editor editor) {
    Map<Document, List<MarkdownImage>> waitingProcessMap = new HashMap<>(10);
    List<MarkdownImage> markdownImages = new ArrayList<>(10);
    for (Map.Entry<String, InputStream> inputStreamMap : resolveClipboardData(entry).entrySet()) {
        MarkdownImage markdownImage = new MarkdownImage();
        markdownImage.setFileName("");
        markdownImage.setImageName(inputStreamMap.getKey());
        markdownImage.setExtension("");
        markdownImage.setOriginalLineText("");
        markdownImage.setLineNumber(0);
        markdownImage.setLineStartOffset(0);
        markdownImage.setLineEndOffset(0);
        markdownImage.setTitle("");
        markdownImage.setPath("");
        markdownImage.setLocation(ImageLocationEnum.LOCAL);
        markdownImage.setImageMarkType(ImageMarkEnum.ORIGINAL);
        markdownImage.setInputStream(inputStreamMap.getValue());
        markdownImage.setFinalMark("");

        markdownImages.add(markdownImage);
    }
    if(markdownImages.size() > 0){
        waitingProcessMap.put(editor.getDocument(), markdownImages);
    }
    return waitingProcessMap;
}
 
Example 15
Source Project: evt4j   Source File: TransferAction.java    License: MIT License 5 votes vote down vote up
@NotNull
@Contract("_, _, _, _ -> new")
public static TransferAction of(String domain, String tokenName, List<String> to, String memo) {
    List<Address> addresses = new ArrayList<>();

    for (int i = 0; i < to.size(); i++) {
        addresses.add(Address.of(to.get(i)));
    }

    return new TransferAction(domain, tokenName, addresses, memo);
}
 
Example 16
Source Project: evt4j   Source File: EveriPassAction.java    License: MIT License 5 votes vote down vote up
@Contract("_ -> new")
@NotNull
public static EveriPassAction of(String link) {
    EvtLink.ParsedLink parsedLink = EvtLink.parseLink(link, false);

    // sanity control to make sure the link is for everipass
    if (!EvtLink.ParsedLink.isEveriPass(parsedLink)) {
        throw new EvtLinkException("Invalid EvtLink: This link is not for everiPass");
    }

    // get domain
    EvtLink.Segment domainSegment = EvtLink.findSegmentByType(parsedLink.getSegments(), 91);

    if (domainSegment == null) {
        throw new EvtLinkException("Failed to parse EveriPass link to extract \"domain\"");
    }

    // get token name
    EvtLink.Segment tokenSegment = EvtLink.findSegmentByType(parsedLink.getSegments(), 92);

    if (tokenSegment == null) {
        throw new EvtLinkException("Failed to parse EveriPass link to extract \"token name\"");
    }

    String domain = new String(domainSegment.getContent(), StandardCharsets.UTF_8);
    String tokenName = new String(tokenSegment.getContent(), StandardCharsets.UTF_8);

    return new EveriPassAction(link, domain, tokenName);
}
 
Example 17
Source Project: evt4j   Source File: FungibleDetailData.java    License: MIT License 5 votes vote down vote up
@NotNull
@Contract("_ -> new")
public static FungibleDetailData ofRaw(JSONObject raw) {
    Objects.requireNonNull(raw);
    return new FungibleDetailData(PublicKey.of(raw.getString("creator")),
            Permission.ofRaw(raw.getJSONObject("issue")), Address.of(raw.getString("address")),
            raw.getJSONArray("metas"), raw.getString("name"), new DateTime(raw.getString("create_time")),
            Asset.parseFromRawBalance(raw.getString("current_supply")),
            Asset.parseFromRawBalance(raw.getString("total_supply")), raw.getString("sym"),
            Permission.ofRaw(raw.getJSONObject("manage")), raw.getString("sym_name"));
}
 
Example 18
Source Project: jimgui   Source File: JImVec4.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @param color AWT color
 * @return a mutable imgui vec4 instance
 */
@Contract
public static @NotNull MutableJImVec4 fromAWT(@NotNull java.awt.Color color) {
	return new MutableJImVec4(color.getRed() / 256f,
			color.getGreen() / 256f,
			color.getBlue() / 256f,
			color.getAlpha() / 256f);
}
 
Example 19
Source Project: evt4j   Source File: ActionData.java    License: MIT License 4 votes vote down vote up
@NotNull
@Contract("_ -> new")
public static ActionData create(JSONObject raw) {
    Objects.requireNonNull(raw);
    return new ActionData(raw);
}
 
Example 20
Source Project: jimgui   Source File: JImGuiUtil.java    License: Apache License 2.0 4 votes vote down vote up
@Contract(value = "!null -> !null; null -> null", pure = true)
private static @Nullable byte[] getBytesDefaultImpl(@Nullable String text) {
	return text != null ? (text + '\0').getBytes(StandardCharsets.UTF_8) : null;
}
 
Example 21
Source Project: MineTinker   Source File: LanguageManager.java    License: GNU General Public License v3.0 4 votes vote down vote up
/**
 * @return the completeness of the used language file in percent * 100. So range is [0, 10000]
 */
@Contract(pure = true)
public static Long getCompleteness() {
	return completenessPercent;
}
 
Example 22
Source Project: jimgui   Source File: NativeBool.java    License: Apache License 2.0 4 votes vote down vote up
@Override
@Contract
public void deallocateNativeObject() {
	deallocateNativeObject0(nativeObjectPtr);
}
 
Example 23
Source Project: jimgui   Source File: NativeBool.java    License: Apache License 2.0 4 votes vote down vote up
@Override
@Contract(pure = true)
public int hashCode() {
	return Long.hashCode(nativeObjectPtr);
}
 
Example 24
Source Project: markdown-image-kit   Source File: ParserUtils.java    License: MIT License 4 votes vote down vote up
/**
 * 将字符串text中由openToken和closeToken组成的占位符依次替换为args数组中的值
 *
 * @param openToken  the open token     占位符开始
 * @param closeToken the close token    占位符结束
 * @param text       the text           包含占位符的字符串
 * @param args       the args           被替换的参数
 * @return string string
 */
@Contract("_, _, _, null -> param3")
public static String parse(String openToken, String closeToken, String text, Object... args) {
    if (args == null || args.length <= 0) {
        return text;
    }
    int argsIndex = 0;

    if (text == null || text.isEmpty()) {
        return "";
    }
    char[] src = text.toCharArray();
    int offset = 0;
    // search open token
    int start = text.indexOf(openToken, offset);
    if (start == -1) {
        return text;
    }
    final StringBuilder builder = new StringBuilder();
    StringBuilder expression = null;
    while (start > -1) {
        if (start > 0 && src[start - 1] == '\\') {
            // this open token is escaped. remove the backslash and continue.
            builder.append(src, offset, start - offset - 1).append(openToken);
            offset = start + openToken.length();
        } else {
            // found open token. let's search close token.
            if (expression == null) {
                expression = new StringBuilder();
            } else {
                expression.setLength(0);
            }
            builder.append(src, offset, start - offset);
            offset = start + openToken.length();
            int end = text.indexOf(closeToken, offset);
            while (end > -1) {
                if (end > offset && src[end - 1] == '\\') {
                    // this close token is escaped. remove the backslash and continue.
                    expression.append(src, offset, end - offset - 1).append(closeToken);
                    offset = end + closeToken.length();
                    end = text.indexOf(closeToken, offset);
                } else {
                    expression.append(src, offset, end - offset);
                    offset = end + closeToken.length();
                    break;
                }
            }
            if (end == -1) {
                // close token was not found.
                builder.append(src, start, src.length - start);
                offset = src.length;
            } else {
                String value = (argsIndex <= args.length - 1) ?
                               (args[argsIndex] == null ? "" : args[argsIndex].toString()) : expression.toString();
                builder.append(value);
                offset = end + closeToken.length();
                argsIndex++;
            }
        }
        start = text.indexOf(openToken, offset);
    }
    if (offset < src.length) {
        builder.append(src, offset, src.length - offset);
    }
    return builder.toString();
}
 
Example 25
Source Project: jimgui   Source File: JImFontAtlas.java    License: Apache License 2.0 4 votes vote down vote up
/** Do NOT deallocate the returned pointer */
@Contract(pure = true)
public @NotNull NativeShort getGlyphRangesForThai() {
	return new NativeShort(super.getGlyphRangesThai());
}
 
Example 26
Source Project: markdown-image-kit   Source File: UploadWeiboCloudAction.java    License: MIT License 4 votes vote down vote up
@Contract(pure = true)
@Override
protected Icon getIcon() {
    return MikIcons.WEIBO_OSS;
}
 
Example 27
Source Project: markdown-image-kit   Source File: UploadWeiboCloudAction.java    License: MIT License 4 votes vote down vote up
@Contract(pure = true)
@Override
boolean isAvailable() {
    return OssState.getStatus(MikPersistenComponent.getInstance().getState().getWeiboOssState());
}
 
Example 28
Source Project: evt4j   Source File: OkhttpApi.java    License: MIT License 4 votes vote down vote up
@Contract(pure = true)
private String getMethod() {
    return method;
}
 
Example 29
Source Project: MineTinker   Source File: ModManager.java    License: GNU General Public License v3.0 4 votes vote down vote up
/**
 * @param wand the ItemStack
 * @return if the ItemStack is viable as MineTinker-Builderswand
 */
@Contract("null -> false")
public boolean isWandViable(ItemStack wand) {
	return wand != null && DataHandler.hasTag(wand, "identifier_builderswand", PersistentDataType.INTEGER, false);
}
 
Example 30
Source Project: markdown-image-kit   Source File: UploadQiniuCloudAction.java    License: MIT License 4 votes vote down vote up
@Contract(pure = true)
@Override
protected Icon getIcon() {
    return MikIcons.QINIU_OSS;
}