当前位置: 首页>>代码示例>>Java>>正文


Java Optional.isPresent方法代码示例

本文整理汇总了Java中java8.util.Optional.isPresent方法的典型用法代码示例。如果您正苦于以下问题:Java Optional.isPresent方法的具体用法?Java Optional.isPresent怎么用?Java Optional.isPresent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java8.util.Optional的用法示例。


在下文中一共展示了Optional.isPresent方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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()));
}
 
开发者ID:nen155,项目名称:TFG-SmartU-La-red-social,代码行数:24,代码来源:SolicitadosActivity.java

示例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();
    }
}
 
开发者ID:lyrachord,项目名称:FX3DAndroid,代码行数:27,代码来源:Edge.java

示例3: boundaryPolygonsOfPlaneGroup

import java8.util.Optional; //导入方法依赖的package包/类
private static List<Polygon> boundaryPolygonsOfPlaneGroup(
        List<Polygon> planeGroup) {

    List<Polygon> polygons = boundaryPathsWithHoles(
            boundaryPaths(boundaryEdgesOfPlaneGroup(planeGroup)));

    System.out.println("polygons: " + polygons.size());

    List<Polygon> result = new ArrayList<>(polygons.size());

    for (Polygon p : polygons) {

        Optional<List<Polygon>> holesOfPresult
                = p.
                getStorage().getValue(Edge.KEY_POLYGON_HOLES);

        if (!holesOfPresult.isPresent()) {
            result.add(p);
        } else {
            result.addAll(PolygonUtil.concaveToConvex(p));
        }
    }

    return result;
}
 
开发者ID:lyrachord,项目名称:FX3DAndroid,代码行数:26,代码来源:Edge.java

示例4: unCheckElement

import java8.util.Optional; //导入方法依赖的package包/类
private void unCheckElement(int position){
	View view =gridView.getChildAt(position);
	ImageView seleccionado = (ImageView) view.findViewById(R.id.elemento_area);
	seleccionado.setVisibility(View.GONE);
	Optional<Area> areaOptional = StreamSupport.stream(areasBack).filter(area1 -> area1.getId() == ((Area) getItem(position)).getId()).findAny();
	if(areaOptional.isPresent())
		areasBack.remove(areaOptional.get());
}
 
开发者ID:nen155,项目名称:TFG-SmartU-La-red-social,代码行数:9,代码来源:AdapterAreasInteres.java

示例5: assertValue

import java8.util.Optional; //导入方法依赖的package包/类
@Override
void assertValue(U value, Supplier<Stream<T>> source, boolean ordered)
        throws Exception {
    Optional<U> reduced = source.get().map(mapper).reduce(reducer);
    if (value == null)
        assertTrue(!reduced.isPresent());
    else if (!reduced.isPresent()) {
        assertEquals(value, identity);
    }
    else {
        assertEquals(value, reduced.get());
    }
}
 
开发者ID:streamsupport,项目名称:streamsupport,代码行数:14,代码来源:CollectorsTest.java

示例6: 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!");
	}
}
 
开发者ID:jsettlers,项目名称:settlers-remake,代码行数:9,代码来源:OriginalMapFileContentReader.java

示例7: 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);
		}
	}
}
 
开发者ID:jsettlers,项目名称:settlers-remake,代码行数:37,代码来源:OriginalMapFileContentReader.java

示例8: 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);
		}
	}
}
 
开发者ID:jsettlers,项目名称:settlers-remake,代码行数:35,代码来源:OriginalMapFileContentReader.java

示例9: 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;
    }
 
开发者ID:lyrachord,项目名称:FX3DAndroid,代码行数:68,代码来源:Edge.java

示例10: 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;
}
 
开发者ID:lyrachord,项目名称:FX3DAndroid,代码行数:67,代码来源:Edge.java

示例11: 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);
		}
	}
}
 
开发者ID:jsettlers,项目名称:settlers-remake,代码行数:62,代码来源:OriginalMapFileContentReader.java


注:本文中的java8.util.Optional.isPresent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。