Professional Documents
Culture Documents
Porady Programistyczne
Porady Programistyczne
Zależności – Maven
Dodając nową zależność do pom.xml Maven bierze taką wersję jaką zdefiniowałeś, jeśli jest wyższa
niż w parent pomie, jeśli jest niższa bierze tę z parent poma. Ryzykowne jest podanie wyższej wersji,
ponieważ może zniszczyć to co już działało.
Wyrażenie:
private boolean isIIIFPresentationAPISearchMode (SearchRequestDTO
searchRequestDTO){
if(IIIF_PRESENTATION_API_MODE.equals(getSearchMode(searchRequestDTO))) {
return true;
}
return false;
Często zamiast prostego warunku if (warunek) {return wartość} return null (czyli prostej metody na
ominięcie sprawdzania typu zwracanych danych), lepiej rzucić wyjątkiem np.
W przypadku zwracania wartości należy sprawdzać, czy wartość wejściowa nie jest nullem:
Taki kod:
public Hit searchResponseDTOToHit(SearchResponseDTO response) {
return response.getHits().getContent().get(0);
Enumy
Przy implementacji enuma trzeba dawac jego wartości jako private i implementować gettera
Code style
Odstępy w properties
Git
Cofanie się do poprzednich branchy
Git reset –hard HEAD~x , gdzie x to liczba branchy o ile się cofasz
W Idei można przejrzeć wszystkie pliki zmienione lokalnie i zaznaczyć je i zacommitowac i spuchowac
od razu z poziomu tego okna
Ogólne porady
Controller
Nie rób camel case w linkach
Stosuj streamy
public SearchIndexDTO findMainSearchIndex() {
List<SearchIndexDTO> indexes = findSearchIndexes();
for (SearchIndexDTO index : indexes) {
String indexName = index.getName();
if ("Main search index".equals(indexName)) {
return index;
}
}
throw new IllegalStateException("Main search index not found");
}
zmien na
Optional.ofNullable(findSearchIndexes()).orElse(List.of()).stream()
.filter(index -> "Main search index".equals(index.getName()))
.findAny()
.orElseThrow(() -> new IllegalStateException("Main search index not
found"));
Porównywanie stringów
Przy porównywaniu zmniennej do stałej przy pomocy metody equals(). Stała powinna być pierwsza:
stała.equals(zmienna)
CollectionUtils.isEmpty
StringUtils.isEmpty
Odpalanie aplikacji
Zawsze odpalaj tryb debug
Angular
Index Signatures
https://www.typescriptlang.org/docs/handbook/2/objects.html#index-signatures
export interface Item {
id: number;
size: number;
}
export interface Example {
name: string;
items: {
[key: string]: Item
};
}
Tricki przeglądarkowe
Testowanie z pominięciem CORSa z localhost:
For temporary testing during development we can disable it by opening chrome with disabled
web security like this.
Open command line terminal and go to folder where chrome is installed i.e. C:\Program Files
(x86)\Google\Chrome\Application
A new browser window will open with disabled web security. Use it only for testing your app.
There's a secret passphrase built into the error page. Just make sure the page is selected (click
anywhere on the screen), and just type thisisunsafe.