Java 类org.apache.commons.collections.BidiMap 实例源码

项目:mule-intellij-plugins    文件:MuleSchemaProvider.java   
private Map<String, String> parseSpringSchemas(String springSchemasContent) {
    BidiMap schemaUrlsAndFileNames = new TreeBidiMap();
    for (String line : springSchemasContent.split("\n")) {
        if (line != null && !line.startsWith("#") && line.contains("=")) {
            String url = line.substring(0, line.indexOf("=")).replaceAll("\\\\", "");
            String fileName = line.substring(line.indexOf("=") + 1);

            if (schemaUrlsAndFileNames.containsValue(fileName)) {
                if (url.contains("current")) { //Avoid duplicates and prefer URL with "current"
                    schemaUrlsAndFileNames.removeValue(fileName);
                    schemaUrlsAndFileNames.put(url, fileName);
                }
            } else {
                schemaUrlsAndFileNames.put(url, fileName);
            }
        }
    }
    return schemaUrlsAndFileNames;
}
项目:OLE-INST    文件:AccountingLineViewField.java   
/**
 * parse the given lookup parameter string into a bidirectinal map
 * 
 * @param lookupParameters the lookup parameter string
 * @param accountingLinePrefix the actual accounting line prefix
 * @return a bidirectinal map that holds all the given lookup parameters
 */
private BidiMap buildBidirecionalMapFromParameters(String parameters, String accountingLinePrefix) {
    BidiMap parameterMap = new DualHashBidiMap();

    //  if we didnt get any incoming parameters, then just return an empty parameterMap 
    if (StringUtils.isBlank(parameters)) {
        return parameterMap;
    }

    String[] parameterArray = StringUtils.split(parameters, OLEConstants.FIELD_CONVERSIONS_SEPERATOR);

    for (String parameter : parameterArray) {
        String[] entrySet = StringUtils.split(parameter, OLEConstants.FIELD_CONVERSION_PAIR_SEPERATOR);

        if (entrySet != null) {
            String parameterKey = escapeAccountingLineName(entrySet[0], accountingLinePrefix);
            String parameterValue = escapeAccountingLineName(entrySet[1], accountingLinePrefix);

            parameterMap.put(parameterKey, parameterValue);
        }
    }

    return parameterMap;
}
项目:imcms    文件:ApplicationConfig.java   
@Autowired
@Bean
public Config imageArchiveConfig(Environment environment) {
    BidiMap languages = new DualHashBidiMap();
    languages.put("eng", "en");
    languages.put("swe", "sv");

    Config config = new Config();

    config.setStoragePath(new File(environment.getProperty("ImageArchiveStoragePath")));
    config.setTmpPath(new File(environment.getProperty("ImageArchiveTempPath")));
    config.setImageMagickPath(new File(environment.getProperty("ImageMagickPath")));
    config.setImagesPath(new File(environment.getProperty("ImageArchiveImagesPath")));
    config.setLibrariesPath(new File(environment.getProperty("ImageArchiveLibrariesPath")));
    config.setOldLibraryPaths(new File[]{new File(environment.getProperty("ImageArchiveOldLibraryPaths"))});
    config.setUsersLibraryFolder(environment.getProperty("ImageArchiveUsersLibraryFolder"));
    config.setMaxImageUploadSize(Long.parseLong(environment.getProperty("ImageArchiveMaxImageUploadSize")));
    config.setMaxZipUploadSize(Long.parseLong(environment.getProperty("ImageArchiveMaxZipUploadSize")));
    config.setLanguages(languages);
    return config;
}
项目:kfs    文件:AccountingLineViewField.java   
/**
 * parse the given lookup parameter string into a bidirectinal map
 *
 * @param lookupParameters the lookup parameter string
 * @param accountingLinePrefix the actual accounting line prefix
 * @return a bidirectinal map that holds all the given lookup parameters
 */
