小编Tia*_*ago的帖子

如何创建具有可变数量参数的函数?

如何在Rust中创建具有可变数量参数的函数?

像这个Java代码:

void foo(String... args) {
    for (String arg : args) {
        System.out.println(arg);
    }
}
Run Code Online (Sandbox Code Playgroud)

variadic-functions rust

34
推荐指数
3
解决办法
1万
查看次数

如何让当前线程进入睡眠状态?

有太多过时的信息,很难找到如何睡觉.我想要类似于这个Java代码的东西:

Thread.sleep(4000);
Run Code Online (Sandbox Code Playgroud)

sleep rust

26
推荐指数
2
解决办法
8946
查看次数

Java 2D加权数据插值

我试图找到一些Java lib,代码示例(或起点)来帮助我弄清楚如何用权重插入2d点列表以生成带有水平曲线的插值.

谷歌搜索我发现有几种算法可以做到这一点,我找到了一些有趣内容的解释.我想要尝试的第一个算法是反距离加权插值.

但有了这些信息,我有一些基本的疑虑:

  • 要生成如下图所示的一张图片,我必须做一个像素矩阵(带有权重),插入数据,将像素组合在一起(按颜色范围)然后连接点确实绘制曲线并放置像这样的参考文本值?

  • 如果我需要做这个像素矩阵,对于一个巨大的插值来说它会非常昂贵,那么我可以做更少的点并使用样条曲线来加入然后创建颜色级别吗?

示例数据:

+-------------------+
|  X  |  Y  | WEIGHT|
+-------------------+
|  2  |  5  |   30  |
|  7  |  3  |   25  |
|  1  |  1  |   10  |
|  5  |  6  |   45  |
|  7  |  9  |   15  |
+-------------------+
Run Code Online (Sandbox Code Playgroud)

示例规则:

  • 00-10之间的值:蓝色
  • 10-20之间的价值:绿色
  • 值在20-30之间:黄色
  • 价值在30-40之间:红色

示例结果:

Shepard插值示例

示例数据,规则和结果不兼容,只是随机的例子来解释我的问题.


这是我的最终测试类:http://pastebin.com/nD6MT8eS

java algorithm interpolation

16
推荐指数
1
解决办法
5499
查看次数

hosting.json可用选项

我在哪里可以找到一些文档,关于文件中哪些选项可用hosting.json?现在我正在使用server.ulrs但我想知道是否可以在其上添加https证书路径/密码.

我的hosting.json:

{
  "server.urls": "http://0.0.0.0:80;https://0.0.0.0:443"
}
Run Code Online (Sandbox Code Playgroud)

我在哪里使用它:

public static void Main(string[] args)
{
    var config = new ConfigurationBuilder()
        .SetBasePath(Directory.GetCurrentDirectory())
        .AddJsonFile("hosting.json", optional: true) // <<<<<<<<< LOADING FILE
        .Build();

    var host = new WebHostBuilder()
        .UseKestrel()
        .UseConfiguration(config) // <<<<<<<<<<< USING IT
        .UseContentRoot(Directory.GetCurrentDirectory())
        .UseIISIntegration()
        .UseStartup<Startup>()
        .Build();

    host.Run();
}
Run Code Online (Sandbox Code Playgroud)

json .net-core asp.net-core

9
推荐指数
1
解决办法
6533
查看次数

通过扩展方法注入DI服务

我正在尝试IStringLocalizer在扩展方法中获取服务实例,这可能吗?关于应如何注射的任何建议?

我的目标是使用名称作为约定来翻译类型。

public static class I18nExtensions
{

    private IStringLocalizer _localizer; // <<< How to inject it?

    public static string GetName(this Type type)
    {
        return _localizer[type.Name].Value;
    }
}
Run Code Online (Sandbox Code Playgroud)

c# extension-methods dependency-injection asp.net-core

7
推荐指数
2
解决办法
4210
查看次数

Java Generics <this ??>

有什么方法可以使用你所使用的类的类型来进行泛型参数吗?例如,我有这个班ServiceNode

public final class ServiceNode<S extends NetworkService> {

    private final S service;
    private final Client client;
    private Object attachment;

    public ServiceNode(S service, Client client) {
        this (service, client, null);
    }

    public ServiceNode(S service, Client client, Object attachment) {
        this.service = service;
        this.client = client;
        this.attachment = attachment;
    }

