org.apache.commons.collections.BidiMap Java Examples

The following examples show how to use org.apache.commons.collections.BidiMap. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ReverseMapLookup.java    From levelup-java-examples with Apache License 2.0 6 votes vote down vote up
@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"));
}
 
Example #2
Source File: AccountingLineViewField.java    From kfs with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #3
Source File: MuleSchemaProvider.java    From mule-intellij-plugins with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #4
Source File: DateDetectorTest.java    From hop with Apache License 2.0 5 votes vote down vote up
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 ) );
  }
}
 
Example #5
Source File: DateDetectorTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
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 ) );
  }
}
 
Example #6
Source File: DateDetector.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
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;
  }
}
 
Example #7
Source File: CommonsTest.java    From java-study with Apache License 2.0 5 votes vote down vote up
/**
 * 双向Map
 * 唯一的key和map,可以通过键或值来操作
 * 比如删除、查询等
 */
private static void bidimapTest(){
	BidiMap map=new TreeBidiMap();
	map.put(1, "a");
	map.put(2, "b");
	map.put(3, "c");
	System.out.println("map:"+map);	//map:{1=a, 2=b, 3=c}
	System.out.println("map.get():"+map.get(2)); //map.get():b
	System.out.println("map.getKey():"+map.getKey("a")); //map.getKey():1
	System.out.println("map.removeValue():"+map.removeValue("c")); //map.removeValue():3
	System.out.println("map:"+map);	//map:{1=a, 2=b}
}
 
Example #8
Source File: DateDetector.java    From hop with Apache License 2.0 5 votes vote down vote up
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;
  }
}
 
Example #9
Source File: UnmodifiableBidiMap.java    From Penetration_Testing_POC with Apache License 2.0 5 votes vote down vote up
public BidiMap inverseBidiMap() {
    if (inverse == null) {
        inverse = new UnmodifiableBidiMap(getBidiMap().inverseBidiMap());
        inverse.inverse = this;
    }
    return inverse;
}
 
Example #10
Source File: UnmodifiableOrderedBidiMap.java    From Penetration_Testing_POC with Apache License 2.0 4 votes vote down vote up
public BidiMap inverseBidiMap() {
    return inverseOrderedBidiMap();
}
 
Example #11
Source File: UnmodifiableSortedBidiMap.java    From Penetration_Testing_POC with Apache License 2.0 4 votes vote down vote up
public BidiMap inverseBidiMap() {
    return inverseSortedBidiMap();
}
 
Example #12
Source File: AbstractDualBidiMap.java    From Penetration_Testing_POC with Apache License 2.0 4 votes vote down vote up
public BidiMap inverseBidiMap() {
    if (inverseBidiMap == null) {
        inverseBidiMap = createBidiMap(maps[1], maps[0], this);
    }
    return inverseBidiMap;
}
 
Example #13
Source File: TreeBidiMap.java    From Penetration_Testing_POC with Apache License 2.0 4 votes vote down vote up
public BidiMap inverseBidiMap() {
    return main;
}
 
Example #14
Source File: AbstractBidiMapDecorator.java    From Penetration_Testing_POC with Apache License 2.0 4 votes vote down vote up
public BidiMap inverseBidiMap() {
    return getBidiMap().inverseBidiMap();
}
 
Example #15
Source File: AnnotationSpans.java    From argument-reasoning-comprehension-task with Apache License 2.0 4 votes vote down vote up
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;
}
 
Example #16
Source File: UnmodifiableBidiMap.java    From Penetration_Testing_POC with Apache License 2.0 3 votes vote down vote up
/**
 * Factory method to create an unmodifiable map.
 * <p>
 * If the map passed in is already unmodifiable, it is returned.
 * 
 * @param map  the map to decorate, must not be null
 * @return an unmodifiable BidiMap
 * @throws IllegalArgumentException if map is null
 */
public static BidiMap decorate(BidiMap map) {
    if (map instanceof Unmodifiable) {
        return map;
    }
    return new UnmodifiableBidiMap(map);
}
 
Example #17
Source File: AbstractDualBidiMap.java    From Penetration_Testing_POC with Apache License 2.0 3 votes vote down vote up
/** 
 * Constructs a map that decorates the specified maps,
 * used by the subclass <code>createBidiMap</code> implementation.
 *
 * @param normalMap  the normal direction map
 * @param reverseMap  the reverse direction map
 * @param inverseBidiMap  the inverse BidiMap
 */
