How to remove characters after a semicolon as I can't use split() - android-studio

I have the following code, which is returning the following information but I only need the name of the clinic and not the rest of the information. How would I remove them?
Intent secondIntent = getIntent();
final String message = secondIntent.getStringExtra("Add a Review for");
This is producing the following information: Ringwood Family Medical Centre : Shop 19A/59-65 :8842 6200 : 3134
but I only need the name of the clinic and I tried using the following code but there is some kind of error:
message = message.split(":", Integer.parseInt("10"));

Actually, I think String#split might be want you want here:
final String message = secondIntent.getStringExtra("Add a Review for")
.split("\\s*:\\s*")[0];

Related

How to get first String based on whitespace out of a full String using java8?

Let's Example I have String s = "Rahul Kumar" I need to have Rahul as a output using java8
Actual Requirement, I do have a list of Trip Object, I want to set driverName property as only first name to each Trip Object and return that list?
System.out.println( someStringValue.subSequence(0, someStringValue.indexOf(' ')));
I'm getting trouble to incorporate this code into the listOfTrip. If I'm doing like this,
List<CharSequence> list = listOfTrips.stream().map(e -> e.getDriverName().subSequence(0, someStringValue.indexOf(' '))).collect(Collectors.toList()); System.out.println(list);
Here, With this, The return type is wrong and it is not fetching only first name out of full name.
Below will give you the proper result:
List<CharSequence> list2 = listOfTrips.stream()
.map(m->m.getDriverName().substring(0,m.getDriverName().indexOf(' ')))
.collect(Collectors.toList());
Please try this also once:
String s = "Rahul Kumar";
Optional<String> beforeWhiteSpace = Pattern.compile(" ").splitAsStream(s).collect(Collectors.toList()).stream().findFirst();

Error "Failed to construct URI for OData request with request path" SAP Java VDM withQueryParameter

I have create a CAP VDM in java with SAP SDK 3.29.1.
In event handler #On read, i would like to pass the input filters to the VDM.
Es.
#On(event = CdsService.EVENT_READ, entity = "XXXX")
public void readXXX(CdsReadEventContext context) throws ODataException {
final String filter = context.getParameterInfo().getQueryParameter("$filter");
final List<XXXXX> dati = new DefaultXXXService().getAllXXXX().select().withQueryParameter("$filter", filter).executeRequest(dest);
}
When run the query in the log i get the error:
"Failed to construct URI for OData request with request path ..."
"Illegal character in query at index 95. ...."
But the path and filter is right for the call, can you help me?
In the old version sdk i used:
FilterExpression filtriFrontEnd =FilterExpressionConverter.convertTo(queryRequest.getQueryExpression());
final List<XXXX> area = new DefaultXXXXService().getAllXXX().filter(new UncheckedFilterExpression<>(filtriFrontEnd)).select().execute(new ErpConfigContext("XXX"));
Thank you.
When run the query in the log i get the error: "Failed to construct URI for OData request with request path ..." "Illegal character in query at index 95. ...."
Can you check whether the following works for you..?
import com.sap.cloud.sdk.datamodel.odata.client.request.ODataUriFactory;
final String filter = context.getParameterInfo().getQueryParameter("$filter");
final String encodedFilter = ODataUriFactory.encodeQuery(filter);
final List<XXXXX> dati = new DefaultXXXService().getAllXXXX().select().withQueryParameter("$filter", encodedFilter ).executeRequest(dest);
Please let me know, as this could be an issue that needs to be addressed.
The method contract of withQueryParameter which explicitly warns about this API usage:
Using this function to bypass fluent helper method calls can lead to unsupported response handling. There is no contract on the order or priority of parameters added to the query.
Instead please use the filter function directly. There should be an entity field for the postal code, the code should look similar to this:
new DefaultXXXService()
.getAllXXXX()
.filter(Entity.POSTAL_CODE.eq("16100"))
If this is not feasible in your use case I suggest to build this filter expression manually as you did before and apply encoding to it as Alex pointed out in his answer.

Mapping wrong number of parameter from Gherkin features file to step definition

