Java Code Examples for java.util.Properties#equals()

The following examples show how to use java.util.Properties#equals() . These examples are extracted from open source projects. 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
public Void call() throws IOException {
    while (!done) {

        // store as XML format
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        props.storeToXML(out, null, "UTF-8");

        // load from XML format
        Properties p = new Properties();
        ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
        p.loadFromXML(in);

        // check that the properties are as expected
        if (!p.equals(props))
            throw new RuntimeException("Properties not equal");
    }
    return null;
}
 
Example 2
public Void call() throws IOException {
    while (!done) {

        // store as XML format
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        props.storeToXML(out, null, "UTF-8");

        // load from XML format
        Properties p = new Properties();
        ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
        p.loadFromXML(in);

        // check that the properties are as expected
        if (!p.equals(props))
            throw new RuntimeException("Properties not equal");
    }
    return null;
}
 
Example 3
public Void call() throws IOException {
    while (!done) {

        // store as XML format
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        props.storeToXML(out, null, "UTF-8");

        // load from XML format
        Properties p = new Properties();
        ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
        p.loadFromXML(in);

        // check that the properties are as expected
        if (!p.equals(props))
            throw new RuntimeException("Properties not equal");
    }
    return null;
}
 
Example 4
Source Project: apollo   File: SimpleConfig.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public synchronized void onRepositoryChange(String namespace, Properties newProperties) {
  if (newProperties.equals(m_configProperties)) {
    return;
  }
  Properties newConfigProperties = propertiesFactory.getPropertiesInstance();
  newConfigProperties.putAll(newProperties);

  List<ConfigChange> changes = calcPropertyChanges(namespace, m_configProperties, newConfigProperties);
  Map<String, ConfigChange> changeMap = Maps.uniqueIndex(changes,
      new Function<ConfigChange, String>() {
        @Override
        public String apply(ConfigChange input) {
          return input.getPropertyName();
        }
      });

  updateConfig(newConfigProperties, m_configRepository.getSourceType());
  clearConfigCache();

  this.fireConfigChange(new ConfigChangeEvent(m_namespace, changeMap));

  Tracer.logEvent("Apollo.Client.ConfigChanges", m_namespace);
}
 
Example 5
Source Project: java-trader   File: AccountImpl.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 更新配置属性
 * @return true 如果有变化, false 如果相同
 */
public boolean update(Map configElem) {
    boolean result = false;
    IniFile configIni = null;
    try{
        configIni = new IniFile(new StringReader((String)configElem.get("text")));
    }catch(Throwable t) {
        throw new RuntimeException(t);
    }
    IniFile.Section brokerMarginRatioSection = configIni.getSection("brokerMarginRatio");
    Properties brokerMarginRatio2 = new Properties();
    if( brokerMarginRatioSection!=null ) {
        brokerMarginRatio2 = brokerMarginRatioSection.getProperties();
    }
    if ( !brokerMarginRatio.equals(brokerMarginRatio2)) {
        this.brokerMarginRatio = brokerMarginRatio2;
        result = true;
    }

    Properties connectionProps2 = configIni.getSection("connectionProps").getProperties();
    if ( !connectionProps2.equals(connectionProps) ) {
        this.connectionProps = connectionProps2;
        result = true;
    }
    return result;
}
 
Example 6
Source Project: birt   File: Connection.java    License: Eclipse Public License 1.0 6 votes vote down vote up
private static Properties adjustDbProfileProperties( Properties dataSourceProperties )
    throws OdaException
{
    // first adapts to db profile properties
    Properties dbProfileProps = PropertyAdapter.adaptToDbProfilePropertyNames( dataSourceProperties );

    // use the oda.consumer.propertyProvider extension implemented for the profile's definition type,
    // to get the effective properties to open a connection
    String defnType = dbProfileProps.getProperty( IDriverMgmtConstants.PROP_DEFN_TYPE );
    Map<String,String> appContext = new HashMap<String, String>();
    appContext.put( IPropertyProvider.ODA_CONSUMER_ID, defnType );

    Properties adjustedDbProfileProps = ProviderUtil.getEffectiveProperties( dbProfileProps, appContext );
    if( dbProfileProps.equals( adjustedDbProfileProps ) )
        return dataSourceProperties;    // no adjustment is applicable

    // adapt adjusted db profile properties back to data source properties
    return PropertyAdapter.adaptToDataSourcePropertyNames( adjustedDbProfileProps );
}
 