private BidiMap buildBidirecionalMapFromParameters(String parameters, String accountingLinePrefix) {
    BidiMap parameterMap = new DualHashBidiMap();

    //  if we didnt get any incoming parameters, then just return an empty parameterMap
    if (StringUtils.isBlank(parameters)) {
        return parameterMap;
    }

    String[] parameterArray = StringUtils.split(parameters, KFSConstants.FIELD_CONVERSIONS_SEPERATOR);

    for (String parameter : parameterArray) {
        String[] entrySet = StringUtils.split(parameter, KFSConstants.FIELD_CONVERSION_PAIR_SEPERATOR);

        if (entrySet != null) {
            String parameterKey = escapeAccountingLineName(entrySet[0], accountingLinePrefix);
            String parameterValue = escapeAccountingLineName(entrySet[1], accountingLinePrefix);

            parameterMap.put(parameterKey, parameterValue);
        }
    }

    return parameterMap;
}
项目:levelup-java-examples    文件:ReverseMapLookup.java   
@Test
public void flip_map_entries_with_apachecommons() {

    BidiMap stateCodeToDescription = new DualHashBidiMap();

    stateCodeToDescription.put("WI", "Wisconsin");
    stateCodeToDescription.put("MN", "Minnesota");
    stateCodeToDescription.put("FL", "Florida");
    stateCodeToDescription.put("IA", "Iowa");
    stateCodeToDescription.put("OH", "Ohio");

    BidiMap descriptionToStateCode = stateCodeToDescription
            .inverseBidiMap();

    logger.info(descriptionToStateCode);

    assertEquals("IA", descriptionToStateCode.get("Iowa"));
}
项目:jasperreports    文件:JRCsvDataSource.java   
protected void assignColumnNames()
{
    BidiMap indexColumns = new DualHashBidiMap();
    for (int i = 0; i < crtRecordColumnValues.size(); i++)
    {
        String name = crtRecordColumnValues.get(i);

        Integer existingIdx = (Integer) indexColumns.getKey(name);
        if (existingIdx == null)
        {
            //use the name from the file if possible
            indexColumns.put(i, name);
        }
        else
        {
            //the name is taken, force COLUMN_i for this column and recursively if COLUMN_x is already used
            Integer forceIndex = i;
            do
            {
                String indexName = INDEXED_COLUMN_PREFIX + forceIndex;
                Integer existingIndex = (Integer) indexColumns.getKey(indexName);
                indexColumns.put(forceIndex, indexName);
                forceIndex = existingIndex;
            }
            while(forceIndex != null);
        }
    }

    this.columnNames = new LinkedHashMap<String, Integer>();
    for (int i = 0; i < crtRecordColumnValues.size(); i++)
    {
        String columnName = (String) indexColumns.get(i);
        this.columnNames.put(columnName, i);
    }
}
项目:bsming    文件:MyMapUtil.java   
/**
 * 根据值反向获取key
 * @param <R>
 * @param <T>
 * @param source 
 * @param valueList Map的值集合
 * @return Map的key集合
 */
