Example usage for java.util LinkedHashMap keySet

List of usage examples for java.util LinkedHashMap keySet

Introduction

In this page you can find the example usage for java.util LinkedHashMap keySet.

Prototype

public Set<K> keySet() 

Source Link

Document

Returns a Set view of the keys contained in this map.

Usage

From source file:com.streamsets.pipeline.lib.generator.delimited.DelimitedCharDataGenerator.java

private void writeHeader(Record record, String key) throws DataGeneratorException, IOException {
    Field field = record.get();//from  ww  w . j ava  2s. c o  m

    if (field.getType() == Field.Type.LIST) {
        writeLine(record, key);
    } else if (field.getType() == Field.Type.LIST_MAP) {
        LinkedHashMap<String, Field> columns = field.getValueAsListMap();
        Set<String> values = columns.keySet(); // Set is backed by LinkedHashMap, so order is maintained
        printer.printRecord(values);
    } else {
        throw new DataGeneratorException(Errors.DELIMITED_GENERATOR_00, record.getHeader().getSourceId(),
                field.getType());
    }

}

From source file:ubic.gemma.analysis.service.CompositeSequenceGeneMapperService.java

/**
 * @param officialSymbols//from  ww  w.  j  av a2 s . c  o  m
 * @param arrayDesigns to look in
 * @return LinkedHashMap<Gene, Collection<CompositeSequence>>
 */
public LinkedHashMap<Gene, Collection<CompositeSequence>> getGene2ProbeMapByOfficialSymbols(
        Collection<String> officialSymbols, Collection<ArrayDesign> arrayDesigns) {

    LinkedHashMap<String, Collection<Gene>> genesMap = findGenesByOfficialSymbols(officialSymbols);

    Set<String> geneOfficialSymbolKeyset = genesMap.keySet();

    LinkedHashMap<Gene, Collection<CompositeSequence>> compositeSequencesForGeneMap = new LinkedHashMap<Gene, Collection<CompositeSequence>>();

    for (String officialSymbol : geneOfficialSymbolKeyset) {
        log.debug("official symbol: " + officialSymbol);
        Collection<Gene> genes = genesMap.get(officialSymbol);
        for (Gene g : genes) {
            Collection<CompositeSequence> compositeSequences = geneService.getCompositeSequencesById(g.getId());
            for (CompositeSequence sequence : compositeSequences) {
                if (arrayDesigns.contains(sequence.getArrayDesign())) {
                    if (compositeSequencesForGeneMap.get(g) == null) {
                        compositeSequencesForGeneMap.put(g, new HashSet<CompositeSequence>());
                    }
                    compositeSequencesForGeneMap.get(g).add(sequence);
                }
            }
        }
    }
    return compositeSequencesForGeneMap;
}

From source file:ubic.gemma.core.analysis.service.CompositeSequenceGeneMapperService.java

/**
 * @param arrayDesigns    to look in//from  ww w  .j a  v  a  2s . co m
 * @param officialSymbols official symbols
 * @return map of gene to composite sequences
 */
public LinkedHashMap<Gene, Collection<CompositeSequence>> getGene2ProbeMapByOfficialSymbols(
        Collection<String> officialSymbols, Collection<ArrayDesign> arrayDesigns) {

    LinkedHashMap<String, Collection<Gene>> genesMap = this.findGenesByOfficialSymbols(officialSymbols);

    Set<String> geneOfficialSymbolKeySet = genesMap.keySet();

    LinkedHashMap<Gene, Collection<CompositeSequence>> compositeSequencesForGeneMap = new LinkedHashMap<>();

    for (String officialSymbol : geneOfficialSymbolKeySet) {
        log.debug("official symbol: " + officialSymbol);
        Collection<Gene> genes = genesMap.get(officialSymbol);
        for (Gene g : genes) {
            Collection<CompositeSequence> compositeSequences = geneService.getCompositeSequencesById(g.getId());
            for (CompositeSequence sequence : compositeSequences) {
                if (arrayDesigns.contains(sequence.getArrayDesign())) {
                    if (compositeSequencesForGeneMap.get(g) == null) {
                        compositeSequencesForGeneMap.put(g, new HashSet<CompositeSequence>());
                    }
                    compositeSequencesForGeneMap.get(g).add(sequence);
                }
            }
        }
    }
    return compositeSequencesForGeneMap;
}

From source file:com.plnyyanks.frcnotebook.datafeed.EventListFetcher.java

@Override
protected String doInBackground(Activity... args) {

    listActivity = args[0];/*from w w w. j av  a  2 s . c  o  m*/
    year = PreferenceHandler.getYear();
    LinkedHashMap<String, ListItem> data;
    data = TBADatafeed.fetchEvents_TBAv1(year);

    keys = new ArrayList<String>();
    keys.addAll(data.keySet());

    events = new ArrayList<ListItem>();
    events.addAll(data.values());

    return "";
}

