我正在尝试生成一些Ruby代码,它将获取一个字符串并返回一个新的字符串,从其末尾删除了一些x个字符 - 这些可以是实际的字母,数字,空格等.
例如:给出以下字符串
a_string = "a1wer4zx"
我需要一种简单的方法来获得相同的字符串,减去 - 比如说 - 最后3个字符.在上面的例子中,那将是"a1wer".我现在这样做的方式似乎很复杂:
an_array = a_string.split(//,(a_string.length-2))
an_array.pop
new_string = an_array.join
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我试图通过使用where子句与几个不同类型的参数从数据库中检索记录.这是我写的一个简单的方法,我将breedId和gender作为参数传递.
public List<Dog> listByBreedIdAndGender(long breedId, String gender) {
return query("SELECT * FROM dog_entity WHERE breed__id = ? AND gender = ?",
new MapSqlParameterSource(":breedId", breedId)
.addValue(":gender", gender));
}
private List<Dog> query(String sql, MapSqlParameterSource parameters) {
List<Dog> dogs = jdbcTemplate.query(sql, new DogRowMapper(), parameters);
return dogs;
}
Run Code Online (Sandbox Code Playgroud)
我跑了这个方法,但得到了以下异常.任何人都可以让我知道如何将多个参数传递给jdbcTemplate.query(),我是一个新的.
{
timestamp: 1419637479460
status: 500
error: "Internal Server Error"
exception: "org.springframework.dao.TransientDataAccessResourceException"
message: "PreparedStatementCallback; SQL [SELECT * FROM dog_entity WHERE breed__id = ? AND gender = ?]; Invalid argument value: java.io.NotSerializableException; nested exception is java.sql.SQLException: Invalid …Run Code Online (Sandbox Code Playgroud) 我有一个接受Mono作为参数的方法.我想要的只是从中获取实际的String.谷歌搜索,但没有找到答案,除了在Mono对象上调用block(),但它会进行阻塞调用,所以想避免使用block().如果可能,请建议其他方式. 我需要这个String的原因是因为在这个方法中我需要调用另一个方法,比如print()和实际的String值.我明白这很容易,但我是反应式编程的新手.
码:
public String getValue(Mono<String> monoString)
{
// How to get actual String from param monoString
//and call print(String) method
}
public void print(String str)
{
System.out.println(str);
}
Run Code Online (Sandbox Code Playgroud) 据我所知,LinkedHashMap扩展了HashMap,LinkedHashMap.Entry也扩展了HashMap.Entry.
LinkedHashMap有两个主要属性:1)header是LinkedHashMap.Entry节点.2)继承的 表是HashMap.Entry []数组.现在,表中的LinkedHashMap被分配的阵列LinkedHashMap.Entry在运行时,这是由下面方法照顾:
/**
* This override differs from addEntry in that it doesn't resize the
* table or remove the eldest entry.
*/
void createEntry(int hash, K key, V value, int bucketIndex) {
HashMap.Entry<K,V> old = table[bucketIndex];
Entry<K,V> e = new Entry<>(hash, key, value, old);
table[bucketIndex] = e;
e.addBefore(header);
size++;
}
Run Code Online (Sandbox Code Playgroud)
前三行的方法实际上转换HashMap.Entry 到LinkedHashMap.Entry和还保持的引用之后和之前的输入的方式,使得之前的头指向最后一个元素,以便和最后一个元素的后指向头形成圆圈. …
我使用以下命令连接到远程 sftp:
sftp user@host
Run Code Online (Sandbox Code Playgroud)
接下来输入密码后,我收到 sftp 提示,即
sftp>
Run Code Online (Sandbox Code Playgroud)
我的工作是将多个文件从目录 A 移动到目录 B。我可以通过重命名命令来执行此操作,但一次只能移动一个文件。是否有任何命令/语法可以将文件列表从目录 A 移动到目录 B。如下所示:
rename /A/file1 /A/file2 B/
Run Code Online (Sandbox Code Playgroud)
只是补充一下,我必须仅使用 sftp 协议通过命令行来完成此操作,而不是使用 fileZilla 或 wincp 等任何工具。
我在 com.comp.myapp.routes 下的项目中定义了多个路由类。为了测试这些,我正在模拟最终路线并检查/比较收到的交付。
例如说我有以下路线:
public class MyRoute1 extends RouteBuilder {
public void configure() throws Exception {
//Route_1 code
}
}
public class MyRoute2 extends RouteBuilder {
public void configure() throws Exception {
//Route_2 code
}
}
....
...//some route impl
..
public class MyRouteN extends RouteBuilder {
public void configure() throws Exception {
//Route_N code
}
}
Run Code Online (Sandbox Code Playgroud)
现在对于所有这些路由,我编写的测试用例似乎相同。先嘲讽一下。
模拟MyRoute1:
public class MyRoute1_Mock extends RouteBuilder {
public void configure() throws Exception {
from("direct:sampleInput")
.log("Received Message is ${body} and Headers …Run Code Online (Sandbox Code Playgroud) 在我的eclipse中,我创建了一个新项目New - > Other-> Spring - > Spring Template Project - > Spring MVC Project.
在pom我得到以下错误:
在这一行找到了多个注释: - 生命周期配置未涵盖的插件执行:org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile(执行:default-编译,阶段:编译) - CoreException:可以不计算构建计划:插件org.apache.maven.plugins:maven-compiler-plugin:2.5.1或其中一个依赖项无法解析:无法读取org.apache.maven.plugins的工件描述符:maven-compiler -plugin:jar:2.5.1:ArtifactResolutionException:无法传输org.apache.maven.plugins:maven-compiler-plugin:pom:2.5.1来自
repo.maven.apache.org/maven2缓存在本地存储库中,在中心的更新间隔过去或强制更新之前,不会重新尝试解析.原始错误:无法传输工件org.apache.maven.plugins:maven- compiler-plugin:pom:2.5.1 from/to central repo.maven.apache.org/maven2):null to repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-compiler-plugin/2.5.1/maven-compiler-plugin-2.5.1.pom - 生命周期配置未涵盖的插件执行:org.apache.maven.plugins:maven -compiler-plugin:2.5.1:testCompile(执行:default- testCompile,阶段:test-compile) - CoreException:无法计算构建计划:插件org.apache.maven.plugins:maven-compiler-plugin:2.5.1或其中一个依赖项无法解析:无法读取org.apache.maven.plugins的工件描述符:maven-compiler-plugin:jar:2.5.1:ArtifactResolutionException:无法传输工件org.apache.maven.plugins: maven-compiler-plugin:pom:2.5.1 from/to central(repo.maven.apache.org/maven2):null to repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-compiler -plugin/2.5.1 /行家编译-插件-2.5.1.pom
我确实删除了存储库文件夹和Maven - > Update Project.但没有任何效果.
错误来自以下标记:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud) 所述frequencySet()被计算的每个字符的频率String在一个Integer[]包裹成Counter具有被覆盖的equals和哈希码类。此方法应该仅返回集合中的唯一频率,但会添加两个Counter对象。
从打印语句可以看出:hashcode()返回相等的值,并且equals()返回true。
怎么了?
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
String[] a = new String[2];
a[0]="tan";
a[1]="nat";
Set<Counter> s = frequencySet(a);
System.out.println(s.size()); // prints
System.out.println(getFreq(a[0]).equals(getFreq(a[1])) + ":" + getFreq(a[0]).hashcode() + ":" + getFreq(a[1]).hashcode() );
}
public static Set<Counter> frequencySet(String[] strs) {
Set<Counter> set = new HashSet<>();
for(String s: strs){
Counter counter = getFreq(s);
set.add(counter); …Run Code Online (Sandbox Code Playgroud) 我正在解决Palindrome指数问题.问题的难度水平很容易,但我还没有通过所有的测试用例:(.在大多数测试用例中,我得到了超时,令人惊讶的是,一个测试用例也失败了.我搜索了回文检查 - 似乎只有两种方式 -
1. Using StringBuilder reverse() method.
2. Comparing characters till mid of the string length.
Run Code Online (Sandbox Code Playgroud)
我尝试了两种方法但仍然没有成功.
以下是我的尝试:
import java.util.Scanner;
public class PalindromeIndex {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int totalTestCases = Integer.parseInt(scanner.nextLine());
String testString = null;
StringBuffer outputString = new StringBuffer();
for (int i = 0; i < totalTestCases; i++) {
testString = scanner.nextLine();
boolean is0thElementTrue = false;
// One lettered word is always a palindrome so checked that …Run Code Online (Sandbox Code Playgroud) 我用javascript跟随Html文件.这给了我"testCircle未定义"的错误.kinldy帮我解决这个问题.
<html>
<body>
<h1> Testing Object-based Javascipt </h1>
<script type="text/javascript">
function mycircle(x,y,r)
{
this.xcoord=x;
this.ycoord=y;
this.radius=r;
this.area = getArea;
this.getCircumference = function () { return (2 * Math.PI * this.radius ) ; };
}
function getArea()
{
return (Math.PI * this.radius * this.radius);
}
var testCircle = mycircle(3,4,5);
window.alert('The radius of my circle is ' + testCircle.radius);
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
提前致谢....
java ×5
spring-mvc ×2
apache-camel ×1
bash ×1
command ×1
equals ×1
hashcode ×1
hashmap ×1
hashset ×1
javascript ×1
jdbctemplate ×1
junit ×1
lambda ×1
linux ×1
maven-plugin ×1
optimization ×1
palindrome ×1
performance ×1
rename ×1
ruby ×1
set ×1
sftp ×1
spring ×1
unit-testing ×1