    public S service() {
        return service;
    }

....

}
Run Code Online (Sandbox Code Playgroud)

这是抽象类的一部分 NetworkService

public abstract class NetworkService {

    private final Set<ServiceNode<?>> registeredNodes = new HashSet<>();

    public final void register(ServiceNode<?> node) {
        registeredNodes.add(node);
    } …
Run Code Online (Sandbox Code Playgroud)

java

5
推荐指数
1
解决办法
824
查看次数

PeriodAxis TimeZone不正确

使用DateAxis它工作正常:

// From: 2/5/13 02:00:00 PM (+1), To: 2/5/13 03:00:00 PM (+1)
// Configuring dataset
Timezone tz = new SimpleTimeZone(1, "Test");
TimeSeriesCollection dataset = new TimeSeriesCollection(tz);
TimeSeries timeSeries = new TimeSeries("Series1");
...
timeSeries.add(new Millisecond(new Date(timestamp1), tz, locale), value1);
timeSeries.add(new Millisecond(new Date(timestamp2), tz, locale), value2);
timeSeries.add(new Millisecond(new Date(timestamp3), tz, locale), value3);
...
// Setting axis timezone
((DateAxis) chart.getXYPlot().getDomainAxis()).setTimeZone(tz);
((DateAxis) chart.getXYPlot().getDomainAxis()).setRange(new DateRange(
           from, to), true, true);
Run Code Online (Sandbox Code Playgroud)

DateAxis图表

但是当我尝试对PeriodAxis执行相同操作时,它会显示不正确的时区.看起来它是从我的电脑获得时区(-3).

// From: 2/5/13 02:00:00 PM (+1), To: 2/5/13 03:00:00 PM (+1) …
Run Code Online (Sandbox Code Playgroud)

java timezone jfreechart

4
推荐指数
1
解决办法
452
查看次数

Java EE 6 - 有状态REST作为有状态会话bean

我正在创建需要有状态的REST Web服务.考虑以下情况:

  1. Web服务执行困难且耗时的计算并返回非常大的结果.因此,此服务仅返回结果数,并且整个结果将保存在有状态bean中的服务器上.
  2. 当结果存在时.客户可以要求提供现有结果的子集.

我试图通过@Stateful会话bean 这样做,但它仍然像@Stateless.现在我想知道它是否可能,因为客户端不接受任何Cookie,因此服务器无法识别它.

是否可以通过REST接收有状态bean?

代码示例:

@Path("/similarity/")
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Stateful
@StatefulTimeout(600000) // 10 minutes
public class SimilarityResource {

    private List<SimilarityResult> savedSimilarityResults = new ArrayList<SimilarityResult>();

    @POST
    @Path("/atom-count/")
    public List<SimilarityResult> atomCountSimilarity(JAXBElement<SimilarityRequestXML> sr) {

        try {
            if (this.savedSimilarityResults.isEmpty()) {

                List<SimilarityResult> similarityResults = acs.findAllSimilar(); // Time consuming

                this.savedSimilarityResults = similarityResults; // Save results
                return similarityResults;
            } else {
                CompoundResponse cr = new CompoundResponse("Hureeey stateful bean works!.", 404);
                throw new WebApplicationException(cr.buildResponse());
            }

        } catch (CompoundSearchException e) { …
Run Code Online (Sandbox Code Playgroud)

java rest web-services web-applications java-ee

3
推荐指数
1
解决办法
5761
查看次数

将结构与String匹配的模式

是否可以匹配String字段?我不能使这个代码工作.

struct Foo {
    x: int,
    y: int,
    str: String
}

pub fn main() {
    let a = Foo { x: 1, y: 2 , str: "Hi".to_string()};
    match a {
        Foo { x: x, y: y, str: "Hi".to_string() } => println!("Found {}, {}", x, y),
        _ => {}
    }
}
Run Code Online (Sandbox Code Playgroud)

给出了这个错误:

<anon>:10:36: 10:37 error: expected one of `,` or `...`, found `.`
<anon>:10         Foo { x: x, y: y, str: "Hi".to_string() } => println!("Found {}, {}", x, y),
                                             ^
Run Code Online (Sandbox Code Playgroud)

string pattern-matching rust

1
推荐指数
1
解决办法
96
查看次数