I have an Angular app that shows a list of entities and I have a 'show more' button that increments page number and uses this method:
Page<myEntity> result = myRepo.findByAttr(attr, page);
I format this result and send it via REST's JSON. I want to disable 'show more' button if there's no further pages to get. There's a 'frameworkie' specific way to retrieve this number or I should use findAll() and count through this list?
This is the source code of Page interface
public interface Page<T> extends Slice<T> {
/**
* Returns the number of total pages.
*
* #return the number of total pages
*/
int getTotalPages();
/**
* Returns the total amount of elements.
*
* #return the total amount of elements
*/
long getTotalElements();
/**
* Returns a new {#link Page} with the content of the current one mapped by the given {#link Converter}.
*
* #param converter must not be {#literal null}.
* #return a new {#link Page} with the content of the current one mapped by the given {#link Converter}.
* #since 1.10
*/
<S> Page<S> map(Converter<? super T, ? extends S> converter);
}
You have getTotalElements() to get the total number of matching element.
getTotalPages() will give total number of pages.
Use result.getTotalElements() to get the total number of matching element.
Use result.getTotalPages() to get the total number of page.
p.s. Use result.getContent() to get the content as List<>
Related
I'm trying to figure out how to get the relativeAtomicMass from one class named ChemicalElement onto another called MolarMass in which I try to figure out the atomicmass of an element given it's symbol then find out a compound mass. I'm not sure how to return a double, I tried using a toString to do it since that's what a tutor taught me to do but I'm not sure if it's the correct way that my teacher wants me to do it. I know I need to get the relativeAtomicMass onto MolarMass to finish the assignment but i'm stuck at the moment. Heres the code for my assignment:
package chemical;
public class ChemicalElement {
// Properties (fields/variables): This time we leave give them default visibility, which gives
// other classes in the same package (i.e. the same directory) full access to them, for brevity.
/** The number of protons */
int atomicNumber;
/** 1-3 letter IUPAC symbol */
String symbol;
/** Full name */
String name;
/** Relative atomic mass () */
double relativeAtomicMass;
/** Row in the periodic table */
int period;
/** Column in the periodic table */
int group;
// Actions (methods): For now we provide a constructor to initialize all fields.
/**
* Constructs a new ChemicalElement object with the given properties.
*
* #param atomicNumber the number of protons
* #param symbol the IUPAC symbol
* #param name the full name
* #param relativeAtomicMass the average atomic mass relative to carbon-12
* #param period the row in the periodic table
* #param group the column in the periodic table
*/
public ChemicalElement(int atomicNumber, String symbol, String name, double relativeAtomicMass,
int period, int group) {
this.atomicNumber = atomicNumber;
this.symbol = symbol;
this.name = name;
this.relativeAtomicMass = relativeAtomicMass;
this.period = period;
this.group = group;
}
public String toString()
{
return name;
}
}
package chemical;
import java.net.URL;
import java.util.Scanner;
import java.util.Arrays;
public class MolarMass {
public static void main(String[] compoundTokens) throws Exception {
ChemicalElement[] elements = readElementData();
//System.out.printf("%.6f%n", compoundmass(elements, compoundTokens));
System.out.println(Arrays.toString(elements));
}
/**
* Loads data about all chemical elements into an array.
*
* #return an array containing references to objects describing all 118 chemical elements
* #throws Exception if anything goes awry (we only know how to pass the buck)
*/
private static ChemicalElement[] readElementData() throws Exception {
ChemicalElement[] elements = new ChemicalElement[119];
Scanner dataFile =
new Scanner(new URL("http://jeff.cis.cabrillo.edu/datasets/elements").openStream());
while (dataFile.hasNext()) {
// Example line: 1 H Hydrogen 1.008 1 1
int atomicNumber = dataFile.nextInt();
elements[atomicNumber] = new ChemicalElement(atomicNumber, dataFile.next(), dataFile.next(),
dataFile.nextDouble(), dataFile.nextInt(), dataFile.nextInt());
}
return elements;
}
/**
* Determines the molar mass of a compound.
*
* #param elements an array containing references to objects describing all 118 chemical elements
* #param tokens a compound formula
* #return the molar mass of the given compound
*/
// private static double compoundMass(ChemicalElement[] elements, String[] tokens) {
// TODO
/**
* Determines the relative atomic mass of an element, given its symbol.
*
* #param elements an array containing references to objects describing all 118 chemical elements
* #param symbol the symbol of the element in question
* #return the relative atomic mass of the given element
*/
// private static double relativeAtomicMass(ChemicalElement[] elements, String symbol) {
// TODO
}
Also i'd imagine that once I get the relative atomic mass onto molarmass it would be easy to fill out the code for relativeatomicmass but how would I use that to create compounds?
Thanks any help would be appreciated.
I want to set the length for a String type field,but i see the Source code:
value is reset after a call to {#link #add(String, Class)}
What is the significance of a method?How can i set the length for a String type field?anyone could help me
/**
* Sets a restriction on the field length of the next attribute added to the feature type.
*
* <p>This method is the same as adding a restriction based on length( value ) < length This
* value is reset after a call to {#link #add(String, Class)}
*
* #return length Used to limit the length of the next attribute created
*/
public SimpleFeatureTypeBuilder length(int length) {
attributeBuilder.setLength(length);
return this;
}
If you follow through the code you will see that add(String, Class) is called to add the new attribute to the schema. It calls out to AttributeTypeBuilder to encode the attribute. This is where setLength stores the length restriction you set in length. Once the attribute is generated resetTypeState is called to "reset" the attribute builder ready for your next attribute (this is where length is reset to null).
So the JavaDoc warning is correct length is reset after you add the attribute to the schema, so if you want to set a length restriction on an attribute you need to do something like:
fBuilder.length(30);
fBuilder.add("myStringAttr",String.class);
schema = fBuilder.buildFeatureType();
I'm working with Mybatis 3.2.6 and implementing a custom resulthandler. I've done this before using a simple datatype parameter and have had no problems. This time around I need to pass in several arguments... The signature I'm using is
session.select(statement, parameter, handler);
For parameter I've created a simple POJO to easily send in what I need. It is as follows:
public class DifferenceParam {
private int current;
private int compare;
private String table;
private String comparator;
/**
* Constructor excluding comparator. Will default a value of
* "code" to compare content on, e.g., <br/>
* {#code select * from a minus select * from b where a.code = b.code } <br/>
* #param table
* #param current
* #param compare
*/
public DifferenceParam(String table, int current, int compare) {
this(table, "code", current, compare);
}
/**
* Constructor providing a specific column to compare on, e.g. <br/>
* {#code select * from a minus select * from b where a.[comparator] = b.[comparator] } <br/>
* #param table
* #param comparator
* #param current
* #param compare
*/
public DifferenceParam(String table, String comparator, int current, int compare) {
this.table = table;
this.comparator = comparator;
this.current = current;
this.compare = compare;
}
/** Appropriate setters and getters to follow **/
}
The handler implementation is irrelevant at the moment, because I get an exception well in advance... The query I'm executing is:
<select id="getCodeSetModifications" parameterType="DifferenceParam" resultType="Code">
select *
from
(
select * from ${param.table} where revision_seq = #{param.current}
minus
select * from ${param.table} where revision_seq = #{param.compare}
) a, ${param.table} b
where a.${param.comparator} = b.${param.comparator}
and b.revision_seq = #{param.compare}
</select>
Here is the interface as well
public List<Code> getCodeSetModifications(#Param("param") DifferenceParam param);
The problem I'm having is that execution via a mapper e.g.,
session.getMapper(DifferenceParam.class);
works just fine, but when I invoke through a select on the session I get the following exception.
Error querying database. Cause: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'param' in 'class com.mmm.his.cer.cerval.uidifference.map.param.DifferenceParam'
Cause: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'param' in 'class com.mmm.his.cer.cerval.uidifference.map.param.DifferenceParam'
I've debugged as far as I can go into Mybatis, but am having no luck.
Thanks in advance...
When you use session.getMapper(DifferenceParam.class);, mybatis looks for #Param annotation and uses it's value in query.
When you invoke session.select(statement, parameter, handler);, such mapping doesn't occur.
Try to add public DifferenceParam getParam() { return this; } to DifferenceParam to workaround this.
when the MyBatis query only have one param. Don't need #{param.} reference.
because it default use the only param.
so when u use ${param.table}, it actually using #{DifferenceParam.param.table}.
because it think the ${param.} inside of the #{DifferenceParam.}
I would like to create a template to automatically make my Javadoc documentation when I create a method. For example if I create a method:
protected User createUser_1P(String uname, String[] stocks) throws ElementAlreadyExists {
...
return u;
}
I would like the template to generate something like this:
/*
* #param uname user name
* #param stocks list of stocks
* #return User
* #throws ElementAlreadyExists
*/
Any help will be apreciated. Thanks
To generate JavaDoc for your method in IntelliJ all you need to do is to type /** on the line above the method definition and hit Enter.
For your method the following JavaDoc will be generated:
/**
*
* #param uname
* #param stocks
* #return
* #throws ElementAlreadyExists
*/
protected User createUser_1P(String uname, String[] stocks) throws ElementAlreadyExists {
...
return u;
}
Mind you that IntelliJ does not provide with any descriptions, you will have to fill them out.
Is there a built-in data structure in Java to represent a Crit-bit tree? Or any libraries available that might provide this functionality? I would also accept brief code as an answer, if one can be implemented in a simplistic brief way.
Did you try the radixtree java project?
You might find in it the structure you are looking for, like the:
RadixTree class
(extract):
/**
* This interface represent the operation of a radix tree. A radix tree,
* Patricia trie/tree, or crit bit tree is a specialized set data structure
* based on the trie that is used to store a set of strings. In contrast with a
* regular trie, the edges of a Patricia trie are labelled with sequences of
* characters rather than with single characters. These can be strings of
* characters, bit strings such as integers or IP addresses, or generally
* arbitrary sequences of objects in lexicographical order. Sometimes the names
* radix tree and crit bit tree are only applied to trees storing integers and
* Patricia trie is retained for more general inputs, but the structure works
* the same way in all cases.
*
* #author Tahseen Ur Rehman
* email: tahseen.ur.rehman {at.spam.me.not} gmail.com
*/
public interface RadixTree<T> {
/**
* Insert a new string key and its value to the tree.
*
* #param key
* The string key of the object
* #param value
* The value that need to be stored corresponding to the given
* key.
* #throws DuplicateKeyException
*/
public void insert(String key, T value) throws DuplicateKeyException;
RadixTreeNode class
(extract):
/**
* Represents a node of a Radix tree {#link RadixTreeImpl}
*
* #author Tahseen Ur Rehman
* #email tahseen.ur.rehman {at.spam.me.not} gmail.com
* #param <T>
*/
class RadixTreeNode<T> {
private String key;
private List<RadixTreeNode<T>> childern;
private boolean real;
private T value;
/**
* intailize the fields with default values to avoid null reference checks
* all over the places
*/
public RadixTreeNode() {
key = "";
childern = new ArrayList<RadixTreeNode<T>>();
real = false;
}
Another option is rkapsi's patricia-trie, or if you're looking for something a little less complicated that you can hack on yourself, you can try his simple-patricia-trie.
I've also got a functional-critbit implementation available that's focused on space-efficiency (though its performance is fine, as well). It comes in both mutable and immutable flavors.
try concurrent-trees
on gradle:
compile 'com.googlecode.concurrent-trees:concurrent-trees:2.4.0'