List of usage examples for com.google.common.collect BiMap containsKey
boolean containsKey(Object key);
From source file:org.pshow.ecm.content.metadata.DefaultContetntSchemaHolder.java
/** * ???namespace/*from w w w . j a v a 2s .co m*/ * * @param namespaces * @param psNamespace */ private void checkNamespace(BiMap<String, String> namespaces, NamespaceDef psNamespace) { // ???uri if (namespaces.containsKey(psNamespace.getUri())) { throw new SchemaRegistException( String.format("Namespace regist error: duplicate namespace uri -> %s", psNamespace.toString())); } // ???prefix if (namespaces.containsValue(psNamespace.getPrefix())) { throw new SchemaRegistException(String .format("Namespace regist error: duplicate namespace prefix -> %s", psNamespace.toString())); } }
From source file:org.gbif.common.search.builder.SolrQueryBuilder.java
/** * Sets the query filters.//from w w w.j a va2s . c o m * Takes a {@link Multimap} and produces a Solr filter query containing the filtering criteria. * The output string will be in the format: (param1:vp1.1 OR param1:vp1.2) AND (param2:vf2.1 OR param2:vp2.2)... * The param-i key are taken from the key sets of the map and the vpi.j (value j of param i) are the entry set of the * map. * * @return the String containing a Solr filter query */ private void setQueryFilter(final SearchRequest<P> searchRequest, SolrQuery solrQuery) { final Multimap<P, String> params = searchRequest.getParameters(); final boolean isFacetedRequest = FacetedSearchRequest.class.isAssignableFrom(searchRequest.getClass()); if (params != null) { BiMap<P, String> fieldsPropertiesMapInv = facetFieldsPropertiesMap.inverse(); for (P param : params.keySet()) { if (param != null && !fieldsPropertiesMapInv.containsKey(param)) { LOG.warn("Unknown search parameter {}", param); continue; } // solr field for this parameter final String solrFieldName = fieldsPropertiesMapInv.get(param); List<String> filterQueriesComponents = Lists.newArrayList(); for (String paramValue : params.get(param)) { // Negate expression is removed if it is present final String interpretedValue = getInterpretedValue(param.type(), removeNegation(paramValue)); final String queryComponent = PARAMS_JOINER.join(solrFieldName, interpretedValue); filterQueriesComponents.add(isNegated(paramValue) ? NOT_OP + queryComponent : queryComponent); } if (!filterQueriesComponents.isEmpty()) { // there are filter queries for this parameter StringBuilder filterQuery = buildFilterQuery(isFacetedRequest, solrFieldName, filterQueriesComponents); solrQuery.addFilterQuery(filterQuery.toString()); } } } }
From source file:com.comphenix.protocol.injector.player.ReplacedArrayList.java
/** * Undo all replacements./* w w w .j av a 2 s . com*/ */ public synchronized void revertAll() { // No need to do anything else if (replaceMap.size() < 1) return; BiMap<TKey, TKey> inverse = replaceMap.inverse(); for (int i = 0; i < underlyingList.size(); i++) { TKey replaced = underlyingList.get(i); if (inverse.containsKey(replaced)) { TKey original = inverse.get(replaced); onReplacing(replaced, original); underlyingList.set(i, original); } } replaceMap.clear(); }
From source file:uk.ac.susx.tag.method51.twitter.apikeystore.JsonApiKeyPersistenceImpl.java
@Override public synchronized String registerKey(ApiKey key) { String name = key.displayName; BiMap<String, ApiKey> keys = deserialiseKeys(); String id = null;//from www . j a v a2 s. com if (keys.inverse().containsKey(key)) { id = keys.inverse().get(key); throw new ApiKeyStoreException("key already registered: " + id); } else { Integer idNum = keys.size(); while (keys.containsKey(idNum.toString())) { idNum++; } id = idNum.toString(); keys.put(id, key); } serialiseKeys(keys); return id; }
From source file:seeit3d.base.ui.ide.view.MappingViewComposite.java
private void removeAlreadyMappedMetrics(List<MetricCalculator> metricsInformation, BiMap<MetricCalculator, VisualProperty> currentMapping) { for (Iterator<MetricCalculator> iterator = metricsInformation.iterator(); iterator.hasNext();) { MetricCalculator metric = iterator.next(); if (currentMapping.containsKey(metric)) { iterator.remove();//from w w w . j av a2s.c o m } } }
From source file:haven.Inventory.java
public Coord translateCoordinatesServerClient(Coord server) { if (!isTranslated) return server; Coord client = server;// ww w.j av a2 s .co m BiMap<Coord, Coord> dictionaryServerClient = dictionaryClientServer.inverse(); if (dictionaryServerClient.containsKey(server)) { client = dictionaryServerClient.get(server); } else { //find a spot for it int width = isz_client.x; int height = isz_client.y; Coord newloc = getEmptyLocalSpot(dictionaryClientServer, width); //if we're going too deep: add another row boolean expanded = false; if (newloc.y >= height && 2 * height >= width) { newloc = new Coord(0, height); expanded = true; } client = newloc; dictionaryClientServer.put(client, server); if (expanded) { updateClientSideSize(); } } return client; }
From source file:edu.usf.cutr.gtfsrtvalidator.validation.rules.CrossFeedDescriptorValidator.java
@Override public List<ErrorListHelperModel> validate(long currentTimeMillis, GtfsDaoImpl gtfsData, GtfsMetadata gtfsMetadata, GtfsRealtime.FeedMessage feedMessage, GtfsRealtime.FeedMessage previousFeedMessage) { List<OccurrenceModel> w003List = new ArrayList<>(); List<OccurrenceModel> e047List = new ArrayList<>(); // key is trip_id from TripUpdates feed, value is vehicle.id BiMap<String, String> tripUpdates = HashBiMap.create(); // A set of trips (key = trip_id) that don't have any vehicle.ids Set<String> tripsWithoutVehicles = new HashSet<>(); int tripUpdateCount = 0; // key is vehicle_id from VehiclePositions feed, value is trip_id BiMap<String, String> vehiclePositions = HashBiMap.create(); // A set of vehicles (key = vehicle.id) that don't have any trip_ids Set<String> vehiclesWithoutTrips = new HashSet<>(); int vehiclePositionCount = 0; // Build the maps for (GtfsRealtime.FeedEntity entity : feedMessage.getEntityList()) { if (entity.hasTripUpdate() && hasTripId(entity.getTripUpdate())) { tripUpdateCount++;/*from w w w .j a v a2 s .c om*/ String tripId = entity.getTripUpdate().getTrip().getTripId(); String vehicleId = ""; if (entity.getTripUpdate().hasVehicle() && entity.getTripUpdate().getVehicle().hasId()) { vehicleId = entity.getTripUpdate().getVehicle().getId(); } if (StringUtil.isEmpty(vehicleId)) { // Trip does not have a vehicle.id - add it to the set (it can't exist in HashBiMap) tripsWithoutVehicles.add(tripId); } else { // Trip has a vehicle.id - add it to the HashBiMap try { tripUpdates.put(tripId, vehicleId); } catch (IllegalArgumentException e) { // TODO - We should log this as error under new rule - see https://github.com/CUTR-at-USF/gtfs-realtime-validator/issues/33 _log.error("Error adding trip_id " + tripId + " -> vehicle_id " + vehicleId + " to TripUpdates HashBiMap. TripUpdate exists twice in feed, or more than one TripUpdate is assigned to the same vehicle. " + e); } } } if (entity.hasVehicle() && hasVehicleId(entity.getVehicle())) { vehiclePositionCount++; String vehicleId = entity.getVehicle().getVehicle().getId(); String tripId = ""; if (entity.getVehicle().hasTrip() && entity.getVehicle().getTrip().hasTripId()) { tripId = entity.getVehicle().getTrip().getTripId(); } if (StringUtil.isEmpty(tripId)) { // Vehicle does not have a trip_id - add it to the set (it can't exist in HashBiMap) vehiclesWithoutTrips.add(vehicleId); } else { // Vehicle has a trip_id - add it to the HashBiMap try { vehiclePositions.put(vehicleId, tripId); } catch (IllegalArgumentException e) { // TODO - We should log this as error under new rule - see https://github.com/CUTR-at-USF/gtfs-realtime-validator/issues/38 _log.error("Error adding vehicle.id " + vehicleId + " -> trip_id " + tripId + " to VehiclePositions HashBiMap. Vehicle exists twice in feed, or more than one vehicle is assigned to same trip. " + e); } } } } List<ErrorListHelperModel> errors = new ArrayList<>(); if (tripUpdateCount == 0 || vehiclePositionCount == 0) { // We are missing a VehiclePositions or TripUpdates feed, so we can't compare across feeds - return empty list; return errors; } /** * Create inverse maps, so we can efficiently check if a trip_id in TripUpdates is in VehiclePositions, and if * vehicle_id in VehiclePositions is in TripUpdates. * * tripUpdatesInverse - A map of vehicle_ids to trip_ids, from the TripUpdates feed * vehiclePositionsInverse - A map of trip_ids to vehicle_ids, from the VehiclePositions feed * * Note that we still need to check vehiclesWithoutTrips and tripsWithoutVehicles, as these trips/vehicles can't exist in HashBiMaps. * See https://github.com/CUTR-at-USF/gtfs-realtime-validator/issues/241#issuecomment-313194304. */ BiMap<String, String> tripUpdatesInverse = tripUpdates.inverse(); BiMap<String, String> vehiclePositionsInverse = vehiclePositions.inverse(); // Check all trips that contained a vehicle for (Map.Entry<String, String> trip : tripUpdates.entrySet()) { if (!vehiclePositionsInverse.containsKey(trip.getKey())) { // W003 - TripUpdates feed has a trip_id that's not in VehiclePositions feed RuleUtils.addOccurrence(W003, "trip_id " + trip.getKey() + " is in TripUpdates but not in VehiclePositions feed", w003List, _log); } if (!vehiclePositions.containsKey(trip.getValue()) && !vehiclesWithoutTrips.contains(trip.getValue())) { // W003 - TripUpdates feed has a vehicle_id that's not in VehiclePositions feed RuleUtils.addOccurrence(W003, "vehicle_id " + trip.getValue() + " is in TripUpdates but not in VehiclePositions feed", w003List, _log); } checkE047TripUpdates(trip, vehiclePositionsInverse, e047List); } // Check all vehicles that contained a trip for (Map.Entry<String, String> vehiclePosition : vehiclePositions.entrySet()) { if (!tripUpdatesInverse.containsKey(vehiclePosition.getKey())) { // W003 - VehiclePositions has a vehicle_id that's not in TripUpdates feed RuleUtils.addOccurrence(W003, "vehicle_id " + vehiclePosition.getKey() + " is in VehiclePositions but not in TripUpdates feed", w003List, _log); } if (!tripUpdates.containsKey(vehiclePosition.getValue()) && !tripsWithoutVehicles.contains(vehiclePosition.getValue())) { // W003 - VehiclePositions has a trip_id that's not in the TripUpdates feed RuleUtils.addOccurrence(W003, "trip_id " + vehiclePosition.getValue() + " is in VehiclePositions but not in TripUpdates feed", w003List, _log); } checkE047VehiclePositions(vehiclePosition, tripUpdatesInverse, e047List); } // Check all trips that did NOT contain a vehicle for (String trip_id : tripsWithoutVehicles) { if (!vehiclePositionsInverse.containsKey(trip_id)) { // W003 - TripUpdates feed has a trip_id that's not in VehiclePositions feed RuleUtils.addOccurrence(W003, "trip_id " + trip_id + " is in TripUpdates but not in VehiclePositions feed", w003List, _log); } } // Check all vehicles that did NOT contain a trip for (String vehicle_id : vehiclesWithoutTrips) { if (!tripUpdatesInverse.containsKey(vehicle_id)) { // W003 - VehiclePositions has a vehicle_id that's not in TripUpdates feed RuleUtils.addOccurrence(W003, "vehicle_id " + vehicle_id + " is in VehiclePositions but not in TripUpdates feed", w003List, _log); } } if (!w003List.isEmpty()) { errors.add(new ErrorListHelperModel(new MessageLogModel(W003), w003List)); } if (!e047List.isEmpty()) { errors.add(new ErrorListHelperModel(new MessageLogModel(E047), e047List)); } return errors; }
From source file:net.sourcedestination.sai.comparison.matching.MatchingGenerator.java
public static GraphMatching includeEdgeMatching(final GraphMatching nodeMatching, BiMap<Integer, Integer> edgeMatch) { final BiMap<Integer, Integer> copyEdgeMatch = ImmutableBiMap.copyOf(edgeMatch); // transform Map.Entry to Pair instances final ImmutableSet<Pair<Integer>> matchedEdges = ImmutableSet.copyOf(edgeMatch.entrySet().stream() .map((arg) -> Pair.makePair(arg.getKey(), arg.getValue())).collect(toSet())); return new GraphMatching() { @Override/*w w w . j ava 2s. c om*/ public Graph getGraph1() { return nodeMatching.getGraph1(); } @Override public Graph getGraph2() { return nodeMatching.getGraph2(); } @Override public int getMatchedNodeInGraph2(int g1NodeID) { return nodeMatching.getMatchedNodeInGraph2(g1NodeID); } @Override public int getMatchedNodeInGraph1(int g2NodeID) { return nodeMatching.getMatchedNodeInGraph1(g2NodeID); } @Override public Set<Pair<Integer>> getAllNodeMatches() { return nodeMatching.getAllNodeMatches(); } @Override public int getMatchedEdgeInGraph2(int g1NodeID) { if (copyEdgeMatch.containsKey(g1NodeID)) return copyEdgeMatch.get(g1NodeID); return -1; } @Override public int getMatchedEdgeInGraph1(int g2NodeID) { if (copyEdgeMatch.inverse().containsKey(g2NodeID)) return copyEdgeMatch.inverse().get(g2NodeID); return -1; } @Override public Set<Pair<Integer>> getAllEdgeMatches() { return matchedEdges; } }; }
From source file:org.invenzzia.opentrans.visitons.network.Track.java
/** * Imports the junctions from the given list of records. * //from w w w . j av a2 s.com * @param records List of junction records. * @param world World instance used for finding the actual entity. */ public void importJunctions(List<JunctionRecord> records, BiMap<Long, Long> vertexMapping, World world) { if (records.isEmpty()) { this.junctions = ImmutableList.of(); } Junction juncs[] = new Junction[records.size()]; int i = 0; for (JunctionRecord jr : records) { long theId = jr.getId(); if (vertexMapping.containsKey(theId)) { theId = vertexMapping.get(theId); } IVertex vertex = world.findVertex(theId); if (!(vertex instanceof Junction)) { throw new IllegalStateException("The vertex #" + theId + " was expected to be a junction."); } juncs[i++] = (Junction) vertex; } this.junctions = ImmutableList.copyOf(juncs); }
From source file:haven.Inventory.java
Coord getEmptyLocalSpot(BiMap<Coord, Coord> dictionary, int width) { int index = 0; Coord newloc;/*w w w.j ava 2 s . co m*/ do { newloc = new Coord((index % (width - 1)), (int) (index / (width - 1))); index++; } while (dictionary.containsKey(newloc)); return newloc; }