From source file:org.sonar.server.es.Facets.java

public Set<String> getBucketKeys(String facetName) {
    LinkedHashMap<String, Long> facet = facetsByName.get(facetName);
    if (facet != null) {
        return facet.keySet();
    }/*  w  w w .j ava2  s  .  c o m*/
    return Collections.emptySet();
}

From source file:edu.usu.sdl.opencatalog.api.impl.LookupServiceImpl.java

@Override
public <T extends BaseEntity> List<T> findLookup(Class<T> lookTableClass, boolean all) {
    List<T> correctedList = new ArrayList<>();

    //Route request
    WebTarget target = getRestTarget(SERVICE + "/" + lookTableClass.getSimpleName());
    Response response = target.queryParam("all", all).request(MediaType.APPLICATION_JSON).get();

    //TODO: handle failed case (Look at status to provide meaningful errors

    //String rawData = response.readEntity(String.class);

    //      try// w  w  w.ja  v a2  s .  c o  m
    //      {
    //         ObjectMapper objectMapper = new ObjectMapper();
    //         correctedList = objectMapper.readValue(rawData, new TypeReference<List<T>>() {});
    //      } catch (IOException ex)
    //      {
    //         throw new RuntimeException(ex);
    //      }

    List<LinkedHashMap<String, String>> linkedMap = response.readEntity(new GenericType<List>() {
    });

    if (linkedMap.isEmpty() == false) {
        for (LinkedHashMap<String, String> map : linkedMap) {
            try {
                T dataObject = lookTableClass.newInstance();
                for (String key : map.keySet()) {
                    BeanUtils.setProperty(dataObject, key, map.get(key));
                }
                correctedList.add(dataObject);
            } catch (InstantiationException | IllegalAccessException | InvocationTargetException ex) {
                log.log(Level.SEVERE, null, ex);
            }
        }
    }

    return correctedList;
}

From source file:com.nestlabs.sdk.StructureTest.java

@Test
public void testWhereDescribeContents_shouldReturnZero() {
    try {/*from   www.  ja  v a  2  s  . c o m*/
        String json = IOUtils.toString(this.getClass().getResourceAsStream(TEST_STRUCTURE_JSON), "utf-8");
        Structure structure = mapper.readValue(json, Structure.class);
        LinkedHashMap<String, Structure.Where> wheres = structure.getWheres();
        for (String whereId : wheres.keySet()) {
            assertEquals(wheres.get(whereId).describeContents(), 0);
        }
    } catch (IOException e) {
        e.printStackTrace();
        Assert.fail();
    }
}

From source file:com.concursive.connect.web.modules.setup.utils.SetupUtils.java