Example 7
public Void call() throws IOException {
    while (!done) {

        // store as XML format
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        props.storeToXML(out, null, "UTF-8");

        // load from XML format
        Properties p = new Properties();
        ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
        p.loadFromXML(in);

        // check that the properties are as expected
        if (!p.equals(props))
            throw new RuntimeException("Properties not equal");
    }
    return null;
}
 
Example 8
/**
 * Test loadFromXML with a document that does not have an encoding declaration
 */
static void testLoadWithoutEncoding() throws IOException {
    System.out.println("testLoadWithoutEncoding");

    Properties expected = new Properties();
    expected.put("foo", "bar");

    String s = "<?xml version=\"1.0\"?>" +
               "<!DOCTYPE properties SYSTEM \"http://java.sun.com/dtd/properties.dtd\">" +
               "<properties>" +
               "<entry key=\"foo\">bar</entry>" +
               "</properties>";
    ByteArrayInputStream in = new ByteArrayInputStream(s.getBytes("UTF-8"));
    Properties props = new Properties();
    props.loadFromXML(in);

    if (!props.equals(expected)) {
        System.err.println("loaded: " + props + ", expected: " + expected);
        throw new RuntimeException("Test failed");
    }
}
 
Example 9
public Void call() throws IOException {
    while (!done) {

        // store as XML format
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        props.storeToXML(out, null, "UTF-8");

        // load from XML format
        Properties p = new Properties();
        ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
        p.loadFromXML(in);

        // check that the properties are as expected
        if (!p.equals(props))
            throw new RuntimeException("Properties not equal");
    }
    return null;
}
 
Example 10
public Void call() throws IOException {
    while (!done) {

        // store as XML format
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        props.storeToXML(out, null, "UTF-8");

        // load from XML format
        Properties p = new Properties();
        ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
        p.loadFromXML(in);

        // check that the properties are as expected
        if (!p.equals(props))
            throw new RuntimeException("Properties not equal");
    }
    return null;
}
 
Example 11
public Void call() throws IOException {
    while (!done) {

        // store as XML format
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        props.storeToXML(out, null, "UTF-8");

        // load from XML format
        Properties p = new Properties();
        ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
        p.loadFromXML(in);

        // check that the properties are as expected
        if (!p.equals(props))
            throw new RuntimeException("Properties not equal");
    }
    return null;
}
 
Example 12
/**
 * Gets a connection with the given target table and properties
 * <p/>
 * Tries to get one with the correct target table and properties, then prefers one without a target table, then one
 * with a different target table and properties
 *
 * @param targetTable
 * @param targetTableProps
 * @return
 * @throws IOException
 */
public synchronized HBaseConnectionHandle getConnectionHandle( String targetTable, Properties targetTableProps )
  throws IOException {
  HBaseConnectionPoolConnection result = findBestMatch( targetTable, targetTableProps );
  if ( result != null ) {
    availableConnections.remove( result );
  } else {
    result = create();
  }
  boolean targetTableDifferent = targetTable != null && !targetTable.equals( result.getTargetTable() );
  boolean propsDifferent = false;
  Properties resultTargetTableProperties = result.getTargetTableProperties();
  if ( targetTableProps == null ) {
    propsDifferent = resultTargetTableProperties != null;
  } else {
    propsDifferent = targetTableProps.equals( resultTargetTableProperties );
  }
  if ( targetTableDifferent || propsDifferent ) {
    try {
      result.newTargetTableInternal( targetTable, targetTableProps );
    } catch ( Exception e ) {
      throw new IOException( e );
    }
  }
  inUseConnections.add( result );
  return new HBaseConnectionHandleImpl( this, result );
}
 