protected AbstractDualBidiMap(Map normalMap, Map reverseMap, BidiMap inverseBidiMap) {
    super();
    maps[0] = normalMap;
    maps[1] = reverseMap;
    this.inverseBidiMap = inverseBidiMap;
}
 
Example #18
Source File: AccountingLineViewField.java    From kfs with GNU Affero General Public License v3.0 3 votes vote down vote up
/**
 * 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;
}
 
Example #19
Source File: AbstractBidiMapDecorator.java    From Penetration_Testing_POC with Apache License 2.0 2 votes vote down vote up
/**
 * Gets the map being decorated.
 * 
 * @return the decorated map
 */
protected BidiMap getBidiMap() {
    return (BidiMap) map;
}
 
Example #20
Source File: UnmodifiableBidiMap.java    From Penetration_Testing_POC with Apache License 2.0 2 votes vote down vote up
/**
 * Constructor that wraps (not copies).
 * 
 * @param map  the map to decorate, must not be null
 * @throws IllegalArgumentException if map is null
 */
private UnmodifiableBidiMap(BidiMap map) {
    super(map);
}
 
Example #21
Source File: TreeBidiMap.java    From Penetration_Testing_POC with Apache License 2.0 2 votes vote down vote up
/**
 * Gets the inverse map for comparison.
 * 
 * @return the inverse map
 */
public BidiMap inverseBidiMap() {
    return inverseOrderedBidiMap();
}
 
Example #22
Source File: AbstractBidiMapDecorator.java    From Penetration_Testing_POC with Apache License 2.0 2 votes vote down vote up
/**
 * Constructor that wraps (not copies).
 *
 * @param map  the map to decorate, must not be null
 * @throws IllegalArgumentException if the collection is null
 */
protected AbstractBidiMapDecorator(BidiMap map) {
    super(map);
}
 
Example #23
Source File: AbstractDualBidiMap.java    From Penetration_Testing_POC with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new instance of the subclass.
 * 
 * @param normalMap  the normal direction map
 * @param reverseMap  the reverse direction map
 * @param inverseMap  this map, which is the inverse in the new map
 * @return the inverse map
 */
protected abstract BidiMap createBidiMap(Map normalMap, Map reverseMap, BidiMap inverseMap);
 
Example #24
Source File: DualTreeBidiMap.java    From Penetration_Testing_POC with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new instance of this object.
 * 
 * @param normalMap  the normal direction map
 * @param reverseMap  the reverse direction map
 * @param inverseMap  the inverse BidiMap
 * @return new bidi map
 */
protected BidiMap createBidiMap(Map normalMap, Map reverseMap, BidiMap inverseMap) {
    return new DualTreeBidiMap(normalMap, reverseMap, inverseMap);
}
 
Example #25
Source File: DualTreeBidiMap.java    From Penetration_Testing_POC with Apache License 2.0 2 votes vote down vote up
/** 
 * Constructs a <code>DualTreeBidiMap</code> that decorates the specified maps.
 *
 * @param normalMap  the normal direction map
 * @param reverseMap  the reverse direction map
 * @param inverseBidiMap  the inverse BidiMap
 */
protected DualTreeBidiMap(Map normalMap, Map reverseMap, BidiMap inverseBidiMap) {
    super(normalMap, reverseMap, inverseBidiMap);
    this.comparator = ((SortedMap) normalMap).comparator();
}
 
Example #26
Source File: DualHashBidiMap.java    From Penetration_Testing_POC with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new instance of this object.
 * 
 * @param normalMap  the normal direction map
 * @param reverseMap  the reverse direction map
 * @param inverseBidiMap  the inverse BidiMap
 * @return new bidi map
 */
protected BidiMap createBidiMap(Map normalMap, Map reverseMap, BidiMap inverseBidiMap) {
    return new DualHashBidiMap(normalMap, reverseMap, inverseBidiMap);
}
 
Example #27
Source File: DualHashBidiMap.java    From Penetration_Testing_POC with Apache License 2.0 2 votes vote down vote up
/** 
 * Constructs a <code>HashBidiMap</code> that decorates the specified maps.
 *
 * @param normalMap  the normal direction map
 * @param reverseMap  the reverse direction map
 * @param inverseBidiMap  the inverse BidiMap
 */
protected DualHashBidiMap(Map normalMap, Map reverseMap, BidiMap inverseBidiMap) {
    super(normalMap, reverseMap, inverseBidiMap);
}