我在O(n)
时间复杂度方面遇到了问题:
"给定一个数字列表和数字x.查找列表中是否有任何2个数字加起来为x?"
这是我的解决方案:
public class SumMatchResult {
public static void main(String[] args){
int[] numberList = {6,1,8,7,4,6};
int requiredSum = 8;
boolean isSumPresent = checkSumPresentHash(numberList,requiredSum);
if(isSumPresent) {
System.out.println("Numbers exist");
}else {
System.out.println("Numbers donot exist");
}
}
private static boolean checkSumPresentHash(int[] numberList, int requiredSum) {
Map<Integer, Integer> m = new HashMap<Integer,Integer>();
int count = 0;
for(int i=0;i<numberList.length;i++){
m.put(i, numberList[i]);
}
for(int i=0;i<numberList.length;i++){
if(m.containsValue(requiredSum - numberList[i])){
count++;
}
}
if(count>1){
return true;
}
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
我正在使用HashMap.containsValue()
而不是使用HashSet.contains() …
我是JAX-WS的新手,有一件事我不明白.
有很多关于如何设置JAX-WS安全性的教程,但几乎所有情况下BindingProvider.USERNAME_PROPERTY和BindingProvider.PASSWORD_PROPERTY都存储在一些.xml文件中(取决于我认为的容器) - 它们是"硬编码的"那是.这就是我没有得到的.如何通过将BindingProvider.USERNAME_PROPERTY和BindingProvider.PASSWORD_PROPERTY与数据库中的用户名和密码进行比较来验证Web服务客户端?我尝试在客户端设置BindingProvider.USERNAME_PROPERTY和BindingProvider.PASSWORD_PROPERTY,如下所示:
ShopingCartService scs = new ShopingCartService(wsdlURL, name);
ShopingCart sc = scs.getShopingCartPort();
Map<String, Object> requestContext = ((BindingProvider)sc).getRequestContext();
requestContext.put(BindingProvider.USERNAME_PROPERTY, userName);
requestContext.put(BindingProvider.PASSWORD_PROPERTY, password);
sc.someFunctionCall();
Run Code Online (Sandbox Code Playgroud)
然后,在服务器端检索如下:
@Resource
WebServiceContext wsContext;
@WebMethod
public void someFunctionCall() {
MessageContext mc = wsContext.getMessageContext();
mc.get(BindingProvider.USERNAME_PROPERTY);
mc.get(BindingProvider.PASSWORD_PROPERTY);
}
Run Code Online (Sandbox Code Playgroud)
但我总是得到null,我没有在xml中设置任何东西,web服务工作得很好,除了我不能得到那些变量:(
我在java 1.6,tomcat 6和JAX-WS上运行.
任何有关使用数据库中的密码验证用户的帮助都非常感谢,谢谢.
我有这个HashMap:
HashMap<String, Integer> m
Run Code Online (Sandbox Code Playgroud)
它基本上存储任何单词(String)及其频率(整数).以下代码按值排序HashMap:
public static Map<String, Integer> sortByValue(Map<String, Integer> map) {
List<Map.Entry<String, Integer>> list = new LinkedList<Map.Entry<String, Integer>>(map.entrySet());
Collections.sort(list, new Comparator<Map.Entry<String, Integer>>() {
public int compare(Map.Entry<String, Integer> m1, Map.Entry<String, Integer> m2) {
return (m2.getValue()).compareTo(m1.getValue());
}
});
Map<String, Integer> result = new LinkedHashMap<String, Integer>();
for (Map.Entry<String, Integer> entry : list) {
result.put(entry.getKey(), entry.getValue());
}
return result;
}
Run Code Online (Sandbox Code Playgroud)
现在情况已经改变,我有这个:
HashMap<String, doc>;
class doc{
integer freq;
HashMap<String, Double>;
}
Run Code Online (Sandbox Code Playgroud)
我如何按照与sortByValue相同的方法按值对这个HashMap进行排序?
我有一个ListFragment
显示用户创建的项目列表.我有一个ListView
它的id设置为"@android:id/list"和一个TextView
id为"@android:id/empty".
我有一个操作栏按钮来显示片段,以允许用户为列表创建更多条目.这是onOptionsItemSelected()
方法:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Fragment frag = null;
// Right now I only have code for the addCourse() fragment, will add more soon
switch (item.getItemId()) {
case R.id.addCourse:
frag = new AddCourseFragment();
break;
default:
return super.onOptionsItemSelected(item);
}
// The support library is being dumb and replace isn't actually
getFragmentManager().beginTransaction()
.remove(this).add(getId(), frag).addToBackStack(null).commit();
return true;
}
Run Code Online (Sandbox Code Playgroud)
AddCourseFragment代码如下:
public class AddCourseFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, …
Run Code Online (Sandbox Code Playgroud) 我需要在现有的Spring启动Web应用程序中创建报告功能(功能).建议是使用BIRT,我可以将其与spring boot web app集成.
我找到了下面的文章,并且能够在spring boot starter项目中运行报告(使用http://start.spring.io/).这篇文章相当陈旧,帮助我找到了一个有效的例子.https://spring.io/blog/2012/01/30/spring-framework-birt.这篇文章基本上就是我想要的,但是在一个spring boot web app中.
我面临的挑战是使用BIRT查看器运行报告,该查看器具有很好的附加功能.(打印,Expoet数据,PDF,分页等)
我没有像本文所描述的那样使用BIRT找到任何弹簧启动示例.
我的问题是:
是否有其他方法或其他方式在Spring启动Web应用程序中执行报告?(显然不想通过从头开始创建类似BIRT的功能来重新发明轮子,或者如果可能的话,将报告引擎与Web应用程序分开运行)
今天有没有人在Spring Boot Web应用程序中使用BIRT(与观众一起工作),并愿意分享或教育我最好的方法吗?(我试图让JSP页面与spring boot一起工作,但是无法成功...更缺乏经验而不是其他任何东西)
有谁可以帮助我吗.
亲切的问候,Henk
我的布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/tools"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="10dp"
card_view:cardCornerRadius="4dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<FrameLayout
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<de.hdodenhof.circleimageview.CircleImageView xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/profilePic"
android:layout_width="96dp"
android:layout_height="96dp"
android:layout_gravity="center_horizontal"
android:src="@drawable/avatar" />
</FrameLayout>
<RelativeLayout
android:id="@+id/user_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/header">
<ImageView
android:id="@+id/divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:src="@color/contentDividerLine" />
<TextView
android:id="@+id/username"
style="@style/Base.Widget.AppCompat.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_gravity="bottom"
android:drawablePadding="5dp"
android:padding="8dp"
android:text="Name"
android:textColor="@color/Black" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/user_view">
<ImageView
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:src="@color/contentDividerLine" />
<TextView
android:id="@+id/email"
style="@style/Base.Widget.AppCompat.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_gravity="bottom"
android:drawablePadding="5dp"
android:padding="8dp"
android:text="Email" …
Run Code Online (Sandbox Code Playgroud) Java Mission Control(JMC)宣布将从Oracle从JDK 11开始移交给开源社区。但是,JMC没有与OpenJDK11版本捆绑在一起。
我读到JMC将在此处单独下载提供,但没有要下载的版本。Oracle也不再在其页面上提供有关JMC的下载。而且我再也无法在Oracle JDK中找到它。
该源镜像在GitHub上,但也没有要下载的构建版本。
在哪里可以下载Java Mission Control的最新开源许可版本?
我遇到了Spring 3提供的两个注释(@Component和@Configuration)我对它们感到有些困惑.
这是我读到的关于@Component的内容
把这个"context:component"放在bean配置文件中,就意味着,在Spring中启用自动扫描功能.base-package指示存储组件的位置,Spring将扫描此文件夹并找出bean(使用@Component注释)并将其注册到Spring容器中.
所以我想知道@Configuration的用途是什么,如果@Controller将注册我的bean而不需要在spring配置xml文件中声明它们
下面是我正在使用的代码,我提供了一个pdf文件和一个文本文件作为命令行的输入.
import org.pdfbox.cos.COSDocument;
import org.pdfbox.pdfparser.PDFParser;
import org.pdfbox.pdmodel.PDDocument;
import org.pdfbox.pdmodel.PDDocumentInformation;
import org.pdfbox.util.PDFTextStripper;
import java.io.File;
import java.io.FileInputStream;
import java.io.PrintWriter;
public class PDFTextParser {
PDFParser parser;
String parsedText;
PDFTextStripper pdfStripper;
PDDocument pdDoc;
COSDocument cosDoc;
PDDocumentInformation pdDocInfo;
// PDFTextParser Constructor
public PDFTextParser() {
}
// Extract text from PDF Document
String pdftoText(String fileName) {
System.out.println("Parsing text from PDF file " + fileName + "....");
File f = new File(fileName);
if (!f.isFile()) {
System.out.println("File " + fileName + " does not exist.");
return null;
} …
Run Code Online (Sandbox Code Playgroud) 在JUnit 3中,我只是打电话给
suite.addTestSuite( MyTest.class )
Run Code Online (Sandbox Code Playgroud)
但是,如果MyTest是一个不扩展TestCase的JUnit 4测试,则不起作用.我应该怎么做才能创建一套测试?