任何人都可以帮助我并告诉如何将char数组转换为列表,反之亦然.我正在尝试编写一个程序,用户输入一个字符串(例如"Mike is good"),在输出中,每个空格都被"%20"(Ie "Mike%20is%20good")替换.虽然这可以通过多种方式完成,但由于插入和删除在链表中需要O(1)时间,我想用链表进行尝试.我正在寻找将char数组转换为列表,更新列表然后将其转换回来的方法.
public class apples
{
public static void main(String args[])
{
Scanner input = new Scanner(System.in);
StringBuffer sb = new StringBuffer(input.nextLine());
String s = sb.toString();
char[] c = s.toCharArray();
//LinkedList<char> l = new LinkedList<char>(Arrays.asList(c));
/* giving error "Syntax error on token " char",
Dimensions expected after this token"*/
}
}
Run Code Online (Sandbox Code Playgroud)
因此,在这个程序中的用户输入字符串,这是我在我存储StringBuffer,这我先转换为字符串,然后到一个char数组,但我没能获得一个列表l从s.
如果有人可以告诉正确的方法将char数组转换为列表,反之亦然,我将非常感激.
我需要使用Python将自定义参数添加到URL查询字符串
示例:这是浏览器提取的URL(GET):
/scr.cgi?q=1&ln=0
Run Code Online (Sandbox Code Playgroud)
然后执行一些python命令,因此我需要在浏览器中设置以下URL:
/scr.cgi?q=1&ln=0&SOMESTRING=1
Run Code Online (Sandbox Code Playgroud)
有一些标准方法吗?
我正在玩NIO库.我正在尝试在端口8888上侦听连接,一旦接受连接,就从该通道转储所有内容somefile.
我知道该怎么做ByteBuffers,但我想让它与所谓的超高效工作FileChannel.transferFrom.
这就是我得到的:
ServerSocketChannel ssChannel = ServerSocketChannel.open();
ssChannel.socket().bind(new InetSocketAddress(8888));
SocketChannel sChannel = ssChannel.accept();
FileChannel out = new FileOutputStream("somefile").getChannel();
while (... sChannel has not reached the end of the stream ...) <-- what to put here?
out.transferFrom(sChannel, out.position(), BUF_SIZE);
out.close();
Run Code Online (Sandbox Code Playgroud)
所以,我的问题是:如何表达" transferFrom某个频道,直到到达流末端"?
编辑:将1024更改为BUF_SIZE,因为所使用的缓冲区大小与问题无关.
为使用jersey-test-framework-provider-inmemoryh2数据库和org.springframework.jdbc.core.JdbcTemplate?的Jersey REST API设计和运行e2e集成测试的正确方法是什么?
要求:
测试范围应该是端到端的:从资源开始并通过所有应用程序到h2数据库.
写作测试:
目前我的JUnit集成测试失败,如果从IDE的JUnit一起运行,主要是因为它们相互干扰(与JUnit并发运行).另一个问题是那些应该在每次测试后回滚,使用事务支持(当前@Transactional注释没有任何帮助).支持这种测试所需的最小Spring工具集是什么?如何使它工作?应该@Transactional放在其他地方吗?
例:
@Transactional
public class OrderResourceIT extends JerseyTest {
@Override
protected Application configure() {
// config
}
@Override
protected void configureClient(final ClientConfig config) {
// config
}
@Before
public void startUp(){
// database bootstrap programmatically before each test
}
@Test
@Transactional
public void testGetOrders(){
Response response = target("/orders")
.request()
.get();
List<Order> orders = response.readEntity(new GenericType<List<Order>>(){});
// asserts
}
}
Run Code Online (Sandbox Code Playgroud)
执行:
计划执行maven-failsafe-plugin …
如何检查给定的类是否具有特定字段以及它是否已初始化(此时有值)?
abstract class Player extends GameCahracter {
}
public class Monster extends GameCahracter{
public int level = 1;
}
abstract class GameCharacter{
public void attack(GameCahracter opponent){
if (opponent instanceof Monster && ){ // << here I have to know is it instance of Monster and if it has initialized value
}
}
Run Code Online (Sandbox Code Playgroud) Maven构建成功,但是当我尝试运行它失败时:
Error: Could not find or load main class app.jar
Run Code Online (Sandbox Code Playgroud)
我在resources/META-INF/MANIFEST.MF与
Manifest-Version: 1.0
Main-Class: go.Application
Run Code Online (Sandbox Code Playgroud)
一切似乎都到位了.怎么了?
的pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.5</version>
<configuration>
<archive>
<manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
UPDATE1
使用IntelliJ构建jar工件时也是如此.
UPDATE2
好的,我设法运行它,但现在我有:
Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
Run Code Online (Sandbox Code Playgroud)
UPDATE3
通过添加到Application.java来实现它:
@Bean
public EmbeddedServletContainerFactory servletContainer() {
TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();
return factory;
}
Run Code Online (Sandbox Code Playgroud) 在Jersey Rest应用程序中使用DI时出错:
org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no object available for injection at SystemInjecteeImpl(requiredType=PricingService,parent=PricingResource,qualifiers={},position=0,optional=false,self=false,unqualified=null,1633188703)
Run Code Online (Sandbox Code Playgroud)
我对这个概念很陌生,看起来很复杂,因为有些例子似乎已被弃用了.据我所知,有几种方法可以使DI工作:原生HK2,Spring/HK2 Bridge.什么是更简单,更直接的配置?如何为Jersey 2.x以编程方式(而不是XML的粉丝)进行设置?
ResourceConfig
import org.glassfish.jersey.server.ResourceConfig;
public class ApplicationConfig extends ResourceConfig {
public ApplicationConfig() {
register(new ApplicationBinder());
packages(true, "api");
}
}
Run Code Online (Sandbox Code Playgroud)
AbstractBinder
public class ApplicationBinder extends AbstractBinder {
@Override
protected void configure() {
bind(PricingService.class).to(PricingService.class).in(Singleton.class);
}
}
Run Code Online (Sandbox Code Playgroud)
PricingResource
@Path("/prices")
public class PricingResource {
private final PricingService pricingService;
@Inject
public PricingResource(PricingService pricingService) {
this.pricingService = pricingService;
}
@GET
@Produces(MediaType.APPLICATION_JSON)
public Collection<Price> findPrices() {
return pricingService.findPrices();
}
}
Run Code Online (Sandbox Code Playgroud)
PricingService
@Singleton
public …Run Code Online (Sandbox Code Playgroud) 我收到错误:
Exception in thread "main" org.hibernate.HibernateException:
Could not obtain transaction-synchronized Session for current thread
Run Code Online (Sandbox Code Playgroud)
主要
ppService.deleteProductPart(cPartId, productId);
Run Code Online (Sandbox Code Playgroud)
@Service( "productPartService")
@Override
public void deleteProductPart(int cPartId, int productId) {
productPartDao.deleteProductPart(cPartId, productId);
}
Run Code Online (Sandbox Code Playgroud)
@Repository( "productPartDAO")
@Override
public void deleteProductPart(ProductPart productPart) {
sessionFactory.getCurrentSession().delete(productPart);
}
@Override
public void deleteProductPart(int cPartId, int productId) {
ProductPart productPart = (ProductPart) sessionFactory.getCurrentSession()
.createCriteria("ProductPart")
.add(Restrictions.eq("part", cPartId))
.add(Restrictions.eq("product", productId)).uniqueResult();
deleteProductPart(productPart);
}
Run Code Online (Sandbox Code Playgroud)
怎么解决?
更新:
如果我修改这样的方法:
@Override
@Transactional
public void deleteProductPart(int cPartId, int productId) {
System.out.println(sessionFactory.getCurrentSession());
}
Run Code Online (Sandbox Code Playgroud)
它返回:
SessionImpl(PersistenceContext[entityKeys=[],collectionKeys=[]];ActionQueue[insertions=[] updates=[] deletions=[] collectionCreations=[] collectionRemovals=[] …Run Code Online (Sandbox Code Playgroud) 当我尝试使用Keytool"C:\ Program Files\Java\jdk1.7.0\bin"生成MD5密钥时,使用以下参数:
C:>"C:\ Program Files\Java\jdk1.7.0\bin\keytool.exe"-list -alias和roiddebugkey -keystore"C:\ Users\user1.android\debug.keystore"-storepass andro id -keypass android androiddebugkey,20.09.2011,PrivateKeyEntry,Huella Digital de Certificado(SHA1):ED:55:7E:68:28:7A:90:28:B1:2F:62:3A:B5:94:06:DD:C4 :6C:D6:20
当我试图提交这个"ED:55:7E:68:28:7A:90:28:B1:2F:62:3A:B5:94:06:DD:C4:6C:D6:20" http://code.google.com/android/maps-api-signup.html的关键- 它不起作用.如何使它工作?为什么我有SHA1而不是MD5?
我需要迭代并删除我的数据存储区的所有记录.我正在使用Google App引擎启动器在本地主机上测试它.怎么做?
当我试图以这种方式删除Person模型中的所有recors时:
qObj = Person.all()
db.delete(qObj)
Run Code Online (Sandbox Code Playgroud)
我收到错误BadValueError: Property y must be a str or unicode instance, not a long
我猜模型数据类型存在冲突.
class Person(db.Model):
name = db.StringProperty()
x = db.StringProperty()
y = db.StringProperty()
group = db.StringProperty()
Run Code Online (Sandbox Code Playgroud)
该领域y = db.StringProperty()以前是y = db.IntegerProperty().此时我需要刷新所有数据库记录.我怎样才能做到这一点?
是否有机会删除存储所有数据库记录的本地文件?