Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I'm writing a crafting plugin and I need to check if getResult().GetType() is equal to ItemStack, but getType() probably does not accept the ItemStack.
ItemStack its = new ItemStack(Material.getMaterial(s.getInt("item")),
1, (byte) s.getInt("data"));
if(e.getInventory().getResult().getType().equals(its)) { //this don't work
It won't work because e.getInventory().getResult().getType() returns Material object and its in your case is ItemStack object. So if you want to check if just the items' types are equal, you have to write:
if(e.getInventory().getResult().getType().equals(its.getType())) {
//code here
}
or if you want to do such a comparison like you presented in your post you have to compare ItemStack objects as you cannot compare ItemStack object to Material one. Then you have to write something like this:
if(e.getInventory().gtResult().equals(its)) {
//code here
}
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I know that the () in ArrayList<Integer> = new ArrayList<>() can be used to describe the capacity for the ArrayList, but recently I've seen people put ArrayLists in the () of other ArrayLists.
I wasn't able to find the answer from searching on Google multiple times, any ideas?
This is a call to the ArrayList(Collection<T>) constructor. It creates a new array list with the elements of the Collection (e.g., another ArrayList) being passed to the constructor.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
object Test extends App {
val i: Iterable[(String, Long)] = List(("a", 1), ("b", 2))
val sortedMap: SortedMap[String, Long] = i.toList.sortBy(_._2)
}
I don't want to convert Iterable to List/Array etc since it's coming form a jdbc query.
You can't do that. SortedMap sorts by keys, not values.
If you want it sorted by value, you gotta use ListMap, and can't avoid converting to List:
ListMap(i.toList.sortBy(-_._2):_*)
There isn't really too much wrong with converting to list, since you are loading the whole thing in memory anyway. This is faster too, than building a tree one element at a time.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Below is the output of my code...
System.out.println(CompanyStructure.get());
Output: [com.some.spf.b2bac.facilit.api.parameter.GetkingResult$king#2357662d, com.some.spf.b2bac.facilit.api.parameter.GetkingResult$king#633ced71, com.some.spf.b2bac.facilit.api.parameter.GetkingResult$king#312aac03]
I tried to convert to json string.
jsonString = CommonUtil.convertFromEntityToJsonStr(CompanyStructure.get());
System.out.println(jsonString);
Output:[{"customerId":"1"},{"customerId":"2"},{"customerId":"3"}];
I want to fetch all names with the ids 1,2,3 through sql iam using postgresql. how do i fix this?
You get the Object representation of object. To loop though the objects that get() method use a for each:
for (GetkingResult result : CompanyStructure.get()) {
if (result.getId() == 1) // do something
}
Also you can override the toString() method of the GetkingResult object.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have code like this and this is pure java class which does not involve and DB Connections
if(transfer.getAmount().getDestination().getCountryCode().equals("CN"){
transfer.getBankDetails().setCountryCode("CN");
transfer.setDeliveryOptions(null);
return new Event(this, "D2B");
}else if(transfer.getAmount().getDestination().getCountryCode().equals("US"){
transfer.getBankDetails().setCountryCode("CN");
transfer.setDeliveryOptions(null);
return new Event(this, "D2B");
}
and this code repeats for all the countries now I want optimize the code.
For that I have a table which has country name and country table.
So I want to get the country code from DB and reduce most of the code.
Use a HashMap<String, String> in which you will insert your list of countries. Then you just need to call you code once, like
String aCountryCode = transfer.getAmount().getDestination().getCountryCode();
String aBankCountryCode = aMapOfCountries.get(aCountryCode );
if (aBankCountryCode != null) {
transfer.getBankDetails().setCountryCode(aBankCountryCode );
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Is it possible to search without iterator without using map.
Map<String,Short> map = new HashMap<String,Short>();
map.put("String2", (short)2);
map.put("String1", (short)1);
map.put("String3", (short)4);
I am looking for a way to get the value based on the key (Return 2 for value String2). Is Map the right one to use in this scenario.
Thanks !
Returning values based on a key is precisely what maps are for.
To retrieve your value you can simply do:
short returnVal = map.get("String2");