public static <R,T> List<R> getKeyListByValueList(BidiMap source,List<T> valueList){
    if(null == source || null == valueList){
        return new ArrayList<R>();
    }
    List<R> result = new ArrayList<R>();
    for(T value : valueList){
        R key = (R) source.getKey(value);
        if(null == key){
            continue;
        }
        result.add(key);
    }
    return result;
}
项目:runningdinner    文件:UploadFileModel.java   
private static NameColumnConfig createNameColumnConfig(final Set<String> columnMappingNames, final BidiMap bidirectionalColumnMappings) {
    if (columnMappingNames.contains(ColumnMappingOption.FULLNAME)) {
        Integer columnIndex = (Integer)bidirectionalColumnMappings.getKey(ColumnMappingOption.FULLNAME);
        return NameColumnConfig.createForOneColumn(columnIndex);
    }
    else {
        Integer firstNameColumnIndex = (Integer)bidirectionalColumnMappings.getKey(ColumnMappingOption.FIRSTNAME);
        Integer lastNameColumnIndex = (Integer)bidirectionalColumnMappings.getKey(ColumnMappingOption.LASTNAME);
        return NameColumnConfig.createForTwoColumns(firstNameColumnIndex, lastNameColumnIndex);
    }
}
项目:pentaho-kettle    文件:DateDetector.java   
public static BidiMap getDateFormatToRegExps( String locale ) {
  if ( locale == null || LOCALE_en_US.equalsIgnoreCase( locale ) ) {
    return DATE_FORMAT_TO_REGEXPS_US;
  } else {
    return DATE_FORMAT_TO_REGEXPS;
  }
}
项目:pentaho-kettle    文件:DateDetectorTest.java   
private void testPatternsFrom( BidiMap formatToRegExps, String locale ) {
  Iterator iterator = formatToRegExps.keySet().iterator();
  while ( iterator.hasNext() ) {
    String pattern = (String) iterator.next();
    String dateString = buildTestDate( pattern );
    assertEquals( "Did not detect a matching date pattern using the date \"" + dateString + "\"", pattern,
        DateDetector.detectDateFormatBiased( dateString, locale, pattern ) );
  }
}
项目:argument-reasoning-comprehension-task    文件:AnnotationSpans.java   
public static AnnotationSpans extractAnnotationSpans(JCas jCas)
{
    BidiMap sentenceBeginIndexToCharacterIndex = new TreeBidiMap();
    BidiMap sentenceEndIndexToCharacterIndex = new TreeBidiMap();

    List<Sentence> sentences = new ArrayList<>(JCasUtil.select(jCas, Sentence.class));
    for (int i = 0; i < sentences.size(); i++) {
        Sentence sentence = sentences.get(i);

        sentenceBeginIndexToCharacterIndex.put(i, sentence.getBegin());
        sentenceEndIndexToCharacterIndex.put(i, sentence.getEnd());
    }

    //        System.out.println(sentenceBeginIndexToCharacterIndex);
    //        System.out.println(sentenceEndIndexToCharacterIndex);

    AnnotationSpans annotationSpans = new AnnotationSpans(
            sentenceBeginIndexToCharacterIndex.size());

    Collection<ArgumentComponent> components = JCasUtil.select(jCas, ArgumentComponent.class);

    for (ArgumentComponent component : components) {
        if (!ArgumentUnitUtils.isImplicit(component)) {
            //            System.out.println("=====");
            //            System.out.println(component.getCoveredText());
            int relativeOffset = (int) sentenceBeginIndexToCharacterIndex
                    .getKey(component.getBegin());

            int endingSentenceIndex = (int) sentenceEndIndexToCharacterIndex
                    .getKey(component.getEnd());

            int length = endingSentenceIndex - relativeOffset + 1;

            String type = component.getType().getShortName();

            SingleAnnotationSpan singleAnnotationSpan = new SingleAnnotationSpan(type,
                    relativeOffset, length);

            annotationSpans.getAnnotationSpans().add(singleAnnotationSpan);
        }
    }

    return annotationSpans;
}
项目:imcms    文件:Config.java   
public BidiMap getLanguages() {
    return languages;
}
项目:imcms    文件:Config.java   
public void setLanguages(BidiMap languages) {
    this.languages = languages;
}
项目:nci-term-browser    文件:ScoreTerm.java   
/**
 * Display results to the user.
 * @param result
 */
protected void printReport(BidiMap result) {
    final String Dash6  = "------";
    final String Dash10 = "----------";
    final String Dash60 = "------------------------------------------------------------";

    Formatter f = new Formatter();

    // Print header.
    String format = "%-5.5s|%-10.10s|%-60.60s\n";
    Object[] hSep = new Object[] { Dash6, Dash10, Dash60 };
    f.format(format, hSep);
    f.format(format, new Object[] { "Score", "Code", "Term" });
    f.format(format, hSep);

    // Iterate over the result.
    for (MapIterator items = result.inverseBidiMap().mapIterator(); items.hasNext(); ) {
        ScoredTerm st = (ScoredTerm) items.next();
        String code = (String) items.getValue();

        // Evaluate code
        if (code != null && code.length() > 10)
            code = code.substring(0, 7) + "...";

        // Evaluate term (wrap if necessary)
        String term = st.term;
        if (term != null && term.length() < 60)
            f.format(format, new Object[] {st.score, code, term });
        else {
            String sub = term.substring(0, 60);
            f.format(format, new Object[] {st.score, code, sub });
            int begin = 60; int end = term.length();
            while (begin < end) {
                sub = term.substring(begin, Math.min(begin+60, end));
                f.format(format, new Object[] {"", "", sub });
                begin+=60;
            }
        }
    }
    Util.displayMessage(f.out().toString());
}
项目:clickwatch    文件:FoldingTransformer.java   
/**
 * Creates a <code>Graph</code> which is a "folded" version of <code>h</code>.
 * 
 * <p>If <code>use_vertices</code> is true, the vertices of the new graph 
 * correspond to the vertices of <code>h</code>, and <code>a</code> 
 * is connected to <code>b</code> in the new graph if the corresponding vertices
 * in <code>h</code> are connected by a hyperedge.  Thus, each hyperedge with 
 * <i>k</i> vertices in <code>h</code> would induce a <i>k</i>-clique in the new graph.</p>
 * 
 * <p>If <code>use_vertices</code> is false, then the vertices of the new
 * graph correspond to the hyperedges of <code>h</code>, and <code>a</code>
 * is connected to <code>b</code> in the new graph if the corresponding hyperedges
 * in <code>h</code> share a vertex.  Thus, each vertex connected to <i>k</i> 
 * hyperedges in <code>h</code> would induce a <i>k</i>-clique in the new graph.</p>
 * 
 * <p>If <code>nev</code> is null, 
 * adds the connecting element as a decoration on the corresponding edge in the new
 * graph; otherwise, sets the weight of each edge to the number of parallel 
 * paths between the corresponding vertices in the original graph that are 
 * encountered in the folding process.</p>
 */
