小编SOP*_*SOP的帖子

我想在两个不同的参数上使用Collections.sort()两次

我有一个对象列表,我想使用不同的属性进行排序.

@Override
public int compareTo(Object obj)
{
    Field tab = (Field) obj;

    int objx = Integer.parseInt(tab.getX());
    // int objy = Integer.parseInt(tab.getY());

    int classX = Integer.parseInt(this.X);

    if (classX == objx)
      return 0;
    else if (classX > objx)
      return 1;
    else
      return -1;
}
Run Code Online (Sandbox Code Playgroud)

到目前为止我所拥有的:

Collections.sort(list1); // But using property1 to sort
Collections.sort(list1); // But using property2 to sort
Run Code Online (Sandbox Code Playgroud)

所以,在第一种情况下,我能够使用property1排序,但如何使用property2排序?我正在尝试使用不同的参数进行排序,但compareTo()只接受一个参数.

java sorting comparator

7
推荐指数
4
解决办法
2136
查看次数

正则表达式排除包含java中特定单词的句子

我正在阅读一个包含大量信息的文件,如下所示:

    type dw_3 from u_dw within w_pg6p0012_01
    boolean visible = false
    integer x = 1797
    integer y = 388
    integer width = 887
    integer height = 112
    integer taborder = 0
    boolean bringtotop = true
    string dataobject = "d_pg6p0012_14"
    end type

    type dw_3 from u_dw within w_pg6p0012_01
    integer x = 1797
    integer y = 388
    integer width = 887
    integer height = 112
    integer taborder = 0
    boolean bringtotop = true
    string dataobject = "d_pg6p0012_14"
    end type
Run Code Online (Sandbox Code Playgroud)

我做了正则表达式:(?i)type dw_\d\s+(.*?)\s+within(.*?)\s+(?!boolean …

java regex

7
推荐指数
2
解决办法
940
查看次数

我正在用Java实现工厂设计模式

我正在用Java实现工厂设计模式,我想在抽象类中保留一个重载方法。它会违反工厂模式概念吗?还是请提出这是否是实施Factory设计模式的正确方法?

abstract class A{
    void meth(int a);
    void meth(int a,int b);
}

class Factory{
    public static A factoryMethod(int a){
         if(a==1){
            return new Ob1();
        }else{
            return new Ob2();
        }
    }
}

class Ob1 extends A{

void meth(int a){}
void meth(int a,int b){}
}
Run Code Online (Sandbox Code Playgroud)

java design-patterns

5
推荐指数
1
解决办法
935
查看次数

对不同类型对象的列表进行排序

我有一个包含不同类型对象的对象列表,但是所有对象中都有一个属性.list包含Field类,Button类,Page类等的对象,但是一个属性在所有属性中是共同的,即"sequence_no",我想在"sequence_no"的基础上对该列表进行排序.

java

4
推荐指数
1
解决办法
1127
查看次数

我希望我的 Spring Boot 应用程序连接到 JNDI 数据源(服务器:wildfly)

我创建了一个 spring boot 应用程序,它从 application.properties 文件中读取数据库和服务器配置,但是当我部署到 wildfly 时,我希望应用程序应该从 wildfly 的 standalone.xml 文件中读取数据库配置,但它仍然从 Application.properties 文件中读取。

//Spring Boot 主应用类

@EnableAutoConfiguration
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class,
        DataSourceTransactionManagerAutoConfiguration.class })
public class DemoWildFlyApplication extends SpringBootServletInitializer
{
    public static void main(String[] args) {
        SpringApplication.run(DemoWildFlyApplication.class, args);
    }
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(DemoWildFlyApplication.class);
    }

    @Bean
    @Primary
    public DataSource primaryDataSource() {
        JndiDataSourceLookup dataSourceLookup = new JndiDataSourceLookup();
        DataSource dataSource = dataSourceLookup.getDataSource("java:jboss/datasources/primary");
        return dataSource;
    }
Run Code Online (Sandbox Code Playgroud)

//application.properties 文件

spring.datasource.primary.jndi-name=java:jboss/datasources/primary
spring.datasource.primary.driver-class-name=org.postgresql.Driver
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQL9Dialect
spring.jpa.show-sql=false
spring.jpa.generate-ddl=true
Run Code Online (Sandbox Code Playgroud)

//独立的.xml

  <xa-datasource jndi-name="java:jboss/datasources/primary" pool-name="pool" enabled="true" use-java-context="true"> …
Run Code Online (Sandbox Code Playgroud)

java spring spring-boot

4
推荐指数
1
解决办法
8741
查看次数

我想用css对齐一些句子

                 this is my alignment :
             this is my alignment one :
         this is my alignment one two :
   this is my alignment one two three :

style="position:absolute;top:63px;left:151px;width:88px;margin-left:-132px;margin-top:5px"

<span id="resultModel.hdPk1Label" name="resultModel.hdPk1Label" class="singleFormLabel" style="position:absolute;top:36px;left:151px;width:88px;margin-left:-132px;margin-top:5px"><font class="essential_mark">*</font>label.hdPk1 &nbsp;:&nbsp;</span>
Run Code Online (Sandbox Code Playgroud)

我有一些元素/标签,我想以上述方式排列/对齐它们,并使用上面的代码,但它对齐如下所示:

this is my alignment :
this is my alignment one :
this is my alignment one two :
this is my alignment one two three :
Run Code Online (Sandbox Code Playgroud)

我怎样才能达到理想的效果?

html css

1
推荐指数
1
解决办法
63
查看次数

标签 统计

java ×5

comparator ×1

css ×1

design-patterns ×1

html ×1

regex ×1

sorting ×1

spring ×1

spring-boot ×1