Example usage for java.util Set remove

List of usage examples for java.util Set remove

Introduction

In this page you can find the example usage for java.util Set remove.

Prototype

boolean remove(Object o);

Source Link

Document

Removes the specified element from this set if it is present (optional operation).

Usage

From source file:gov.nih.nci.cabig.ctms.web.WebToolsTest.java

public void testRequestPropertiesToMapHasNoExtras() throws Exception {
    Map<String, Object> actual = WebTools.requestPropertiesToMap(request);

    Set<String> extra = new LinkedHashSet<String>(actual.keySet());
    for (String property : EXPECTED_REQUEST_PROPERTIES) {
        if (actual.containsKey(property))
            extra.remove(property);
    }/*from   www  .  ja  va2s  .  c o m*/
    assertEquals("One or more extra properties in map: " + extra, 0, extra.size());
}

From source file:edu.ucsd.library.xdre.web.StatsCollectionsReportController.java

public synchronized static void generateReport() throws Exception {
    DAMSClient damsClient = null;//from w  ww. j av a 2  s  .  com
    StringBuilder strBuf = new StringBuilder();
    strBuf.append("UCSD Library DAMS Collections Report - " + ReportFormater.getCurrentTimestamp() + "\n");
    strBuf.append(
            "Collection\tType\tUnit\tSearchable Items\tItems Count\tSize(MB)\tView\tPublic\tUCSD\tCurator\tRestricted\tCulturally Sensitive\tNotes"
                    + "\n");

    Map<String, String> unitsMap = null;
    Map<String, Set<String>> unitsRecordsMap = new HashMap<String, Set<String>>();
    Map<String, String> colRows = new TreeMap<String, String>();

    try {
        String colId = null;
        String colTitle = null;
        List<String> values = null;
        String visibility = "";
        String unit = "";
        String colType = "";
        String rowVal = null;
        Document doc = null;
        damsClient = DAMSClient.getInstance();
        Map<String, String> colMap = damsClient.listCollections();

        CollectionHandler colHandler = null;
        unitsMap = DAMSClient.reverseMap(damsClient.listUnits());
        for (Iterator<String> it = unitsMap.keySet().iterator(); it.hasNext();) {
            String unitId = it.next();
            Set<String> uRecords = new HashSet<String>();
            uRecords.addAll(damsClient.listUnitObjects(unitId));
            unitsRecordsMap.put(unitId, uRecords);
        }
        for (Iterator<String> iter = colMap.keySet().iterator(); iter.hasNext();) {
            visibility = "";
            unit = "";
            colTitle = iter.next();
            colId = colMap.get(colTitle);

            // Remove records from all units
            try {
                colHandler = new StatsCollectionQuantityHandler(damsClient, colId);
                if (unitsRecordsMap.size() > 0) {
                    for (Iterator<Set<String>> uit = unitsRecordsMap.values().iterator(); uit.hasNext();) {
                        Set<String> uRecords = uit.next();
                        uRecords.remove(colId);
                        uRecords.removeAll(colHandler.getItems());
                    }
                }
            } finally {
                if (colHandler != null) {
                    colHandler.release();
                    colHandler = null;
                }
            }

            colId = colId.substring(colId.lastIndexOf("/") + 1);
            int idx = colTitle.lastIndexOf("[");
            if (idx > 0) {
                colType = colTitle.substring(idx + 1, colTitle.lastIndexOf("]"));
                colTitle = colTitle.substring(0, idx).trim();
            }

            doc = damsClient.solrLookup("q=" + URLEncoder.encode("id:" + colId, "UTF-8"));
            values = getValues(doc, "//*[@name='visibility_tesim']/str");
            for (Iterator<String> it = values.iterator(); it.hasNext();)
                visibility += (visibility.length() > 0 ? " " : "") + it.next();
            values = getValues(doc, "//*[@name='unit_code_tesim']/str");
            for (Iterator<String> it = values.iterator(); it.hasNext();)
                unit += (unit.length() > 0 ? " " : "") + it.next();
            rowVal = getRow(damsClient, colTitle, colId, colType, unit, visibility, colMap, null);
            if (rowVal != null && rowVal.length() > 0)
                colRows.put(colTitle, rowVal + "\n");
        }

        // Orphans in each unit
        for (Iterator<String> uit = unitsRecordsMap.keySet().iterator(); uit.hasNext();) {
            colId = uit.next();
            colTitle = unitsMap.get(colId);
            Set<String> uRecords = unitsRecordsMap.get(colId);
            List<String> items = new ArrayList<String>();
            items.addAll(uRecords);
            colType = "Unit";
            colId = colId.substring(colId.lastIndexOf("/") + 1);

            doc = damsClient.solrLookup("q=" + URLEncoder.encode("id:" + colId, "UTF-8"));
            visibility = "";
            values = getValues(doc, "//*[@name='visibility_tesim']/str");
            for (Iterator<String> it = values.iterator(); it.hasNext();)
                visibility += (visibility.length() > 0 ? " " : "") + it.next();

            unit = "";
            values = getValues(doc, "//*[@name='unit_code_tesim']/str");
            for (Iterator<String> it = values.iterator(); it.hasNext();)
                unit += (unit.length() > 0 ? " " : "") + it.next();
            rowVal = getRow(damsClient, colTitle, colId, colType, unit, visibility, colMap, items);
            if (rowVal != null && rowVal.length() > 0)
                colRows.put(colTitle, rowVal + "\n");
        }

        for (Iterator<String> iter = colRows.values().iterator(); iter.hasNext();) {
            strBuf.append(iter.next());
        }

        STATUSREPORT = strBuf.toString();
    } finally {
        if (damsClient != null) {
            damsClient.close();
            damsClient = null;
        }
    }
}

