org.apache.commons.collections.KeyValue Java Examples

The following examples show how to use org.apache.commons.collections.KeyValue. 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: TestAdressBean.java    From gsn with GNU General Public License v3.0 6 votes vote down vote up
@Test@Ignore
public void testEqualsObject() {
	KeyValue[] predicates1 = new KeyValue[2];
	KeyValue[] predicates2 = new KeyValue[2];
	predicates1[0] = new KeyValueImp("key1", "val1");
	predicates2[0] = new KeyValueImp("key1", "val1");
	
	predicates1[1] = new KeyValueImp("key2", "val2");
	predicates2[1] = new KeyValueImp("key2", "val2");
	addressBean1 = new AddressBean("wrapper", predicates1);
	addressBean2 = new AddressBean("wrapper", predicates2);
	assertEquals(addressBean1, addressBean2);
	predicates1[0] = new KeyValueImp("val1", "key1");
	assertFalse(addressBean1.equals(addressBean2));
	addressBean1 = new AddressBean("wrapper", new KeyValueImp("key1", "key2"));
	assertFalse(addressBean1.equals(addressBean2));	
}
 
Example #2
Source File: TestAdressBean.java    From gsn with GNU General Public License v3.0 6 votes vote down vote up
@Test@Ignore
public void testHashCode() {
	KeyValue[] predicates1 = new KeyValue[2];
	KeyValue[] predicates2 = new KeyValue[2];
	predicates1[0] = new KeyValueImp("key1", "val1");
	predicates2[0] = new KeyValueImp("key1", "val1");
	
	predicates1[1] = new KeyValueImp("key2", "val2");
	predicates2[1] = new KeyValueImp("key2", "val2");
	addressBean1 = new AddressBean("wrapper", predicates1);
	addressBean2 = new AddressBean("wrapper", predicates2);
	assertEquals(addressBean1.hashCode(), addressBean2.hashCode());
	predicates1[0] = new KeyValueImp("val1", "key1");
	assertTrue(addressBean1.hashCode() != addressBean2.hashCode());
	addressBean1 = new AddressBean("wrapper", new KeyValueImp("key1", "key2"));
	assertTrue(addressBean1.hashCode() != addressBean2.hashCode());		
}
 
Example #3
Source File: TestStreamExporterVirtualSensor.java    From gsn with GNU General Public License v3.0 5 votes vote down vote up
public void testConnectToExistingMySQLDB ( ) {
   StreamExporterVirtualSensor vs = new StreamExporterVirtualSensor( );
   ArrayList < KeyValue > params = new ArrayList < KeyValue >( );
   params.add( new KeyValueImp( StreamExporterVirtualSensor.PARAM_URL , url ) );
   params.add( new KeyValueImp( StreamExporterVirtualSensor.PARAM_USER , user ) );
   params.add( new KeyValueImp( StreamExporterVirtualSensor.PARAM_PASSWD , passwd ) );
   config.setMainClassInitialParams( params );
   vs.setVirtualSensorConfiguration( config );
   assertTrue( vs.initialize( ) );
}
 
Example #4
Source File: VSensorConfig.java    From gsn with GNU General Public License v3.0 5 votes vote down vote up
public String[][] getRPCFriendlyAddressing() {
	String[][] toReturn = new String[this.addressing.length][2] ;
	for(int i=0;i<toReturn.length;i++)
		for (KeyValue val : this.addressing) {
			toReturn[i][0] = ( String ) val.getKey( );
			toReturn[i][1] = ( String ) val.getValue( );
		}
	return toReturn;
}
 
Example #5
Source File: AddressBean.java    From gsn with GNU General Public License v3.0 5 votes vote down vote up
public String toString ( ) {
	final StringBuffer result = new StringBuffer( "[" ).append( this.getWrapper( ) );
	for ( final KeyValue predicate : this.predicates ) {
		result.append( predicate.getKey( ) + " = " + predicate.getValue( ) + "," );
	}
	result.append( "]" );
	return result.toString( );
}
 
Example #6
Source File: VSensorConfig.java    From gsn with GNU General Public License v3.0 5 votes vote down vote up
public String [ ] getAddressingKeys ( ) {
	final String result[] = new String [ this.getAddressing( ).length ];
	int counter = 0;
	for ( final KeyValue predicate : this.getAddressing( ) )
		result[ counter++ ] = ( String ) predicate.getKey( );
	return result;
}
 