Example 13
private synchronized void updateFileProperties(Properties newProperties, ConfigSourceType sourceType) {
  this.m_sourceType = sourceType;
  if (newProperties.equals(m_fileProperties)) {
    return;
  }
  this.m_fileProperties = newProperties;
  persistLocalCacheFile(m_baseDir, m_namespace);
}
 
Example 14
@Override
protected void runSync(ExtensionContext extensionContext, Element element) throws FaultException {

    Properties properties = null;
    String fileLocation = element.getAttribute("location").trim();

    String source = fileLocation.split(":")[0];

    if (source.equals("file")) {
        properties = getPropertiesFromLocalFile(fileLocation.split(":")[1]);
    } else if (source.equals("conf")) {
        properties = getPropertiesFromConfigRegistryFile(fileLocation.split(":")[1]);
    } else if (source.equals("gov")) {
        properties = getPropertiesFromGovernanceFile(fileLocation.split(":")[1]);
    } else {
        System.out.println("File Location Error !!");
    }

    NodeList propertyNameList = element.getElementsByTagName("property");

    for (int i = 0; i < propertyNameList.getLength() && !properties.equals(null); i++) {
        Element property = (Element) propertyNameList.item(i);
        String propertyName = property.getAttribute("name").trim();
        String value = properties.getProperty(propertyName, "");
        Element to = (Element) property.getElementsByTagName("to").item(0);
        String variable = to.getAttribute("variable").trim();
        extensionContext.readVariable(variable.trim()).setTextContent(value.trim());
    }

}
 
Example 15
Source Project: apollo   File: AbstractConfigFile.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void onRepositoryChange(String namespace, Properties newProperties) {
  if (newProperties.equals(m_configProperties.get())) {
    return;
  }
  Properties newConfigProperties = propertiesFactory.getPropertiesInstance();
  newConfigProperties.putAll(newProperties);

  String oldValue = getContent();

  update(newProperties);
  m_sourceType = m_configRepository.getSourceType();

  String newValue = getContent();

  PropertyChangeType changeType = PropertyChangeType.MODIFIED;

  if (oldValue == null) {
    changeType = PropertyChangeType.ADDED;
  } else if (newValue == null) {
    changeType = PropertyChangeType.DELETED;
  }

  this.fireConfigChange(new ConfigFileChangeEvent(m_namespace, oldValue, newValue, changeType));

  Tracer.logEvent("Apollo.Client.ConfigChanges", m_namespace);
}
 
Example 16
@Override
public void onRepositoryChange(String namespace, Properties newProperties) {
  if (newProperties.equals(m_fileProperties)) {
    return;
  }
  Properties newFileProperties = propertiesFactory.getPropertiesInstance();
  newFileProperties.putAll(newProperties);
  updateFileProperties(newFileProperties, m_upstream.getSourceType());
  this.fireRepositoryChange(namespace, newProperties);
}
 
Example 17
Source Project: rocketmq-4.3.0   File: MixAll.java    License: Apache License 2.0 4 votes vote down vote up
public static boolean isPropertiesEqual(final Properties p1, final Properties p2) {
    return p1.equals(p2);
}
 
Example 18
Source Project: rocketmq   File: MixAll.java    License: Apache License 2.0 4 votes vote down vote up
public static boolean isPropertiesEqual(final Properties p1, final Properties p2) {
    return p1.equals(p2);
}
 
Example 19
public static boolean isPropertiesEqual(final Properties p1, final Properties p2) {
    return p1.equals(p2);
}
 
Example 20
Source Project: rocketmq-read   File: MixAll.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * properties 是否相等
 * @param p1 p1
 * @param p2 p2
 * @return
 */
public static boolean isPropertiesEqual(final Properties p1, final Properties p2) {
    return p1.equals(p2);
}