From source file:org.jasig.portlet.conference.program.mvc.portlet.MainController.java

@ResourceMapping
public ModelAndView updateSessions(PortletRequest request, @RequestParam String title,
        @RequestParam boolean add) throws ReadOnlyException, ValidatorException, IOException {
    PortletPreferences preferences = request.getPreferences();
    String[] sessions = preferences.getValues("mysessions", new String[] {});

    Set<String> mine = new HashSet<String>();
    for (String session : sessions) {
        mine.add(session);/*www.  j a v  a  2  s . co  m*/
    }
    if (add) {
        mine.add(title);
    } else {
        mine.remove(title);
    }
    preferences.setValues("mysessions", mine.toArray(new String[] {}));

    preferences.store();

    return new ModelAndView("json");
}

From source file:org.magnum.mobilecloud.video.Assign2Controller.java

@RequestMapping(value = VideoSvcApi.VIDEO_SVC_PATH + "/{id}/unlike", method = RequestMethod.POST)
public @ResponseBody void unlikeVideo(@PathVariable("id") long id, Principal p, HttpServletResponse response)
        throws IOException {
    if (!videos.exists(id)) {
        response.setStatus(404);//from   ww w .j a  v  a  2  s .  c o  m
    } else {
        Video v = videos.findOne(id);
        Set<String> likesUserNames = v.getLikesUsernames();
        if (likesUserNames.contains(p.getName())) {
            likesUserNames.remove(p.getName());
            v.setLikes(likesUserNames.size());
            videos.save(v);
            response.setStatus(200);
        } else {
            response.setStatus(400);
        }
    }
}

From source file:com.sourceallies.beanoh.BeanohTestCase.java

private void removeIgnoredClasses(final Set<String> scannedComponents) {
    for (String ignoredClassName : ignoredClassNames) {
        scannedComponents.remove(ignoredClassName);
    }//from  ww  w .  java 2  s  .  co  m
}

From source file:org.atemsource.atem.impl.common.AbstractAttributeFactory.java

protected Set<EntityType> createValidtypesSet(final EntityType elementEntityType, final Class[] includedTypes,
        final Class[] excludedTypes, final EntityTypeCreationContext ctx) {
    Set<EntityType> validTypesSet;
    if (includedTypes == null || includedTypes.length == 0) {
        validTypesSet = elementEntityType.getSelfAndAllSubEntityTypes();
        if (excludedTypes != null) {
            for (Class type : excludedTypes) {
                validTypesSet.remove(ctx.getEntityTypeReference(type));
            }//from  ww w .  jav a  2s.  c  om
        }
    } else {
        validTypesSet = new HashSet<EntityType>();
        for (Class type : includedTypes) {
            validTypesSet.add(ctx.getEntityTypeReference(type));
        }
    }
    return validTypesSet;
}