public static void insertDefaultSiteConfig(Connection db, String fileLibraryPath, Project project,
        String purpose, ApplicationPrefs prefs) throws Exception {
    LOG.debug("insertDefaultSiteConfig");
    // Validate the pre-reqs
    if (!StringUtils.hasText(project.getTitle()) || !StringUtils.hasText(project.getShortDescription())
            || !StringUtils.hasText(project.getKeywords())) {
        throw new Exception("Title, description, keywords are required");
    }//  w w  w  .ja v a  2s  . com

    // Load the categories
    ProjectCategoryList categoryList = new ProjectCategoryList();
    categoryList.setTopLevelOnly(true);
    categoryList.buildList(db);

    // Determine the default's category
    int categoryId = categoryList.getIdFromValue("Groups");

    // Determine the tabs
    boolean isPrivate = false;
    ProjectCategoryList validCategoryList = new ProjectCategoryList();
    if ("social".equals(purpose)) {
        validCategoryList.add(categoryList.getFromValue("Groups"));
        validCategoryList.add(categoryList.getFromValue("People"));
        validCategoryList.add(categoryList.getFromValue("Events"));
        validCategoryList.add(categoryList.getFromValue("Ideas"));
        validCategoryList.add(categoryList.getFromValue("Sponsors"));
    } else if ("directory".equals(purpose)) {
        validCategoryList.add(categoryList.getFromValue("Businesses"));
        validCategoryList.add(categoryList.getFromValue("Organizations"));
        validCategoryList.add(categoryList.getFromValue("Groups"));
        validCategoryList.add(categoryList.getFromValue("People"));
        validCategoryList.add(categoryList.getFromValue("Places"));
        validCategoryList.add(categoryList.getFromValue("Events"));
        validCategoryList.add(categoryList.getFromValue("Ideas"));
    } else if ("community".equals(purpose)) {
        validCategoryList.add(categoryList.getFromValue("Groups"));
        validCategoryList.add(categoryList.getFromValue("People"));
        validCategoryList.add(categoryList.getFromValue("Ideas"));
    } else if ("intranet".equals(purpose)) {
        isPrivate = true;
        prefs.add(ApplicationPrefs.INFORMATION_IS_SENSITIVE, "true");
        prefs.add(ApplicationPrefs.USERS_CAN_REGISTER, "false");
        prefs.add(ApplicationPrefs.USERS_CAN_INVITE, "false");
        prefs.add(ApplicationPrefs.USERS_CAN_START_PROJECTS, "true");
        validCategoryList.add(categoryList.getFromValue("Groups"));
        validCategoryList.add(categoryList.getFromValue("People"));
        validCategoryList.add(categoryList.getFromValue("Events"));
        validCategoryList.add(categoryList.getFromValue("Ideas"));
        validCategoryList.add(categoryList.getFromValue("Projects"));
    } else if ("projects".equals(purpose)) {
        isPrivate = true;
        prefs.add(ApplicationPrefs.INFORMATION_IS_SENSITIVE, "true");
        prefs.add(ApplicationPrefs.USERS_CAN_REGISTER, "false");
        prefs.add(ApplicationPrefs.USERS_CAN_INVITE, "false");
        validCategoryList.add(categoryList.getFromValue("Groups"));
        validCategoryList.add(categoryList.getFromValue("People"));
        validCategoryList.add(categoryList.getFromValue("Projects"));
    } else if ("web".equals(purpose)) {
        validCategoryList.add(categoryList.getFromValue("Products"));
        validCategoryList.add(categoryList.getFromValue("Services"));
        validCategoryList.add(categoryList.getFromValue("Partners"));
        validCategoryList.add(categoryList.getFromValue("Groups"));
        validCategoryList.add(categoryList.getFromValue("People"));
        validCategoryList.add(categoryList.getFromValue("Events"));
        validCategoryList.add(categoryList.getFromValue("Ideas"));
        validCategoryList.add(categoryList.getFromValue("Projects"));
    }
    // Update the related tabs, or leave all enabled
    if (validCategoryList.size() > 0) {
        for (ProjectCategory category : categoryList) {
            category.setEnabled(validCategoryList.get(category) != null);
            category.setSensitive(isPrivate);
            category.update(db);
        }
    }

    // Determine the profile visibility
    project.setUpdateAllowGuests(true);
    project.setAllowGuests(isPrivate ? false : true);
    project.setUpdateAllowParticipants(true);
    project.setAllowParticipants(true);
    project.setUpdateMembershipRequired(true);
    project.setMembershipRequired(false);
    project.setApproved(true);

    // Determine the tabs
    project.setShowProfile(true);
    project.getFeatures().setLabelProfile("Overview");
    project.setShowNews(true);
    project.getFeatures().setLabelNews("Blog");
    project.setShowReviews(true);
    project.setShowWiki(true);
    project.setShowCalendar(true);
    project.setShowDiscussion(true);
    project.setShowDocuments(true);
    project.setShowClassifieds(true);
    project.setShowBadges(true);
    project.setShowLists(true);
    project.setShowIssues(true);
    project.setShowTeam(true);
    project.getFeatures().setLabelTickets("Issues");
    project.getFeatures().setLabelTeam("Participants");
    project.setShowMessages(true);

    // Determine the record details
    project.setUniqueId("main-profile");
    project.setGroupId(1);
    project.setCategoryId(categoryId);
    project.setOwner(1);
    project.setEnteredBy(1);
    project.setModifiedBy(1);
    project.insert(db);
    project.updateFeatures(db);
    project.setSystemDefault(true);
    project.updateSystemDefault(db);

    // Build a list of roles
    LookupList roleList = CacheUtils.getLookupList("lookup_project_role");

    // Build a list of the default permissions
    PermissionList permissionList = new PermissionList();
    permissionList.setProjectId(project.getId());
    permissionList.buildList(db);

    // Modify the permissions for the default profile
    LinkedHashMap<String, Integer> permissionMap = new LinkedHashMap<String, Integer>();
    permissionMap.put("project-tickets-view", TeamMember.MEMBER);
    permissionMap.put("project-tickets-other", TeamMember.CHAMPION);
    permissionMap.put("project-tickets-add", TeamMember.MEMBER);
    permissionMap.put("project-tickets-edit", TeamMember.CHAMPION);
    permissionMap.put("project-tickets-assign", TeamMember.CHAMPION);
    permissionMap.put("project-tickets-close", TeamMember.CHAMPION);
    permissionMap.put("project-tickets-delete", TeamMember.MANAGER);

    for (String name : permissionMap.keySet()) {
        Permission permission = permissionList.get(name);
        permission.setUserLevel(roleList.getIdFromLevel(permissionMap.get(name)));
        LOG.debug("Updating a permission: " + name);
        permission.update(db);
    }

    // Get the admin role
    int adminRowLevel = roleList.getIdFromValue("Manager");

    // Add the admins as a member
    UserList userList = new UserList();
    userList.setAdmin(Constants.TRUE);
    userList.buildList(db);
    for (User thisUser : userList) {
        TeamMember thisMember = new TeamMember();
        thisMember.setProjectId(project.getId());
        thisMember.setUserId(thisUser.getId());
        thisMember.setUserLevel(adminRowLevel);
        thisMember.setEnteredBy(1);
        thisMember.setModifiedBy(1);
        thisMember.insert(db);
    }
}

