本文整理汇总了Java中java8.util.Optional.get方法的典型用法代码示例。如果您正苦于以下问题:Java Optional.get方法的具体用法?Java Optional.get怎么用?Java Optional.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java8.util.Optional
的用法示例。
在下文中一共展示了Optional.get方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreate
import java8.util.Optional; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_solicitados);
context=this;
//Cargo el menú lateral y pongo el nombre del proyecto a el Toolbar
SliderMenu sliderMenu = new SliderMenu(context, this);
sliderMenu.inicializateToolbar("Solicitudes");
usuarioSesion = Sesion.getUsuario(context);
RecyclerView recyclerViewSolicitudes = (RecyclerView) findViewById(R.id.recyclerSolicitudes);
Optional<ArrayList<SolicitudUnion>> listOptional = StreamSupport.stream(Almacen.getProyectos()).filter(proyecto -> proyecto.getIdPropietario() == usuarioSesion.getId()).map(proyecto -> proyecto.getSolicitudes()).findAny();
if(listOptional.isPresent())
adapterSolicitudes = new AdapterSolicitudes(context, listOptional.get());
else
adapterSolicitudes = new AdapterSolicitudes(context, new ArrayList<>());
//Establezco el recyclerview con las redes sociales
LinearLayoutManager llm = new LinearLayoutManager(context);
llm.setOrientation(LinearLayoutManager.VERTICAL);
recyclerViewSolicitudes.setLayoutManager(llm);
recyclerViewSolicitudes.setAdapter(adapterSolicitudes);
recyclerViewSolicitudes.addItemDecoration(new DividerItemDecoration(recyclerViewSolicitudes.getContext(),
llm.getOrientation()));
}
示例2: getIntersection
import java8.util.Optional; //导入方法依赖的package包/类
/**
* Returns the intersection point between this edge and the specified edge.
*
* <b>NOTE:</b> returns an empty optional if the edges are parallel or if
* the intersection point is not inside the specified edge segment
*
* @param e edge to intersect
* @return the intersection point between this edge and the specified edge
*/
public Optional<Vector3d> getIntersection(Edge e) {
Optional<Vector3d> closestPOpt = getClosestPoint(e);
if (!closestPOpt.isPresent()) {
// edges are parallel
return Optional.empty();
}
Vector3d closestP = closestPOpt.get();
if (e.contains(closestP)) {
return closestPOpt;
} else {
// intersection point outside of segment
return Optional.empty();
}
}
示例3: findAndDecryptFilePartSafe
import java8.util.Optional; //导入方法依赖的package包/类
private MapResourceInfo findAndDecryptFilePartSafe(EOriginalMapFilePartType partType) throws MapLoadException {
Optional<MapResourceInfo> filePart = findAndDecryptFilePart(partType);
if (filePart.isPresent()) {
return filePart.get();
} else {
throw new MapLoadException("No " + partType + " information available in mapfile!");
}
}
示例4: readStacks
import java8.util.Optional; //导入方法依赖的package包/类
void readStacks() throws MapLoadException {
Optional<MapResourceInfo> filePartOptional = findAndDecryptFilePart(EOriginalMapFilePartType.STACKS);
if (filePartOptional.isPresent()) {
MapResourceInfo filePart = filePartOptional.get();
// - file position
int pos = filePart.offset;
// - Number of buildings
int stackCount = readBEIntFrom(pos);
pos += 4;
// - safety check
if ((stackCount * 8 > filePart.size) || (stackCount < 0)) {
throw new MapLoadException("wrong number of stacks in map File: " + stackCount);
}
// - read all Stacks
for (int i = 0; i < stackCount; i++) {
int posX = readBEWordFrom(pos);
pos += 2;
int posY = readBEWordFrom(pos);
pos += 2;
int stackType = readByteFrom(pos++);
int count = readByteFrom(pos++);
pos += 2; // not used - maybe: padding to size of 8 (2 INTs)
// -------------
// - update data
mapData.setStack(posX, posY, stackType, count);
}
}
}
示例5: readSettlers
import java8.util.Optional; //导入方法依赖的package包/类
void readSettlers() throws MapLoadException {
Optional<MapResourceInfo> filePartOptional = findAndDecryptFilePart(EOriginalMapFilePartType.SETTLERS);
if (filePartOptional.isPresent()) {
MapResourceInfo filePart = filePartOptional.get();
// - file position
int pos = filePart.offset;
// - Number of buildings
int settlerCount = readBEIntFrom(pos);
pos += 4;
// - safety check
if ((settlerCount * 6 > filePart.size) || (settlerCount < 0)) {
throw new MapLoadException("wrong number of settlers in map File: " + settlerCount);
}
// - read all Stacks
for (int i = 0; i < settlerCount; i++) {
int party = readByteFrom(pos++);
int settlerType = readByteFrom(pos++);
int posX = readBEWordFrom(pos);
pos += 2;
int posY = readBEWordFrom(pos);
pos += 2;
// -------------
// - update data
mapData.setSettler(posX, posY, settlerType, party);
}
}
}
示例6: testEmptyGet
import java8.util.Optional; //导入方法依赖的package包/类
@Test(expectedExceptions=NoSuchElementException.class)
public void testEmptyGet() {
Optional<Boolean> empty = Optional.empty();
Boolean got = empty.get();
}
示例7: boundaryPathsWithHoles
import java8.util.Optional; //导入方法依赖的package包/类
public static List<Polygon> boundaryPathsWithHoles(List<Polygon> boundaryPaths) {
List<Polygon> result = stream(boundaryPaths).
map(p -> p.clone()).collect(Collectors.toList());
List<List<Integer>> parents = new ArrayList<>();
boolean[] isHole = new boolean[result.size()];
for (int i = 0; i < result.size(); i++) {
Polygon p1 = result.get(i);
List<Integer> parentsOfI = new ArrayList<>();
parents.add(parentsOfI);
for (int j = 0; j < result.size(); j++) {
Polygon p2 = result.get(j);
if (i != j) {
if (p2.contains(p1)) {
parentsOfI.add(j);
}
}
}
isHole[i] = parentsOfI.size() % 2 != 0;
}
int[] parent = new int[result.size()];
for (int i = 0; i < parent.length; i++) {
parent[i] = -1;
}
for (int i = 0; i < parents.size(); i++) {
List<Integer> par = parents.get(i);
int max = 0;
int maxIndex = 0;
for (int pIndex : par) {
int pSize = parents.get(pIndex).size();
if (max < pSize) {
max = pSize;
maxIndex = pIndex;
}
}
parent[i] = maxIndex;
if (!isHole[maxIndex] && isHole[i]) {
List<Polygon> holes;
Optional<List<Polygon>> holesOpt = result.get(maxIndex).
getStorage().getValue(KEY_POLYGON_HOLES);
if (holesOpt.isPresent()) {
holes = holesOpt.get();
} else {
holes = new ArrayList<>();
result.get(maxIndex).getStorage().
set(KEY_POLYGON_HOLES, holes);
}
holes.add(result.get(i));
}
}
return result;
}
示例8: boundaryPaths
import java8.util.Optional; //导入方法依赖的package包/类
/**
* Returns a list of all boundary paths.
*
* @param boundaryEdges boundary edges (all paths must be closed)
* @return
*/
private static List<Polygon> boundaryPaths(List<Edge> boundaryEdges) {
List<Polygon> result = new ArrayList<>();
boolean[] used = new boolean[boundaryEdges.size()];
int startIndex = 0;
Edge edge = boundaryEdges.get(startIndex);
used[startIndex] = true;
startIndex = 1;
while (startIndex > 0) {
List<Vector3d> boundaryPath = new ArrayList<>();
while (true) {
Edge finalEdge = edge;
boundaryPath.add(finalEdge.p1.pos);
System.out.print("edge: " + edge.p2.pos);
Optional<Edge> nextEdgeResult = stream(boundaryEdges).
filter(e -> finalEdge.p2.equals(e.p1)).findFirst();
if (!nextEdgeResult.isPresent()) {
System.out.println("ERROR: unclosed path:"
+ " no edge found with " + finalEdge.p2);
break;
}
Edge nextEdge = nextEdgeResult.get();
int nextEdgeIndex = boundaryEdges.indexOf(nextEdge);
if (used[nextEdgeIndex]) {
break;
}
edge = nextEdge;
System.out.println("-> edge: " + edge.p1.pos);
used[nextEdgeIndex] = true;
}
if (boundaryPath.size() < 3) {
break;
}
result.add(Polygon.fromPoints(boundaryPath));
startIndex = nextUnused(used);
if (startIndex > 0) {
edge = boundaryEdges.get(startIndex);
used[startIndex] = true;
}
}
System.out.println("paths: " + result.size());
return result;
}
示例9: readBuildings
import java8.util.Optional; //导入方法依赖的package包/类
void readBuildings() throws MapLoadException {
hasBuildings = false;
Optional<MapResourceInfo> filePartOptional = findAndDecryptFilePart(EOriginalMapFilePartType.BUILDINGS);
if (filePartOptional.isPresent()) {
MapResourceInfo filePart = filePartOptional.get();
// - file position
int pos = filePart.offset;
// - Number of buildings
int buildingsCount = readBEIntFrom(pos);
pos += 4;
// - safety check
if ((buildingsCount * 12 > filePart.size) || (buildingsCount < 0)) {
throw new MapLoadException("wrong number of buildings in map File: " + buildingsCount);
}
hasBuildings = true;
// - read all Buildings
for (int i = 0; i < buildingsCount; i++) {
int party = readByteFrom(pos++); // - Party starts with 0
int buildingType = readByteFrom(pos++);
int posX = readBEWordFrom(pos);
pos += 2;
int posY = readBEWordFrom(pos);
pos += 2;
pos++; // not used - maybe a filling byte to make the record 12 Byte (= 3 INTs) long or unknown?!
// -----------
// - number of soldier in building is saved as 4-Bit (=Nibble):
int countSword1 = readHighNibbleFrom(pos);
int countSword2 = readLowNibbleFrom(pos);
pos++;
int countArcher2 = readHighNibbleFrom(pos);
int countArcher3 = readLowNibbleFrom(pos);
pos++;
int countSword3 = readHighNibbleFrom(pos);
int countArcher1 = readLowNibbleFrom(pos);
pos++;
int countSpear3 = readHighNibbleFrom(pos);
// low nibble is a not used count
pos++;
int countSpear1 = readHighNibbleFrom(pos);
int countSpear2 = readLowNibbleFrom(pos);
pos++;
// -------------
// - update data
mapData.setBuilding(posX, posY, buildingType, party, countSword1, countSword2, countSword3, countArcher1, countArcher2, countArcher3, countSpear1, countSpear2, countSpear3);
}
}
}