Example #7
Source File: VSensorConfig.java    From gsn with GNU General Public License v3.0 5 votes vote down vote up
public String [ ] getAddressingValues ( ) {
	final String result[] = new String [ this.getAddressing( ).length ];
	int counter = 0;
	for ( final KeyValue predicate : this.getAddressing( ) )
		result[ counter++ ] = ( String ) predicate.getValue( );
	return result;
}
 
Example #8
Source File: VSensorConfig.java    From gsn with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Note that the key and value both are trimmed before being inserted into
 * the data strcture.
 * 
 * @return
 */
public TreeMap < String , String > getMainClassInitialParams ( ) {
	if ( !this.isGetMainClassInitParamsInitialized ) {
		this.isGetMainClassInitParamsInitialized = true;
		for ( final KeyValue param : this.mainClassInitialParams ) {
			this.mainClassInitParams.put( param.getKey( ).toString( ).toLowerCase( ) , param.getValue( ).toString( ) );
		}
	}
	return this.mainClassInitParams;
}
 
Example #9
Source File: AddressBean.java    From gsn with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Note that the key for the value is case insensitive.
 * 
 * @param key
 * @return
 */

public String getPredicateValue ( String key ) {
	key = key.trim( );
	for (  KeyValue predicate : this.predicates ) {
		if ( predicate.getKey( ).toString( ).trim( ).equalsIgnoreCase( key ) ) return ( ( String ) predicate.getValue( ));
	}
	return null;
}
 
Example #10
Source File: VSensorConfig.java    From gsn with GNU General Public License v3.0 5 votes vote down vote up
public String toString ( ) {
	final StringBuilder builder = new StringBuilder( "Input Stream [" );
	for ( final InputStream inputStream : this.getInputStreams( ) ) {
		builder.append( "Input-Stream-Name" ).append( inputStream.getInputStreamName( ) );
		builder.append( "Input-Stream-Query" ).append( inputStream.getQuery( ) );
		builder.append( " Stream-Sources ( " );
		if ( inputStream.getSources( ) == null )
			builder.append( "null" );
		else
			for ( final StreamSource ss : inputStream.getSources( ) ) {
				builder.append( "Stream-Source Alias : " ).append( ss.getAlias( ) );
				for ( final AddressBean addressing : ss.getAddressing( ) ) {
					builder.append( "Stream-Source-wrapper >" ).append( addressing.getWrapper( ) ).append( "< with addressign predicates : " );
					for ( final KeyValue keyValue : addressing.getPredicates( ) )
						builder.append( "Key=" ).append( keyValue.getKey( ) ).append( "Value=" ).append( keyValue.getValue( ) );
				}
				builder.append( " , " );
			}
		builder.append( ")" );
	}
	builder.append( "]" );
	return "VSensorConfig{" + "name='" + this.name + '\'' + ", priority=" + this.priority + ", mainClass='" + this.mainClass + '\'' 
	+ ", description='" + this.description + '\'' + ", outputStreamRate=" + this.outputStreamRate
	+ ", addressing=" + this.addressing + ", outputStructure=" + this.outputStructure + ", storageHistorySize='" + this.storageHistorySize + '\'' + builder.toString( )
	+ ", mainClassInitialParams=" + this.mainClassInitialParams + ", lastModified=" + this.lastModified + ", fileName='" + this.fileName + '\'' + ", logger=" + this.logger + ", nameInitialized="
	+ this.nameInitialized + ", isStorageCountBased=" + this.isStorageCountBased + ", parsedStorageSize=" + this.parsedStorageSize + '}';
}
 
Example #11
Source File: VSensorConfig.java    From gsn with GNU General Public License v3.0 5 votes vote down vote up
public void preprocess_addressing() {
	if (!addressing_processed) {
		for (KeyValue kv:getAddressing())
			if (kv.getKey().toString().equalsIgnoreCase("altitude"))
				cached_altitude=Double.parseDouble(kv.getValue().toString());
			else if (kv.getKey().toString().equalsIgnoreCase("longitude"))
				cached_longitude=Double.parseDouble(kv.getValue().toString());
			else if (kv.getKey().toString().equalsIgnoreCase("latitude"))
				cached_latitude=Double.parseDouble(kv.getValue().toString());
		addressing_processed=true;
	}
}
 
