LINUX.ORG.RU

История изменений

Исправление stevejobs, (текущая версия) :

AtomicReference<List<String>> data = new AtomicReference<List<String>>();

List<String> tempList = new ArrayList<String>();
tempList.add("зажрались вы совсем, барин!");
tempList.add("сложно звездочку написать!");
tempList.add("авось AtomicReference то проще писать, да?!");

data.set(tempList);

public static String f1(AtomicReference<List<String>> data) throws IllegalArgumentException {
  boolean valid = false;
  String result = "";
  if (null != data) {
    List<String> tempList = data.get();
    if (null != tempList) {
      String elem1 = tempList.get(0);
      String elem2 = tempList.get(1);
      if (null != elem1 && null != elem2) 
        result = elem1+elem2;
        valid = true;
      }
    }      
  }
  if (true == valid) {
    return result;
  } else {
    throw new IllegalArgumentException();
  }
}

try {
  String result = f1();
  System.out.println(String.format("Результат: ", %s));
} catch (IllegalArgumentException e) {
  System.out.println("Мда, фигня какая-то");
  e.printStackTrace();
}

Исправление stevejobs, :

AtomicReference<List<String>> data = new AtomicReference<List<String>>();

List<String> tempList = new ArrayList<String>();
tempList.add("зажрались вы совсем, барин!");
tempList.add("сложно звездочку написать!");
tempList.add("авось AtomicReference то проще писать, да?!");

data.set(tempList);

public static String f1(AtomicReference<List<String>> data) throws IllegalArgumentException {
  boolean valid = false;
  String result = "";
  if (null != data) {
    List<String> tempList = data.get();
    if (null != tempList) {
      String elem1 = tempList.get(0);
      String elem2 = tempList.get(1);
      if (null != elem1 && null != elem2) 
        result = elem1+elem2;
        valid = true;
      }
    }      
  }
  if (true == valid) {
    return result;
  } else {
    throw new IllegalArgumentException();
  }
}

try {
  String result = f1();
  System.out.println(String.format("Результат: ", %s));
} catch {
  System.out.println("Мда, фигня какая-то");
}

Исходная версия stevejobs, :

AtomicReference<List<String>> data = new AtomicReference<List<String>>();

List<String> tempList = new ArrayList<String>();
tempList.add("зажрались вы совсем, барин!");
tempList.add("сложно звездочку написать!");
tempList.add("авось AtomicReference то проще писать, да?!");

data.set(tempList);

public static String f1(AtomicReference<List<String>> data) throws IllegalArgumentException {
  boolean valid = false;
  String result = "";
  if (null != data) {
    List<String> tempList = data.get();
    if (null != tempList) {
      String elem1 = tempList.get(0);
      String elem2 = tempList.get(1);
      if (null != elem1 && null != elem2) 
        result = elem1+elem2;
      }
    }      
  }
  if (true == valid) {
    return result;
  } else {
    throw new IllegalArgumentException();
  }
}

try {
  String result = f1();
  System.out.println(String.format("Результат: ", %s));
} catch {
  System.out.println("Мда, фигня какая-то");
}