/** * {@inheritDoc} * * @throws org.openbase.jul.exception.CouldNotPerformException {@inheritDoc} */ @Override public List<UnitConfig> getNeighborLocations(String locationId) throws CouldNotPerformException { UnitConfig locationConfig = getLocationConfigById(locationId); if (locationConfig.getLocationConfig().getType() != LocationConfig.LocationType.TILE) { throw new CouldNotPerformException("Id[" + locationId + "] does not belong to a tile and therefore its neighbors aren't defined!"); } Map<String, UnitConfig> neighborMap = new HashMap<>(); for (UnitConfig connectionConfig : getConnectionConfigs()) { if (connectionConfig.getConnectionConfig().getTileIdList().contains(locationId)) { for (String id : connectionConfig.getConnectionConfig().getTileIdList()) { if (id.equals(locationId)) { continue; } neighborMap.put(id, getLocationConfigById(id)); } } } return new ArrayList<>(neighborMap.values()); }
public List<ConnectionRemote> getConnectionList(final boolean waitForData) throws CouldNotPerformException { if (!getConfig().getLocationConfig().getType().equals(LocationType.TILE)) { throw new CouldNotPerformException("Location is not a Tile!"); } List<ConnectionRemote> connectionList = new ArrayList<>(); try { for (UnitConfig connectionUnitConfig : CachedLocationRegistryRemote.getRegistry().getConnectionConfigs()) { ConnectionRemote connection = Units.getUnit(connectionUnitConfig, waitForData, CONNECTION); if (connection.getConfig().getConnectionConfig().getTileIdList().contains(getId())) { connectionList.add(connection); } } } catch (InterruptedException ex) { throw new CouldNotPerformException("Could not get all connections!", ex); } return connectionList; }
/** * Method collects all connections between this and the given location and returns those instances. * * @param locationID the location id of the location to check. * @param waitForData flag defines if the method should block until all needed instances are available. * @return a collection of unit connection remotes. * @throws CouldNotPerformException is thrown if the check could not be performed e.g. if some data is not available yet. */ public List<ConnectionRemote> getDirectConnectionList(final String locationID, final boolean waitForData) throws CouldNotPerformException { if (!getConfig().getLocationConfig().getType().equals(LocationType.TILE)) { throw new CouldNotPerformException("Location is not a Tile!"); } List<ConnectionRemote> connectionList = new ArrayList<>(); try { for (UnitConfig connectionUnitConfig : Registries.getLocationRegistry().getConnectionConfigs()) { ConnectionRemote connection = Units.getUnit(connectionUnitConfig, waitForData, CONNECTION); if (connectionUnitConfig.getConnectionConfig().getTileIdList().contains(getId()) && connectionUnitConfig.getConnectionConfig().getTileIdList().contains(locationID)) { connectionList.add(connection); } } } catch (InterruptedException ex) { throw new CouldNotPerformException("Could not get all connections!", ex); } return connectionList; }