Example #12
Source File: AddressBean.java    From gsn with GNU General Public License v3.0 5 votes vote down vote up
public String getPredicateValueWithException ( String key ) {
	key = key.trim( );
	for (  KeyValue predicate : this.predicates ) {
		if ( predicate.getKey( ).toString( ).trim( ).equalsIgnoreCase( key ) ) {
			final String value = ( String ) predicate.getValue( );
			if (value.trim().length()>0)
				return ( value);
		}
	}
	throw new RuntimeException("The required parameter: >"+key+"<+ is missing.from the virtual sensor configuration file.");
}
 
Example #13
Source File: AddressBean.java    From gsn with GNU General Public License v3.0 5 votes vote down vote up
public AddressBean ( final String wrapper , KeyValue... newPredicates ) {
	this.wrapper = wrapper;
	if (newPredicates == null)
		this.predicates=EMPTY_PREDICATES;
	else
		this.predicates = newPredicates;
}
 
Example #14
Source File: TestStreamExporterVirtualSensor.java    From gsn with GNU General Public License v3.0 4 votes vote down vote up
public void testLogStatementIntoMySQLDB ( ) {
   StreamExporterVirtualSensor vs = new StreamExporterVirtualSensor( );
   // configure parameters
   ArrayList < KeyValue > params = new ArrayList < KeyValue >( );
   params.add( new KeyValueImp( StreamExporterVirtualSensor.PARAM_URL , url ) );
   params.add( new KeyValueImp( StreamExporterVirtualSensor.PARAM_USER , user ) );
   params.add( new KeyValueImp( StreamExporterVirtualSensor.PARAM_PASSWD , passwd ) );
   config.setMainClassInitialParams( params );
   vs.setVirtualSensorConfiguration( config );
   vs.initialize( );
   
   // configure datastream
   Vector < DataField > fieldTypes = new Vector < DataField >( );
   Object [ ] data = null;
   
   for ( String type : DataTypes.TYPE_NAMES )
      fieldTypes.add( new DataField( type , type , type ) );
   int i = 0;
   for ( Object value : DataTypes.TYPE_SAMPLE_VALUES )
      data[ i++ ] = value;
   
   long timeStamp = new Date( ).getTime( );
   StreamElement streamElement = new StreamElement( fieldTypes.toArray( new DataField[] {} ) , ( Serializable [ ] ) data , timeStamp );
   
   // give datastream to vs
   vs.dataAvailable( streamName , streamElement );
   
   // clean up and control
   boolean result = true;
   try {
      DriverManager.registerDriver( new com.mysql.jdbc.Driver( ) );
      Connection connection = DriverManager.getConnection( url , user , passwd );
      Statement statement = connection.createStatement( );
      statement.execute( "SELECT * FROM " + streamName );
      System.out.println( "result" + result );
      result = statement.getResultSet( ).last( );
      System.out.println( "result" + result );
   } catch ( SQLException e ) {
      // TODO Auto-generated catch block
      e.printStackTrace( );
      result = false;
   }
   assertTrue( result );
}
 
Example #15
Source File: SingletonMap.java    From Penetration_Testing_POC with Apache License 2.0 4 votes vote down vote up
/**
 * Constructor specifying the key and value as a <code>KeyValue</code>.
 *
 * @param keyValue  the key value pair to use
 */
public SingletonMap(KeyValue keyValue) {
    super();
    this.key = keyValue.getKey();
    this.value = keyValue.getValue();
}
 
Example #16
Source File: AddressBean.java    From gsn with GNU General Public License v3.0 4 votes vote down vote up
public  KeyValue[] getPredicates() {
	return this.predicates;
}
 
