This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package demo.test; | |
import java.util.Scanner; | |
public class GameWinner { | |
public static void main(String[] args) | |
{ | |
Scanner sc = new Scanner(System.in); | |
System.out.println("Enter number of people: "); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.HashMap; | |
class Node { | |
int key; | |
int value; | |
Node pre; | |
Node next; | |
public Node(int key, int value) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public List<Member> findAll() throws Exception { | |
SearchRequest searchRequest = new SearchRequest(); | |
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); | |
searchSourceBuilder.query(QueryBuilders.matchAllQuery()); | |
searchRequest.source(searchSourceBuilder); | |
searchRequest.indices(ElasticSearchConstants.INDEX_NAME); | |
SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT); | |
return processResponse(searchResponse); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public List<Member> findByAmenityId(UUID amenityId) throws IOException { | |
SearchRequest searchRequest = new SearchRequest(); | |
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); | |
BoolQueryBuilder builder = QueryBuilders.boolQuery() | |
.must(QueryBuilders.nestedQuery(ElasticSearchConstants.AMENITIES, QueryBuilders.boolQuery() | |
.should(QueryBuilders.termQuery(ElasticSearchConstants.AMENITY_ID, amenityId.toString())), ScoreMode.None)); | |
searchSourceBuilder.query(builder); | |
searchRequest.indices(ElasticSearchConstants.INDEX_NAME); | |
searchRequest.source(searchSourceBuilder); | |
SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public String updateDocument(Member document) throws Exception { | |
Member resultDocument = findById(document.getId()); | |
UpdateRequest updateRequest = new UpdateRequest(ElasticSearchConstants.INDEX_NAME, document.getId().toString()); | |
Map<String, Object> documentMapper = objectMapper.convertValue(document, Map.class); | |
updateRequest.doc(documentMapper); | |
UpdateResponse updateResponse = client.update(updateRequest, RequestOptions.DEFAULT); | |
return updateResponse.getResult().name(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@PutMapping("updateDocument") | |
public ResponseEntity<?> updateDocument(@RequestBody Member member) throws Exception { | |
return new ResponseEntity(memberManager.updateDocument(member), HttpStatus.CREATED); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public String deleteDocument(UUID id) throws IOException { | |
DeleteRequest deleteRequest = new DeleteRequest(ElasticSearchConstants.INDEX_NAME, id.toString()); | |
DeleteResponse response = client.delete(deleteRequest, RequestOptions.DEFAULT); | |
return response.getResult().name(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@DeleteMapping("deleteDocuments/{id}") | |
public ResponseEntity<?> deleteDocuments(@PathVariable UUID id) throws Exception { | |
String response = memberManager.deleteDocument(id); | |
return new ResponseEntity<>(response, HttpStatus.OK); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@GetMapping("findAll") | |
public ResponseEntity<?> findAll() throws Exception { | |
List<Member> members = memberManager.findAll(); | |
return new ResponseEntity<>(members, HttpStatus.OK); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@GetMapping(value = "/findByAmenityId") | |
public ResponseEntity<?> findByAmenityId(@RequestParam(value = "id") UUID id){ | |
try { | |
List<Member> member = memberManager.findByAmenityId(id); | |
return new ResponseEntity<>(member, HttpStatus.OK); | |
} catch (Exception e) { | |
return new ResponseEntity<>("Search Failed", HttpStatus.INTERNAL_SERVER_ERROR); | |
} | |
} |
NewerOlder