我编写了一个计时器,用于衡量任何多线程应用程序中特定代码的性能.在下面的计时器中,它还将使用x毫秒的数量填充地图.我将使用这张地图作为我的直方图的一部分来进行进一步的分析,比如这几分钟的调用百分比等等.
public static class StopWatch {
public static ConcurrentHashMap<Long, Long> histogram = new ConcurrentHashMap<Long, Long>();
/**
* Creates an instance of the timer and starts it running.
*/
public static StopWatch getInstance() {
return new StopWatch();
}
private long m_end = -1;
private long m_interval = -1;
private final long m_start;
private StopWatch() {
m_start = m_interval = currentTime();
}
/**
* Returns in milliseconds the amount of time that has elapsed since the timer was created. If the
* …Run Code Online (Sandbox Code Playgroud) 我正在尝试从以下common.xsd哪些导入x.xsd和生成类y.xsd.
common.xsd 如下:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import namespace="mynamespace:x" schemaLocation="x.xsd"/>
<xs:import namespace="mynamespace:y" schemaLocation="y.xsd"/>
</xs:schema>
Run Code Online (Sandbox Code Playgroud)
我尝试使用一个绑定文件,该文件指定了由生成的类实现的公共接口.我的绑定文件如下:
jaxb:extensionBindingPrefixes="inheritance" version="2.1">
<jaxb:globalBindings>
<jaxb:javaType name="java.lang.Long" xmlType="xsd:integer"/>
</jaxb:globalBindings>
<jaxb:bindings schemaLocation="common.xsd" node="/xsd:schema">
<jaxb:bindings node="xsd:complexType[@name='Customer']">
<inheritance:implements>jaxb.BaseMessage</inheritance:implements>
<jaxb:class />
</jaxb:bindings>
<jaxb:bindings node="xsd:complexType[@name='Payments']">
<inheritance:implements>jaxb.BaseMessage</inheritance:implements>
<jaxb:class />
</jaxb:bindings>
Run Code Online (Sandbox Code Playgroud)
我试图生成代码,但它抱怨:
[ERROR] XPath evaluation of "xsd:complexType[@name='Customer']" results in empty target node
[ERROR] XPath evaluation of "xsd:complexType[@name='Payments']" results in empty target node
Run Code Online (Sandbox Code Playgroud)
如何定义绑定文件中的节点实际上是在各个外部XSD文件中但不在common.xsd?
我知道您可以使用以下内容导入Java中的Font:
File file = new File(fontPath);
Font font = Font.createFont(Font.TRUETYPE_FONT, file);
// alternative:
// Font font = Font.createFont(Font.TRUETYPE_FONT, new FileInputStream(file));
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
ge.registerFont(font);
Run Code Online (Sandbox Code Playgroud)
然后,您将使用例如font.deriveFont(Font.PLAIN, 20);获得所需的样式和大小.
例
但现在让我们看一下字体的例子Consolas,你有四个TTF文件:
consola.ttf (纯)consolab.ttf (胆大)consolai.ttf (斜体)consolaz.ttf (加粗斜体)当然你可以consola.ttf使用上面描述的方法导入,但是然后使用font.deriveFont(Font.BOLD, 20);与使用不同,consolab.ttf因为简单的字体被简单地转换为看起来像粗体字体.
示例图片
new Font("Consolas", Font.PLAIN, 20);和new Font("Consolas", Font.BOLD, 20);(作为旁注,如果你在系统上安装了字体,你也会得到正确的粗体字体deriveFont(Font.BOLD);):
consola.ttf导入createFont和导出粗体字体(两者的大小都是20,如上例所示):
好吧,安装时不是问题,但我不希望别人有自定义字体,所以我想将TTF放入jar文件,以便我可以在初始化过程中导入它们getResourceAsStream(path).
有没有办法导入所有相关的TTF,然后只是调用,new Font("Custom Font Name", fontStyle, fontSize); …
输入格式
第一行将包含序列中的数字集.号码按升序列出.
边界条件
1 <= M <= 99999字符串S的长度为5至200.
输出格式
第一行将包含缺失的数字M.
输入/输出示例1
输入:12346789
输出:5
输入/输出2输入596597598600601602
输出:599
序列中的序列号为596 597 598 599 600 601 602. 599是缺失的数字
我的Java解决方案是:
我已经使用过split(("?<=\\G..."))等将数字分成一个,两个,三个四个和五个数字.并将数字保存到相应的数组中.然后我检查了数组中两个相邻数字之间的任何差异 - 如果它是一个那么它将调用一个函数来找到丢失的数字.
但问题在于:
输入:
999899991000110002
Run Code Online (Sandbox Code Playgroud)
输出:
10000
Run Code Online (Sandbox Code Playgroud)
顺序是9998 9999 10001 10002.缺失的数字是10000
当从4位数转换为5位数时,如何拆分字符串?有没有更好的方法来解决这个问题?
public void test(Scanner in)
{
String n = in.nextLine();
int n1 = n.length();
System.out.println(n1);
if (n1 % 2 == 0)
{
} else {
n = "0" + n;
}
System.out.println(n);
String[] one = n.split("(?<=\\G.)");
String[] two = n.split("(?<=\\G..)");
String[] …Run Code Online (Sandbox Code Playgroud) 假设我有一个字符串,"Hello World".我想将此字符串的样式更改为BOLD字体,并将所有字符的大小设置为12到18 [pt].之后我想在JLabel和中使用这个字符串JButton.我怎样才能做到这一点?
我一直在尝试在我的机器(Windows 7 64位)上安装64位版本的PostgreSQL 9.2 for Windows并收到此错误:
The environment variable COMPSPEC does not seem to point to the cmd.exe or there is a trailing semi colon present.
我已经以管理员身份安装了它.
我禁用了防病毒软件(Microsoft Security Essentials)和防火墙.
运行:
"%COMSPEC%" /C "echo test ok"
Run Code Online (Sandbox Code Playgroud)
回 test ok
我检查了我的系统环境变量是否有尾随半冒号,我找不到任何东西.
然后我安装了32位版本并设法使用不同的错误消息到达安装结束:Problem running post-install step. Installation may not complete correctly Error reading the C:\Program Files (x86)\PostgreSQL\9.2\data\postgresql.conf但postgresql.conf该目录中没有文件.它确实安装了应用程序,当我尝试连接服务器上的红色X时,它在底部显示失败,并且在输入密码后它将无法连接.
如何连接到此服务器连接?
用于.xsd在Java Eclipse项目中存储文件的常规文件夹是什么?例如,.jars保留在/lib..xsd文件存储在哪里?
我收到以下异常,但无法找到特定于此异常的任何文档:
org.xml.sax.SAXException: Scanner State 24 not Recognized
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:271)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:339)
at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:121)
Run Code Online (Sandbox Code Playgroud)
任何帮助或指向正确资源的指示都会非常有帮助。
这是我渲染JTable并更改行颜色的代码,但它没有在第6列中显示复选框,只显示字符串(true,false).
你能提供解决方案吗?
提前致谢.
public class JLabelRenderer extends JLabel implements TableCellRenderer
{
private MyJTable myTable;
/**
* Creates a Custom JLabel Cell Renderer
* @param t your JTable implmentation that holds the Hashtable to inquire for
* rows and colors to paint.
*/
public JLabelRenderer(MyJTable t)
{
this.myTable = t;
}
/**
* Returns the component used for drawing the cell. This method is
* used to configure the renderer appropriately before drawing.
* see TableCellRenderer.getTableCellRendererComponent(...); for more comments on the …Run Code Online (Sandbox Code Playgroud) 我们已经实现了Java Lucene搜索引擎4.5,我试图搜索内容,即使字段值不区分大小写(例如,如果我搜索名为"Banglore"的城市,我得到一个结果,但是当我搜索一个名字的城市时"banglore"我得到0结果).
我用来StandardAnalyzer分析数据并WildcardQuery匹配一个Like条件(我试过这里没有成功).
我不知道我哪里出错了.我很感激有关修复此区分大小写问题的任何指导.
public SearchHelper
{
Analyzer analyzer;
Directory index;
public IndexSearcher searcher = null;
public IndexWriter indexWriter = null;
public QueryParser parser = null;
private static int hitsPerPage = 100;
/**
* @param indexFileLocation
* @throws IOException
*/
public SearchHelper(String indexFileLocation) throws IOException
{
// this.analyzer =new StandardAnalyzer();
this.analyzer = new CaseStandardAnalyzer();
// analyzer = new ThaiAnalyzer();
this.index = FSDirectory.open(java.nio.file.Paths.get(indexFileLocation));
}
/**
* @param create
* @return
* @throws IOException …Run Code Online (Sandbox Code Playgroud)