Example #17
Source File: BeansInitializer.java    From gsn with GNU General Public License v3.0 4 votes vote down vote up
public static VSensorConfig vsensor(VsConf vs){
 VSensorConfig v=new VSensorConfig();
 v.setMainClass(vs.processing().className());
 v.setDescription(vs.description());
 v.setName(vs.name());
 v.setIsTimeStampUnique(vs.processing().uniqueTimestamp());
 if (vs.poolSize().isDefined())
   v.setLifeCyclePoolSize(((Integer)vs.poolSize().get()));
 if (vs.processing().rate().isDefined())
   v.setOutputStreamRate(((Integer)vs.processing().rate().get()));
 v.setPriority(vs.priority());
 KeyValueImp [] addr=new KeyValueImp[vs.address().size()];
    Iterable<String> keys=JavaConversions.asJavaIterable(vs.address().keys());
    int i=0;
 for (String k:keys){
  addr[i]=new KeyValueImp(k,vs.address().apply(k));
  i++;
 }
 v.setAddressing(addr);
 InputStream[] is=new InputStream[vs.streams().size()];
 for (int j=0;j<is.length;j++){
  is[j]=stream(vs.streams().apply(j));
 }
 v.setInputStreams(is);
 if (vs.processing().webInput().isDefined()){
  WebInputConf wic=vs.processing().webInput().get();
  v.setWebParameterPassword(wic.password());
  WebInput[] wi=new WebInput[wic.commands().size()];
  for (int j=0;j<wi.length;j++){
	  wi[j]=webInput(wic.commands().apply(j));
  }
  v.setWebInput(wi);
 }
 DataField [] out=new DataField[(vs.processing().output().size())];
 for (int j=0;j<out.length;j++){
  out[j]=dataField(vs.processing().output().apply(j));
 }
 v.setOutputStructure(out);
 Map<String,String> init=vs.processing().initParams();
 ArrayList<KeyValue> ini=new ArrayList<KeyValue>();
    Iterable<String> initkeys=JavaConversions.asJavaIterable(init.keys());
 for (String ik:initkeys){
  logger.trace("keys:"+ik);
  ini.add(new KeyValueImp(ik.toLowerCase(),init.apply(ik)));
 }
 v.setMainClassInitialParams(ini);
 
 StorageConfig st=new StorageConfig();
 if (vs.storageSize().isDefined())
  st.setStorageSize(vs.storageSize().get());
 if (vs.storage().isDefined()){
StorageConf sc=vs.storage().get();
if (sc.identifier().isDefined())
  st.setIdentifier(sc.identifier().get());
st.setJdbcDriver(sc.driver());
st.setJdbcURL(sc.url());
st.setJdbcUsername(sc.user());
st.setJdbcPassword(sc.pass());		
 }
 if (st.getStorageSize()!=null || st.getJdbcURL()!=null)
v.setStorage(st);
 return v;
}
 
Example #18
Source File: VSensorConfig.java    From gsn with GNU General Public License v3.0 4 votes vote down vote up
public void setMainClassInitialParams ( final ArrayList < KeyValue > mainClassInitialParams ) {
	this.mainClassInitialParams = mainClassInitialParams;
}
 
Example #19
Source File: VSensorConfig.java    From gsn with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @param addressing The addressing to set.
 */
public void setAddressing ( KeyValue [] addressing ) {
	this.addressing = addressing;
}
 
Example #20
Source File: VSensorConfig.java    From gsn with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @return Returns the addressing.
 */
public  KeyValue[] getAddressing ( ) {
	return this.addressing;
}
 
Example #21
Source File: DefaultKeyValue.java    From Penetration_Testing_POC with Apache License 2.0 2 votes vote down vote up
/**
 * Constructs a new pair from the specified KeyValue.
 *
 * @param pair  the pair to copy, must not be null
 * @throws NullPointerException if the entry is null
 */
public DefaultKeyValue(final KeyValue pair) {
    super(pair.getKey(), pair.getValue());
}
 
Example #22
Source File: UnmodifiableMapEntry.java    From Penetration_Testing_POC with Apache License 2.0 2 votes vote down vote up
/**
 * Constructs a new entry from the specified KeyValue.
 *
 * @param pair  the pair to copy, must not be null
 * @throws NullPointerException if the entry is null
 */
public UnmodifiableMapEntry(final KeyValue pair) {
    super(pair.getKey(), pair.getValue());
}
 
Example #23
Source File: DefaultMapEntry.java    From Penetration_Testing_POC with Apache License 2.0 2 votes vote down vote up
/**
 * Constructs a new entry from the specified KeyValue.
 *
 * @param pair  the pair to copy, must not be null
 * @throws NullPointerException if the entry is null
 */
public DefaultMapEntry(final KeyValue pair) {
    super(pair.getKey(), pair.getValue());
}