我的应用程序中有 2 个编辑文本,1 个按钮用于在编辑文本中添加输入数字,1 个文本视图用于显示结果。如果单击按钮时我的编辑文本选项卡为空或为空,我想添加一条祝酒消息。我已经搜索并尝试了所有解决方案......但似乎没有任何效果。请帮助!!
这是我将两个数字相加的代码。
package com.example.mycalc;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText editText1 = (EditText)findViewById(R.id.editText1);
final EditText editText2 = (EditText)findViewById(R.id.editText2);
Button button1 = (Button)findViewById(R.id.button1);
final TextView textView1 = (TextView)findViewById(R.id.textView1);
textView1.setText(" ");
button1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
double edit1 = Double.valueOf(editText1.getText().toString());
double edit2 = Double.valueOf(editText2.getText().toString());
double …Run Code Online (Sandbox Code Playgroud) 我有一个数组,其中每个元素都来自由制表符分隔的行。
初始代码:
#!/usr/bin/perl -w
use strict;
Run Code Online (Sandbox Code Playgroud)
下面的代码是一段代码。
sub parser_domains {
my @params = @_;
my $interpro_line = "";
my @interpro_vector = ( );
my $idr_sub_id = $params[0];
my $idr_sub_start = $params[1]+1;
my $idr_sub_end = $params[2]+1;
my $interpro_id = "";
my $interpro_start_location = 0;
my $interpro_end_location = 0;
my $interpro_db = "";
my $interpro_length = 0;
my $interpro_db_accession = "";
my $interpro_signature = "";
my $interpro_evalue = "";
my $interpro_vector_size = 0;
my $interpro_sub_file= "";
my $idr_sub_lenght = ($idr_sub_end-$idr_sub_start)+1;
$interpro_sub_file = …Run Code Online (Sandbox Code Playgroud) 假设我有一个值:
int i = 0;
Run Code Online (Sandbox Code Playgroud)
并且有资格进行空基优化的空类:
struct Empty{
// stuff that passes
// static_assert( std::is_empty<Empty>::value );
};
Run Code Online (Sandbox Code Playgroud)
是否合法:
Empty& e = *reinterpret_cast<Empty*>(reinterpret_cast<void*>(&i)); //?
// do stuff with e
Run Code Online (Sandbox Code Playgroud) c++ void-pointers is-empty template-meta-programming void-safety
如何验证 Set 是空集还是 new HashSet<>() ?尝试了两种方法 -
sizeCollectionUtils.isEmpty()
两者产生相同的值。在我尝试重构的那一刻,我已经有了这个方法。
public static boolean isEmpty(Object value) {
boolean empty = false;
if (value instanceof String && ((String) value).isEmpty()) {
empty = true;
} else if (value instanceof List && ((List<?>) value).isEmpty()) {
empty = true;
} else if (value instanceof String[] && ArrayUtils.isEmpty((String[]) value)) {
empty = true;
} else if (value == null) {
empty = true;
}
return empty;
}
Run Code Online (Sandbox Code Playgroud)
有没有明显更好的方法来做到这一点,我错过了?
我知道我可以if使用链式||语句将所有条件放在一个语句上,但我真的不知道这比我现在得到的更好。
我有一本字典,可能只有这些键。但可以有 2 个键,例如'news'and'coupon'或 only 'coupon'。如何检查字典是否为空?(下面的词典是空的。)
{'news': [], 'ad': [], 'coupon': []}
{'news': [], 'coupon': []}
Run Code Online (Sandbox Code Playgroud)
我写了代码,但它应该只需要 3 个键:
if data["news"] == [] and data["ad"] == [] and data["coupon"] == []:
print('empty')
Run Code Online (Sandbox Code Playgroud)
怎样才能不只带3把钥匙?
我在某处看到了以下代码,想知道检查是否有任何实际好处isEmpty。有不对吗?
List<Long> someIds = ..
if (someIds != null && !someIds.isEmpty()) {
for (Long someId : someIds) {
// something
}
}
Run Code Online (Sandbox Code Playgroud) 我正在使用wordpress模板,其中div.post-thumb为空但具有动态空白区域.
<div class="post-thumb"> </div>
<div class="post-text"></div>
Run Code Online (Sandbox Code Playgroud)
我正在使用以下脚本来检测div.post-thumb是否为空.
$('.post-thumb').each(function(){
if ($(this).html()=='') $('.post-text').css('marginLeft','50px');
});
Run Code Online (Sandbox Code Playgroud)
这个脚本的问题是"div.post-thumb中的动态空格"
如何摆脱这个问题?有没有其他方法可以检测div是否为空,不包括空格?
使用PHP一些代码,我遇到了一些代码,基本上检查相同的变量是否为空两次:
if ( !empty( $_GET[ 'branch' ] ) ) {
$branch = $_GET[ 'branch' ];
}
if ( empty( $branch ) ) {
_output( 'Error: no branch specified!' );
exit( 1 );
}
Run Code Online (Sandbox Code Playgroud)
知道为什么这样设置吗?与使用相比else,有什么优势,比如:
if ( !empty( $_GET[ 'branch' ] ) ) {
$branch = $_GET[ 'branch' ];
} else {
_output( 'Error: no branch specified!' );
exit( 1 );
}
Run Code Online (Sandbox Code Playgroud) 我想
arg.present?
Run Code Online (Sandbox Code Playgroud)
是为了检查一个字符串是空的还是零的真相和光,但是我注意到一个令人困惑的情况.如果我的字符串是:
arg = "\t"
Run Code Online (Sandbox Code Playgroud)
我得到了错误的结果:
2.4.0 :003 > arg = "\t"
=> "\t"
2.4.0 :004 > arg.present?
=> false
Run Code Online (Sandbox Code Playgroud)
检查我的字符串参数是空还是零的更简单的方法是什么?当然,我可以写,arg.empty? || arg.nil?但我正在寻找一种更简洁的方式.
在测试中,我向另一个类注入了一个模拟,该类似乎工作正常。但是,当我检查 ArrayList 是否为空时,尽管其长度/大小为 0,结果却为 false。这种情况怎么会发生以及如何解决这个问题?
@Slf4j
@Configuration
@RequiredArgsConstructor
@Setter(onMethod_ = @SuppressFBWarnings({"EI_EXPOSE_REP2", "EI_EXPOSE_REP"}))
@Getter(onMethod_ = @SuppressFBWarnings({"EI_EXPOSE_REP2", "EI_EXPOSE_REP"}))
@EnableConfigurationProperties(MyProperties.class)
public class MyConfig {
private final MyProperties myProperties;
private final GenericApplicationContext applicationContext;
@PostConstruct
void init() {
Objects.requireNonNull(myProperties, "myProperties needs not to be null.");
if (/*myProperties.getApps().size() == 0 || */myProperties.getApps().isEmpty()) {
log.info("bla bla bla");
} else {
...
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的测试课:
@ExtendWith(MockitoExtension.class)
class MyConfigTest {
@Mock
MyProperties myPropertiesMock;
@InjectMocks
MyConfig myConfig;
ApplicationContextRunner contextRunner;
@Test
void should_check_for_empty_apps() {
contextRunner = new ApplicationContextRunner()
.withPropertyValues("foobar.apps[0].name=", "foobar.apps[0].baseUrl=", …Run Code Online (Sandbox Code Playgroud) 我找不到一种方法让我的终端在空输入时退出程序。我有:
int main(int argc, char const* argv[]) {
// Write your code here
// Define variables
set<string> words; // The set
bool more = true; // Flag indicating there are more lines to read
// If there is no command line argument, use stdin to get the lines
if (argc == 1){
// Take lines in until a blank line is entered
while (more) {
// Get next line from stdin
string input;
cin >> input;
// Quit if we …Run Code Online (Sandbox Code Playgroud) is-empty ×12
java ×4
c++ ×2
collections ×2
android ×1
arraylist ×1
arrays ×1
dictionary ×1
for-loop ×1
hashset ×1
instanceof ×1
jquery ×1
loops ×1
null ×1
perl ×1
php ×1
python ×1
ruby ×1
stdstring ×1
string ×1
terminal ×1
void-safety ×1
whitespace ×1