English 中文(简体)
能否确定 Java CharBuffer的立场?
原标题:Is it possible to set the position of a Java CharBuffer?

在我试图做些什么时,可以再次发言。

我想说一刀,但能够进行比较,例如比较。

  • 1 char at position x
  • 2 chars at position x
  • ...
  • n chars at position x

failing that

  • 1 char at position x+1
  • 2 chars at position x+1
  • ...
  • n chars at position x+1

等等

直至我获得配对,即紧急救助。

很容易用一个阵列来这样做,但我希望以某种方法这样做,并返回一个缓冲地带,指数显示下一步开始处理。 我因此认为CharBuffer是解决这一问题的好办法,但我不相信。

EDIT by way of an example - not exactly compile-able code!

主要委员会

List template1 = new List();
List template2 = new List();
String exampleInput = "oneone two";

template1.add ( "one" );
template1.add ( "two" );
template1.add ( "three" );

template2.add ( "one" );
template2.add ( "one" );
template2.add ( "two" );

Set templates = new Set();
templates.add ( template1 );
templates.add ( template2 );

NoisyParser np = new NoisyParser();
np.parse( templates, exampleInput );

NoisyParser

void parse( Set templates, Sting inp ){
     iterate over each template that matches inp{
        find_match( template, inp );
     }
}

boolean find_match( template, inp ) {
    This is where I need the magic to work out if the current element
    in template matches the current position of inp, or inp+1, give or take.
}
最佳回答

<代码>CharBuffer有一个内部指数,根据该指数,你可以相对照,因此符合您的标准。

http://docs.oracle.com/javase/6/docs/api/java/nio/Buffer.html#position%28int%29”rel=“nofollow”Buffer.position(int newPosition)

也可在前标上<代码>符号。


Since classes from the NIO package usually are used for (and ment to be used for) I/O, I encourage you to consider wrapping up a char[] and an int pos in class:

class PositionableCharArray {
    int pos;
    char[] chars;

    ...
    public void setPos(int pos) { ... }
    public char readChar() { return chars[pos++]; }
}
问题回答

Well you could implement this using Buffer.charAt(int) to get characters relative the current position, and Buffer.get() to advance the current position. Or you could use the Buffer operations for manipulating the position.

但我认为,你最好能执行你自己的班级,该班将品格写成<条码>(或<条码>/条码>),并提供进行你所需要的原始业务的方法。 <may> > 可通过<条码>CharBuffer获得一个更富有成效的解决办法,但这种机会是,这种胜利是业绩瓶颈。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签