From source file:org.bdval.util.RewriteModelConditions.java

/**
 * Process the command line, read the input file, write the output file.
 *
 * @param args the command line arguments
 * @throws JSAPException problem parsing the command line
 * @throws IOException   problem read/writing the files
 *///  ww w. j  a  v  a  2s.  c o  m
@SuppressWarnings("unchecked")
private void process(final String[] args) throws JSAPException, IOException {
    if (!processCommandLine(args)) {
        return;
    }

    final File inputFile = new File(inputFilename);
    if (!inputFile.exists()) {
        return;
    }
    final File outputFile = new File(outputFilename);
    if (outputFile.exists()) {
        // This file CANNOT be appended to!
        outputFile.delete();
    }
    final PrintWriter outputWriter = new PrintWriter(new FileWriter(outputFile));

    final List<String> lines = FileUtils.readLines(new File(inputFilename));
    final List<String> columns = new LinkedList<String>();
    for (final String line : lines) {
        final LinkedHashMap<String, String> data = readData(line);
        for (final String column : sortColumns(data.keySet())) {
            if (!columns.contains(column)) {
                columns.add(column);
            }
        }
    }
    writeHeaders(outputWriter, columns);
    for (final String line : lines) {
        final LinkedHashMap<String, String> data = readData(line);
        writeData(outputWriter, columns, data);
    }
    outputWriter.flush();
    IOUtils.closeQuietly(outputWriter);
}

From source file:com.amalto.workbench.actions.XSDSetAnnotationDescriptionsAction.java

public IStatus doAction() {
    try {//from w  w  w .  j  a v a 2 s  .  co m

        IStructuredSelection selection = (TreeSelection) page.getTreeViewer().getSelection();
        XSDComponent xSDCom = null;
        if (selection.getFirstElement() instanceof Element) {
            TreePath tPath = ((TreeSelection) selection).getPaths()[0];
            for (int i = 0; i < tPath.getSegmentCount(); i++) {
                if (tPath.getSegment(i) instanceof XSDAnnotation)
                    xSDCom = (XSDAnnotation) (tPath.getSegment(i));
            }
        } else
            xSDCom = (XSDComponent) selection.getFirstElement();
        XSDAnnotationsStructure struc = new XSDAnnotationsStructure(xSDCom);
        if (struc.getAnnotation() == null) {
            throw new RuntimeException(
                    Messages.bind(Messages.XSDSetAnnotationXX_ExceptionInfo2, xSDCom.getClass().getName()));
        }

        AnnotationLanguageLabelsDialog dlg = new AnnotationLanguageLabelsDialog(struc.getDescriptions(),
                new AnnotationLabelDialogSelectionListener(page), page.getEditorSite().getShell(),
                Messages.XSDSetAnnotationXX_SetDescOfThisItem);
        dlg.setBlockOnOpen(true);
        dlg.open();

        if (dlg.getReturnCode() == Window.OK) {
            // remove existing annotations with labels
            struc.removeAllDescriptions();
            // add the new ones
            LinkedHashMap<String, String> descriptions = dlg.getDescriptionsMap();
            Set<String> isoCodes = descriptions.keySet();
            for (Iterator iter = isoCodes.iterator(); iter.hasNext();) {
                String isoCode = (String) iter.next();
                struc.setDescription(isoCode, descriptions.get(isoCode));
            }
        } else {
            return Status.CANCEL_STATUS;
        }

        if (struc.hasChanged()) {
            page.markDirty();
            page.refresh();
            page.getTreeViewer().expandToLevel(xSDCom, 2);
        }

    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error,
                Messages.bind(Messages.XSDSetAnnotationXX_ErrorMsg, e.getLocalizedMessage()));
        return Status.CANCEL_STATUS;
    }

    return Status.OK_STATUS;
}