public Graph fold(Hypergraph h, Graph target, boolean use_vertices, NumberEdgeValue nev, BidiMap map)
{
    undirected = true;

    if (target == null)
        target = createGraph();

    VertexGenerator vg = GraphUtils.getVertexGenerator(target);
    if (vg == null)
        vg = new TypedVertexGenerator(target);

    Map m = new HashMap();
    Set vertices;
    Set edges;

    // vertices and hyperedges are duals of one another; we can treat
    // them equivalently for this purpose
    if (use_vertices)
    {
        vertices = h.getVertices();
        edges = h.getEdges();
    }
    else
    {
        vertices = h.getEdges();
        edges = h.getVertices();
    }

    // create vertices:
    // for each "vertex", create a new vertex and import user data
    for (Iterator iter = vertices.iterator(); iter.hasNext(); )
    {
        Element av = (Element)iter.next();
        Vertex v = vg.create();
        v.importUserData(av);
        target.addVertex(v);
        m.put(av, v);
        map.put(v, av);
    }

    // create edges:
    // for each "hyperedge", create an edge between each incident vertex pair
    for (Iterator iter = edges.iterator(); iter.hasNext(); )
    {
        Element he = (Element)iter.next();
        Set elts = he.getIncidentElements();
        Vertex[] v_array = new Vertex[elts.size()];
        int i = 0;
        for (Iterator e_iter = elts.iterator(); e_iter.hasNext(); )
            v_array[i++] = (Vertex)(m.get(e_iter.next()));
        for (i = 0; i < v_array.length; i++)
            for (int j = i + 1; j < v_array.length; j++)
                addEdge(target, v_array[i], he, v_array[j], nev);
    }

    return target;
}
项目:OLE-INST    文件:AccountingLineViewField.java   
/**
 * build the lookup parameter map through applying the override parameters onto the defaults
 * 
 * @param lookupParameters the default lookup parameter string
 * @param overrideLookupParameters the override lookup parameter string
 * @param accountingLinePrefix the actual accounting line prefix
 * @return the actual lookup parameter map
 */
private Map<String, String> getActualParametersMap(String parameters, String overrideParameters, String accountingLinePrefix) {
    BidiMap parametersMap = this.buildBidirecionalMapFromParameters(parameters, accountingLinePrefix);
    BidiMap overrideParametersMap = this.buildBidirecionalMapFromParameters(overrideParameters, accountingLinePrefix);
    parametersMap.putAll(overrideParametersMap);

    return parametersMap;
}
项目:kfs    文件:AccountingLineViewField.java   
/**
 * build the lookup parameter map through applying the override parameters onto the defaults
 *
 * @param lookupParameters the default lookup parameter string
 * @param overrideLookupParameters the override lookup parameter string
 * @param accountingLinePrefix the actual accounting line prefix
 * @return the actual lookup parameter map
 */
private Map<String, String> getActualParametersMap(String parameters, String overrideParameters, String accountingLinePrefix) {
    BidiMap parametersMap = this.buildBidirecionalMapFromParameters(parameters, accountingLinePrefix);
    BidiMap overrideParametersMap = this.buildBidirecionalMapFromParameters(overrideParameters, accountingLinePrefix);
    parametersMap.putAll(overrideParametersMap);

    return parametersMap;
}