org.jetbrains.annotations.Contract Java Examples

The following examples show how to use org.jetbrains.annotations.Contract. 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: ModManager.java    From MineTinker with 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 #2
Source File: MarkdownUtils.java    From markdown-image-kit with 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 #3
Source File: PasteImageAction.java    From markdown-image-kit with 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 #4
Source File: TencentOssClient.java    From markdown-image-kit with 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 #5
Source File: Symbol.java    From evt4j with 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 #6
Source File: BaiduOssClient.java    From markdown-image-kit with 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 #7
Source File: SmmsClient.java    From markdown-image-kit with 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 #8
Source File: OssState.java    From markdown-image-kit with 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 #9
Source File: WeiboOssClient.java    From markdown-image-kit with 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 #10
Source File: OssState.java    From markdown-image-kit with 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 File: EveriPayAction.java    From evt4j with 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 File: JImVec4.java    From jimgui with 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 #13
Source File: ParserUtils.java    From markdown-image-kit with 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 #14
Source File: MarkdownUtils.java    From markdown-image-kit with 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 #15
Source File: FungibleDetailData.java    From evt4j with 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 #16
Source File: EveriPassAction.java    From evt4j with 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 File: TransferAction.java    From evt4j with 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 #18
Source File: JImGui.java    From jimgui with 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 #19
Source File: MutableJImVec4.java    From jimgui with Apache License 2.0 4 votes vote down vote up
@Contract
public final void setZ(final float newValue) {
	setZ(nativeObjectPtr, newValue);
}
 
Example #20
Source File: MutableJImVec4.java    From jimgui with Apache License 2.0 4 votes vote down vote up
@Contract
public final void setX(final float newValue) {
	setX(nativeObjectPtr, newValue);
}
 
Example #21
Source File: DestroyTokenAction.java    From evt4j with MIT License 4 votes vote down vote up
@NotNull
@Contract("_, _ -> new")
public static DestroyTokenAction of(String domain, String tokenName) {
    return new DestroyTokenAction(domain, tokenName);
}
 
Example #22
Source File: UploadTencentCloudAction.java    From markdown-image-kit with MIT License 4 votes vote down vote up
@Contract(pure = true)
@Override
boolean isAvailable() {
    return OssState.getStatus(MikPersistenComponent.getInstance().getState().getTencentOssState());
}
 
Example #23
Source File: RequestParams.java    From evt4j with MIT License 4 votes vote down vote up
@NotNull
@Contract("_ -> new")
public static RequestParams of(NetParams netParams) {
    return new RequestParams(netParams, () -> "{}");
}
 
Example #24
Source File: JImGui.java    From jimgui with Apache License 2.0 4 votes vote down vote up
/**
 * @return shouldn't be closed, will close automatically
 */
@Contract(pure = true)
public @NotNull JImVec4 getBackground() {
	return background;
}
 
Example #25
Source File: MutableJImVec4.java    From jimgui with Apache License 2.0 4 votes vote down vote up
@Contract
public final void setW(final float newValue) {
	setW(nativeObjectPtr, newValue);
}
 
Example #26
Source File: UpdateFungibleAction.java    From evt4j with MIT License 4 votes vote down vote up
@Contract("_, _, _ -> new")
@NotNull
public static UpdateFungibleAction of(Symbol symbol, @Nullable JSONObject issue, @Nullable JSONObject manage) {
    return new UpdateFungibleAction(symbol, issue != null ? Permission.ofRaw(issue) : null,
            manage != null ? Permission.ofRaw(manage) : null);
}
 
Example #27
Source File: MutableJImVec4.java    From jimgui with Apache License 2.0 4 votes vote down vote up
@Contract
public final void incY(final float increment) {
	incY(nativeObjectPtr, increment);
}
 
Example #28
Source File: MutableJImVec4.java    From jimgui with Apache License 2.0 4 votes vote down vote up
@Contract
public final void incX(final float increment) {
	incX(nativeObjectPtr, increment);
}
 
Example #29
Source File: Signature.java    From evt4j with MIT License 4 votes vote down vote up
@Contract(pure = true)
private ECKey.ECDSASignature get() {
    return signature;
}
 
Example #30
Source File: MutableJImVec4.java    From jimgui with Apache License 2.0 4 votes vote down vote up
@Contract
public final void incW(final float increment) {
	incW(nativeObjectPtr, increment);
}