JAVA Regex Character recognition - jdeveloper

I am using p{L} to accept chinese alphabet in our code, i tested this in eclipse and the system showed success result whereas when the same was used in Oracle Jdeveloper, system is throwing a failure. This is the code snippet, i am using.
Please provide me an answer.
public static final String VALID_CHARACTER_PATTERN = "[\\p{L}0-9_*]*";
public static final boolean hasRestrictedChars(String suspectedString) {
return !suspectedString.matches(VALID_CHARACTER_PATTERN);
}
public static void main(String[] args) {
boolean check = hasRestrictedChars("你好");
if (check)
System.out.println("InValid String");
else {
System.out.println("Perfect");
}
}

Related

Antlr4 Listener subtree check condition

I'm new to Antlr, pardon me for basic question, I'm trying to validate the below statement, like if while_condition contains f_lastmove.. do something The while_condition can have other conditions as well. How can I drill down the while_condition? I'm using Listener Pattern with Golang.
I don't know Go, but in Java you could do something like this:
// In this example, the grammar is called `T.g4`
class WhileLastMoveListener extends TBaseListener {
private boolean insideWhileCondition = false;
#Override
public void enterWhile_condition(TParser.While_conditionContext ctx) {
this.insideWhileCondition = true;
}
#Override
public void exitWhile_condition(TParser.While_conditionContext ctx) {
this.insideWhileCondition = false;
}
#Override
public void enterF_lastmove(TParser.F_lastmoveContext ctx) {
if (this.insideWhileCondition) {
// Found a `f_lastmove` rule inside a while `while_condition`
}
}
}

xpath does't work when using template