From source file:com.devicehive.websockets.handlers.DeviceHandlers.java

@PreAuthorize("isAuthenticated() and hasPermission(null, 'REGISTER_DEVICE')")
public WebSocketResponse processDeviceSave(JsonObject request, WebSocketSession session) {
    String deviceId = request.get(Constants.DEVICE_ID).getAsString();
    DeviceUpdate device = gson.fromJson(request.get(Constants.DEVICE), DeviceUpdate.class);

    logger.debug("device/save process started for session {}", session.getId());
    if (deviceId == null) {
        throw new HiveException(Messages.DEVICE_GUID_REQUIRED, SC_BAD_REQUEST);
    }/*w  ww  .j  a  v a2 s . c o m*/
    device.setGuid(Optional.ofNullable(deviceId));
    Set<DeviceClassEquipmentVO> equipmentSet = gson.fromJson(request.get(Constants.EQUIPMENT),
            new TypeToken<HashSet<DeviceClassEquipmentVO>>() {
            }.getType());
    if (equipmentSet != null) {
        equipmentSet.remove(null);
    }
    deviceService.deviceSaveAndNotify(device, equipmentSet,
            (HivePrincipal) SecurityContextHolder.getContext().getAuthentication().getPrincipal());
    logger.debug("device/save process ended for session  {}", session.getId());
    return new WebSocketResponse();
}

From source file:com.arpnetworking.metrics.proxy.models.protocol.v2.LogMessagesProcessor.java

private void unsubscribe(final Path log, final ArrayNode regexes) {
    if (!_logsSubscriptions.containsKey(log)) {
        return;/*from w w w .  j a  va  2 s  .c  o m*/
    }
    final Set<String> logsRegexes = _logsSubscriptions.get(log);
    for (JsonNode node : regexes) {
        logsRegexes.remove(node.asText());
    }
}

From source file:com.stehno.sanctuary.core.remote.InMemoryRemoteStore.java

@Override
public void deleteFile(File rootDirectory, File file) {
    final String root = extractRoot(rootDirectory);
    Set<String> store = stores.get(root);
    if (store != null) {
        final String storeFile = extractStoreFile(file, root);
        if (log.isDebugEnabled())
            log.debug("Deleted[" + root + "]: " + storeFile);

        store.remove(storeFile);
    }/*  ww w . ja  v  a 2s  .  c  o m*/
}

From source file:com.amazon.carbonado.repo.replicated.ReplicatedRepository.java

/**
 * Utility method to select the natural ordering of a storage, by looking
 * for a clustered index on the primary key. Returns null if no clustered
 * index was found.//from  w w  w . j a  v  a  2 s  .  co m
 *
 * TODO: Try to incorporate this into standard storage interface somehow.
 */
private static String[] selectNaturalOrder(Repository repo, Class<? extends Storable> type)
        throws RepositoryException {
    IndexInfoCapability capability = repo.getCapability(IndexInfoCapability.class);
    if (capability == null) {
        return null;
    }
    IndexInfo info = null;
    for (IndexInfo candidate : capability.getIndexInfo(type)) {
        if (candidate.isClustered()) {
            info = candidate;
            break;
        }
    }
    if (info == null) {
        return null;
    }

    // Verify index is part of primary key.
    Set<String> pkSet = StorableIntrospector.examine(type).getPrimaryKeyProperties().keySet();

    String[] propNames = info.getPropertyNames();
    for (String prop : propNames) {
        if (!pkSet.contains(prop)) {
            return null;
        }
    }

    String[] orderBy = new String[pkSet.size()];

    Direction[] directions = info.getPropertyDirections();

    // Clone to remove elements.
    pkSet = new LinkedHashSet<String>(pkSet);

    int i;
    for (i = 0; i < propNames.length; i++) {
        orderBy[i] = ((directions[i] == Direction.DESCENDING) ? "-" : "+") + propNames[i];
        pkSet.remove(propNames[i]);
    }

    // Append any remaining pk properties, to ensure complete ordering.
    if (pkSet.size() > 0) {
        for (String prop : pkSet) {
            orderBy[i++] = prop;
        }
    }

    return orderBy;
}