I had feature declaration like this:
Feature: find taxi and minicabs information
in order to get taxi and minicabs contact at given location
as application developer
I want to find tax and minicabs contact information at given location or query options
Scenario Outline: find taxi and minicabs contact information
Given Joe at location with <lat> and <lon>
When get all taxi and minicabs contacts information
Then should see list of taxi and minicabs
And all of them are at location with <lat> and <lon>
Examples:
| lat | lon |
| 51.490075 | -0.133226 |
And I had step definition like this:
#Given("^Joe at location with ([+-]?([0-9]+[.])?[0-9]+) and ([+-]?([0-9]+[.])?[0-9]+)$")
public void joeAtLocationWithLatAndLon(Number lat, Number lon) throws Throwable {
....
}
I expected I can received 2 parameters but Cucumber passed to me 4 parameters.
Error message as below:
with pattern [^Joe at location with ([+-]?([0-9]+[.])?[0-9]+) and ([+-]?([0-9]+[.])?[0-9]+)$] is declared with 2 parameters. However, the gherkin step has 4 arguments [51.490075, 51., -0.133226, 0.].
Do you have any idea about this? btw, I very appreciate if you can explain the way cucumber identify the number of parameters or share me any document about that.
The issue is the two inside brackets inside the regular expression. Using the current regex you will get 2 groups - one the whole "51.490075" and second "51." which matches the exp in the ([0-9]+[.]) part. Thus 4 arguments are created.
Remove the inside brackets and you will get just one argument for each, so two in total.
The next problem you are going to have is cucumber does not know how to transform String to Number class unless you tell it. For this you need to make use of the Transform annotation and create a specific class for this.
import cucumber.api.Transformer;
public class NumberTransformer extends Transformer<Number>{
#Override
public Number transform(String value) {
return Double.parseDouble(value);
}
}
#Given("^Joe at location with ([+-]?[0-9]+[.]?[0-9]+) and ([+-]?[0-9]+[.]?[0-9]+)$")
public void joeAtLocationWithAnd(#Transform(NumberTransformer.class)Number arg1, #Transform(NumberTransformer.class)Number arg2) throws Exception {
System.out.println(arg1);
System.out.println(arg2);
}
For the transforming issue you can also look up xstreams. If you are using cucumber 2, these kind of transformation is easier by using Xstreamconvertor annotation - https://github.com/cucumber/cucumber-jvm/pull/1010

com.google.gdata.util.InvalidEntryException when max-results is in URL

I want to change max-results while retrieving comments of a video from youtube. This is my code :
YouTubeService service = new YouTubeService(
"CLIENT_ID");
String str="http://gdata.youtube.com/feeds/api/videos/"+videoId;
YouTubeQuery youtubeQuery = new YouTubeQuery(new URL(
str));
youtubeQuery.setMaxResults(50);
youtubeQuery.setStartIndex(1);
String videoEntryUrl = youtubeQuery.getUrl().toString();
System.out.println(videoEntryUrl+" *************");
VideoEntry videoEntry = service.getEntry(new URL(videoEntryUrl),
VideoEntry.class);
While creating VideoEntry object in the last row, it gives this error :
Exception in thread "main" com.google.gdata.util.InvalidEntryException: The 'max-results' parameter is not supported on this resource
http://schemas.google.com/g/2005'>GDataunsupportedQueryParamThe 'max-results' parameter is not supported on this resource
My code prints the query so when it gives error query is like that :
http://gdata.youtube.com/feeds/api/videos/v_wzBsZLLaE?start-index=1&max-results=40
Why max-results parameter is not supported in this situation?
Greetings
You are requesting video information about one video. So, for 1 video, using start-index and max-results does not make any sense. (If it would be allowed then both can only be 1.)

Flickr api doesn't return the estimated value

I am using flickr api in order to count the how many times a tag occur. I want this information in order to calculate the Normalized Google Distance. I am using this query in my java code:
http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=XXXXXXX&format=json&tags=bank
But i don't get good results. For example when i search "bank" the count value is 357439, when i search "credit" the count value is 59288, but when i am search for "bank credit" the count value is only 2. When i searching with the search box at flickr.com for "bank credit" i get a lot of results. But as far as i can see the query it uses is
http://www.flickr.com/search/?q=bank%20credit
which i am not able to use through my java code. I am trying to pass this
http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=XXXXXXX&format=json&q=bank
and it says
Parameterless searches have been disabled. Please use flickr.photos.getRecent instead
How can i solve this problem?
Your generated url is incorrect
http://api.flickr.com/services/rest/method=flickr.photos.search&api_key=XXXXXXX&format=json&q=bank
is missing the question mark
http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=XXXXXXX&format=json&q=bank
UPDATE based on OP comments:
I didn't see you had the question mark on the top url string. Looking at it again, I did realize you are not passing in any valid parameters. "q" isn't one of the listed parameters on the search api page. Try something like below to search photos with "bank" tag
http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=XXXXXXX&format=json&tags=bank
or one with bank in description/title
http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=XXXXXXX&format=json&text=bank
I got the same error. but when I added media = photos in the parameters, it got resolved.
e.g. :
baseurl = "https://api.flickr.com/services/rest/"
params_d['api_key'] = 'XXXXXXX'
params_d['method'] = 'flickr.photos.search'
params_d['tag'] = "river,mountains"
params_d['tag_mode'] = 'all'
params_d['per_page'] = 5
params_d['media'] = "photos"
params_d['nojsoncallback'] = 1
params_d['format'] = 'json'
resp = requests.get(baseurl, params = params_d)

Resources