Does someone know why xpath does not work? When I use "LG", not template with %s everything works fine.
public static void check(){
String path="\"//span[#class='schema-filter__checkbox-text' and text()='%s']\"";
String way = String.format(path, "LG");
driver.findElement(By.xpath(way); - not working
}
The method didnt work because I set incorrect property.
public class Page{
static WebDriver driver;
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver", "C:\\Users\\....\\drivers\\geckodriver.exe");
driver=new FirefoxDriver(); - I set WebDriver driver=new FirefoxDriver() in the beginning.
.....
.....
}
and also '\' from the template should be removed.
public static void f(){
String path="//span[#class='schema-filter__checkbox-text' and text()='%s']";
String way = String.format(path, "LG");
System.out.println(driver.findElement(By.xpath(way)).getText());
}

Parse Local Datastore e Message "no results found for query"

I am trying to finish this program and i am stuck. This is my first program and now it wont work. I keep getting this error when i add query.fromLocalDatastore(); The code runs fine until i try to get it from the local storage. This is telling me there is nothing there for it to retrieve and i don't know why. When i added my test data it worked fine but when i try to pull data from another table i get the error above. Apparently when i added the test data the server synced with the local datastore. Now it is not. Can someone tell me what I did wrong?
public class DataHolder extends Application {
int age;
#Override
public void onCreate() {
super.onCreate();
Parse.enableLocalDatastore(getApplicationContext());
Parse.initialize(this,key, key);
ParseUser.enableAutomaticUser();
ParseACL defaultACL = new ParseACL();
ParseACL.setDefaultACL(defaultACL, true);
}
public class MainActivity extends ActionBarActivity implements Disclaimer.DisclaimerListener {
protected void continueToRun() {
spinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> adapter, View v, int x, long lng) {
final ParseQuery<ParseObject> query = ParseQuery.getQuery("Phone_Numbers");
query.fromLocalDatastore();
if (x == 1) {
final Intent intent = new Intent(getBaseContext(), Protocol_Template.class);
query.fromLocalDatastore();
query.whereEqualTo("objectId", "uGANULyrdL");
startActivity(intent);
}
}
public class Protocol_Template extends Activity {
DataHolder global;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_protocol__template);
final TextView protocol = (TextView) findViewById(R.id.txt02);
findViewById(R.id.btn2timesUpperLeft);
final ParseQuery<ParseObject> query = ParseQuery.getQuery("Phone_Numbers");
query.fromLocalDatastore();
query.getFirstInBackground(new GetCallback<ParseObject>() {
public void done(ParseObject object, ParseException e) {
if (e == null) {
final String protocols = object.get("PhoneNumber").toString();
protocol.setText(protocols);
} else {
protocol.setText(e.getMessage());
}
}
});
}

Minimal implementation of JavaFX TextInputArea

I'm investigating the best way to write a rich text editor in JavaFX - don't mention the HTMLEditor to me: we've spent literally months hacking at it and I could write reams about why it isn't suitable for our purposes! Choice at the moment is to extend AnchorPane and do all of the layout, navigation etc. from scratch or to extend TextInputArea, which looks as though it would help. Anyone have their own implementation of that or would like to propose a minimal implementation?
FWIW here's a scrap from me:
public class TryPain3 extends TextInputControl {
private AnchorPane rootNode = new AnchorPane();
public TryPain3() {
super(new Content() {
private String text = "";
#Override
public String get(int i, int i1) {
return text.substring(i, i1);
}
#Override
public void insert(int i, String string, boolean bln) {
}
#Override
public void delete(int i, int i1, boolean bln) {
}
#Override
public int length() {
return text.length();
}
#Override
public String get() {
return text;
}
#Override
public void addListener(ChangeListener<? super String> cl) {
}
#Override
public void removeListener(ChangeListener<? super String> cl) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
#Override
public String getValue() {
return text;
}
#Override
public void addListener(InvalidationListener il) {
}
#Override
public void removeListener(InvalidationListener il) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
});
setEditable(true);
Text text1 = new Text("fred was here");
text1.setFont(Font.font("Tahoma", FontWeight.NORMAL, 18));
text1.setTextAlignment(TextAlignment.LEFT);
text1.setFontSmoothingType(FontSmoothingType.LCD);
rootNode.getChildren().add(text1);
setSkin(new TP3Skin(this, rootNode));
}
class TP3Skin implements Skin<TryPain3> {
TryPain3 tp;
Node root;
public TP3Skin(TryPain3 tp, Node root) {
this.tp = tp;
this.root = root;
}
#Override
public TryPain3 getSkinnable() {
return tp;
}
#Override
public Node getNode() {
return root;
}
#Override
public void dispose() {
tp = null;
rootNode = null;
}
}
}
It looks as though the skin is not optional.
Questions I'd like to find out are things like:
how is the UI supposed to be drawn - I'm quite happy to code it from scratch but how to get benefit of calls to forward() as an example
should the UI creation be done in the Skin?
whether the base class deals with things like where to put the cursor if you click on a bit of text
I'm sure other questions will arise from this.
You may want to try next JavaFX 8.0 control TextFlow, which allows aggregation of various text styles. See examples here: https://wikis.oracle.com/display/OpenJDK/Rich+Text+API+Samples
JavaFX 8 is part of JDK8. So you can download developers build here http://jdk8.java.net/download.html and it will include JavaFX and new TextFlow control.

Custom WritableCompare displays object reference as output

I am new to Hadoop and Java, and I feel there is something obvious I am just missing. I am using Hadoop 1.0.3 if that means anything.
My goal for using hadoop is to take a bunch of files and parse them one file at a time (as opposed to line by line). Each file will produce multiple key-values, but context to the other lines is important. The key and value are multi-value/composite, so I have implemented WritableCompare for the key and Writable for the value. Because the processing of each file take a bit of CPU, I want to save the output of the mapper, then run multiple reducers later on.
For the composite keys, I followed [http://stackoverflow.com/questions/12427090/hadoop-composite-key][1]
The problem is, the output is just Java object references as opposed to the composite key and value. Example:
LinkKeyWritable#bd2f9730 LinkValueWritable#8752408c
I am not sure if the problem is related to not reducing the data at all or
Here is my main class:
public static void main(String[] args) throws Exception {
JobConf conf = new JobConf(Parser.class);
conf.setJobName("raw_parser");
conf.setOutputKeyClass(LinkKeyWritable.class);
conf.setOutputValueClass(LinkValueWritable.class);
conf.setMapperClass(RawMap.class);
conf.setNumMapTasks(0);
conf.setInputFormat(PerFileInputFormat.class);
conf.setOutputFormat(TextOutputFormat.class);
PerFileInputFormat.setInputPaths(conf, new Path(args[0]));
FileOutputFormat.setOutputPath(conf, new Path(args[1]));
JobClient.runJob(conf);
}
And my Mapper class:
public class RawMap extends MapReduceBase implements
Mapper {
public void map(NullWritable key, Text value,
OutputCollector<LinkKeyWritable, LinkValueWritable> output,
Reporter reporter) throws IOException {
String json = value.toString();
SerpyReader reader = new SerpyReader(json);
GoogleParser parser = new GoogleParser(reader);
for (String page : reader.getPages()) {
String content = reader.readPageContent(page);
parser.addPage(content);
}
for (Link link : parser.getLinks()) {
LinkKeyWritable linkKey = new LinkKeyWritable(link);
LinkValueWritable linkValue = new LinkValueWritable(link);
output.collect(linkKey, linkValue);
}
}
}
Link is basically a struct of various information that get's split between LinkKeyWritable and LinkValueWritable
LinkKeyWritable:
public class LinkKeyWritable implements WritableComparable<LinkKeyWritable>{
protected Link link;
public LinkKeyWritable() {
super();
link = new Link();
}
public LinkKeyWritable(Link link) {
super();
this.link = link;
}
#Override
public void readFields(DataInput in) throws IOException {
link.batchDay = in.readLong();
link.source = in.readUTF();
link.domain = in.readUTF();
link.path = in.readUTF();
}
#Override
public void write(DataOutput out) throws IOException {
out.writeLong(link.batchDay);
out.writeUTF(link.source);
out.writeUTF(link.domain);
out.writeUTF(link.path);
}
#Override
public int compareTo(LinkKeyWritable o) {
return ComparisonChain.start().
compare(link.batchDay, o.link.batchDay).
compare(link.domain, o.link.domain).
compare(link.path, o.link.path).
result();
}
#Override
public int hashCode() {
return Objects.hashCode(link.batchDay, link.source, link.domain, link.path);
}
#Override
public boolean equals(final Object obj){
if(obj instanceof LinkKeyWritable) {
final LinkKeyWritable o = (LinkKeyWritable)obj;
return Objects.equal(link.batchDay, o.link.batchDay)
&& Objects.equal(link.source, o.link.source)
&& Objects.equal(link.domain, o.link.domain)
&& Objects.equal(link.path, o.link.path);
}
return false;
}
}
LinkValueWritable:
public class LinkValueWritable implements Writable{
protected Link link;
public LinkValueWritable() {
link = new Link();
}
public LinkValueWritable(Link link) {
this.link = new Link();
this.link.type = link.type;
this.link.description = link.description;
}
#Override
public void readFields(DataInput in) throws IOException {
link.type = in.readUTF();
link.description = in.readUTF();
}
#Override
public void write(DataOutput out) throws IOException {
out.writeUTF(link.type);
out.writeUTF(link.description);
}
#Override
public int hashCode() {
return Objects.hashCode(link.type, link.description);
}
#Override
public boolean equals(final Object obj){
if(obj instanceof LinkKeyWritable) {
final LinkKeyWritable o = (LinkKeyWritable)obj;
return Objects.equal(link.type, o.link.type)
&& Objects.equal(link.description, o.link.description);
}
return false;
}
}
I think the answer is in the implementation of the TextOutputFormat. Specifically, the LineRecordWriter's writeObject method:
/**
* Write the object to the byte stream, handling Text as a special
* case.
* #param o the object to print
* #throws IOException if the write throws, we pass it on
*/
private void writeObject(Object o) throws IOException {
if (o instanceof Text) {
Text to = (Text) o;
out.write(to.getBytes(), 0, to.getLength());
} else {
out.write(o.toString().getBytes(utf8));
}
}
As you can see, if your key or value is not a Text object, it calls the toString method on it and writes that out. Since you've left toString unimplemented in your key and value, it's using the Object class's implementation, which is writing out the reference.
I'd say that you should try writing an appropriate toString function or using a different OutputFormat.
It looks like you have a list of objects just like you wanted. You need to implement toString() on your writable if you want a human-readable version printed out instead of an ugly java reference.

Resources